Skip to content

Commit

Permalink
test: improve watch mode test
Browse files Browse the repository at this point in the history
PR-URL: #50319
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
MoLow authored and targos committed Nov 11, 2023
1 parent 1aecf0c commit 7d8a18b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions test/sequential/test-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function runWriteSucceed({
child.kill();
cancelRestarts();
}
return { stdout, stderr };
return { stdout, stderr, pid: child.pid };
}

async function failWriteSucceed({ file, watchedFile }) {
Expand Down Expand Up @@ -259,13 +259,14 @@ console.log(values.random);
]);
});

it('should not load --require modules in main process', async () => {
it('should load --require modules in the watched process, and not in the orchestrator process', async () => {
const file = createTmpFile();
const required = createTmpFile('setImmediate(() => process.exit(0));');
const required = createTmpFile('process._rawDebug(\'pid\', process.pid);');
const args = ['--require', required, file];
const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file, args });
const { stdout, pid } = await runWriteSucceed({ file, watchedFile: file, args });

assert.strictEqual(stderr, '');
const importPid = parseInt(stdout[0].split(' ')[1], 10);
assert.notStrictEqual(pid, importPid);
assert.deepStrictEqual(stdout, [
'running',
`Completed running ${inspect(file)}`,
Expand All @@ -275,13 +276,14 @@ console.log(values.random);
]);
});

it('should not load --import modules in main process', async () => {
it('should load --import modules in the watched process, and not in the orchestrator process', async () => {
const file = createTmpFile();
const imported = pathToFileURL(createTmpFile('process._rawDebug("imported");'));
const imported = "data:text/javascript,process._rawDebug('pid', process.pid);";
const args = ['--import', imported, file];
const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file, args });
const { stdout, pid } = await runWriteSucceed({ file, watchedFile: file, args });

assert.strictEqual(stderr, 'imported\nimported\n');
const importPid = parseInt(stdout[0].split(' ')[1], 10);
assert.notStrictEqual(pid, importPid);
assert.deepStrictEqual(stdout, [
'running',
`Completed running ${inspect(file)}`,
Expand Down

0 comments on commit 7d8a18b

Please sign in to comment.