Skip to content

Commit c9ab001

Browse files
unhappychoiceclaude
andcommitted
test: use --no-open flag in CLI e2e instead of dummy open shim
PATH override + dummy `open` script was fragile and could leak real browser launches when the override failed. Replace it with the CLI's existing --no-open flag for a deterministic fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 6c10611 commit c9ab001

1 file changed

Lines changed: 3 additions & 30 deletions

File tree

‎test/e2e/cli.test.ts‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,42 @@
11
import axios from 'axios';
22
import { ChildProcess, spawn } from 'child_process';
33
import path from 'path';
4-
import fs from 'fs';
5-
import os from 'os';
64

75
const cliPath = path.resolve(__dirname, '../../bin/mdts');
86
const testDirectory = path.resolve(__dirname, '../fixtures/mountDirectory');
97
const port = 8522;
108

119
describe('CLI e2e tests', () => {
1210
let cliProcess: ChildProcess;
13-
let tempDir: string;
14-
let originalPath: string | undefined;
1511

1612
beforeAll(async () => {
17-
// Create a temporary directory for our dummy 'open' executable
18-
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mdts-test-'));
13+
cliProcess = spawn('node', [cliPath, '-p', String(port), '--no-open', testDirectory]);
1914

20-
// Create a dummy 'open' executable that does nothing
21-
const dummyOpenPath = path.join(tempDir, 'open');
22-
fs.writeFileSync(dummyOpenPath, '#!/bin/bash\nexit 0');
23-
fs.chmodSync(dummyOpenPath, '755'); // Make it executable
24-
25-
// Store original PATH and prepend our temp directory to it
26-
originalPath = process.env.PATH;
27-
process.env.PATH = `${tempDir}${path.delimiter}${process.env.PATH}`;
28-
29-
cliProcess = spawn('node', [cliPath, '-p', String(port), testDirectory], {
30-
env: { ...process.env, PATH: process.env.PATH }, // Pass the modified PATH to the child process
31-
});
32-
33-
// Optional: Log stderr for debugging
3415
cliProcess.stderr?.on('data', (data: Buffer) => {
3516
console.error(`CLI stderr: ${data}`);
3617
});
3718

38-
// Poll for server readiness
3919
const maxAttempts = 30;
4020
const delayMs = 1000;
4121
for (let i = 0; i < maxAttempts; i++) {
4222
try {
4323
const response = await axios.get(`http://localhost:${port}/api/markdown/content/test.md`);
4424
if (response.status === 200) {
4525
console.log(`Server is ready after ${i + 1} attempts.`);
46-
return; // Server is ready
26+
return;
4727
}
4828
} catch {
4929
// Server not ready yet, continue polling
5030
}
5131
await new Promise(resolve => setTimeout(resolve, delayMs));
5232
}
5333
throw new Error('Server did not become ready within the timeout.');
54-
}, 60000); // Keep the overall timeout for beforeAll
34+
}, 60000);
5535

5636
afterAll(() => {
5737
if (cliProcess) {
5838
cliProcess.kill();
5939
}
60-
// Clean up the temporary directory and restore original PATH
61-
if (tempDir) {
62-
fs.rmSync(tempDir, { recursive: true, force: true });
63-
}
64-
if (originalPath !== undefined) {
65-
process.env.PATH = originalPath;
66-
}
6740
});
6841

6942
test('should serve content/test.md', async () => {

0 commit comments

Comments
 (0)