summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/brainstorm-server/lifecycle.test.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/brainstorm-server/lifecycle.test.js b/tests/brainstorm-server/lifecycle.test.js
index f264f32..fbcb87c 100644
--- a/tests/brainstorm-server/lifecycle.test.js
+++ b/tests/brainstorm-server/lifecycle.test.js
@@ -124,6 +124,45 @@ async function runTests() {
assert(portB >= 49152, 'should fall back to a random high port');
});
+ await test('auto-opens the browser once, on the first screen', async () => {
+ const dir = fs.mkdtempSync('/tmp/bs-open-');
+ const marker = path.join(dir, 'opened.log');
+ const openCmd = `sh -c 'echo "$0" >> ${marker}'`; // capture the launch instead of opening a browser
+ const srv = spawn('node', [SERVER], { env: { ...process.env, BRAINSTORM_PORT: 3417, BRAINSTORM_DIR: dir, BRAINSTORM_OPEN: '1', BRAINSTORM_OPEN_CMD: openCmd, BRAINSTORM_LIFECYCLE_CHECK_MS: 100000 } });
+ let out = ''; srv.stdout.on('data', d => out += d.toString());
+ for (let i = 0; i < 60 && !out.includes('server-started'); i++) await sleep(50);
+
+ // First screen, with no browser connected -> should auto-open.
+ fs.writeFileSync(path.join(dir, 'content', 'first.html'), '<h2>First</h2>');
+ await sleep(700);
+ // Second screen -> must NOT open again.
+ fs.writeFileSync(path.join(dir, 'content', 'second.html'), '<h2>Second</h2>');
+ await sleep(700);
+
+ srv.kill(); await sleep(100);
+ const lines = fs.existsSync(marker) ? fs.readFileSync(marker, 'utf8').trim().split('\n').filter(Boolean) : [];
+ fs.rmSync(dir, { recursive: true, force: true });
+
+ assert.strictEqual(lines.length, 1, 'should open exactly once');
+ assert(lines[0].includes('3417'), `should open the server URL, got: ${lines[0]}`);
+ });
+
+ await test('does NOT auto-open unless approved (BRAINSTORM_OPEN unset)', async () => {
+ const dir = fs.mkdtempSync('/tmp/bs-open-');
+ const marker = path.join(dir, 'opened.log');
+ const openCmd = `sh -c 'echo "$0" >> ${marker}'`;
+ // BRAINSTORM_OPEN intentionally NOT set — auto-open must stay off.
+ const srv = spawn('node', [SERVER], { env: { ...process.env, BRAINSTORM_PORT: 3418, BRAINSTORM_DIR: dir, BRAINSTORM_OPEN_CMD: openCmd, BRAINSTORM_LIFECYCLE_CHECK_MS: 100000 } });
+ let out = ''; srv.stdout.on('data', d => out += d.toString());
+ for (let i = 0; i < 60 && !out.includes('server-started'); i++) await sleep(50);
+ fs.writeFileSync(path.join(dir, 'content', 'first.html'), '<h2>First</h2>');
+ await sleep(700);
+ srv.kill(); await sleep(100);
+ const opened = fs.existsSync(marker);
+ fs.rmSync(dir, { recursive: true, force: true });
+ assert(!opened, 'must not open the browser without explicit approval');
+ });
+
console.log(`\n--- Results: ${passed} passed, ${failed} failed ---`);
if (failed > 0) process.exit(1);
}