Skip to content

Commit 41a3878

Browse files
authored
test: improve watch mode test
PR-URL: #50319 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 8f742bb commit 41a3878

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/sequential/test-watch-mode.mjs

+11-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function runWriteSucceed({
6262
child.kill();
6363
cancelRestarts();
6464
}
65-
return { stdout, stderr };
65+
return { stdout, stderr, pid: child.pid };
6666
}
6767

6868
async function failWriteSucceed({ file, watchedFile }) {
@@ -259,13 +259,14 @@ console.log(values.random);
259259
]);
260260
});
261261

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

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

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

284-
assert.strictEqual(stderr, 'imported\nimported\n');
285+
const importPid = parseInt(stdout[0].split(' ')[1], 10);
286+
assert.notStrictEqual(pid, importPid);
285287
assert.deepStrictEqual(stdout, [
286288
'running',
287289
`Completed running ${inspect(file)}`,

0 commit comments

Comments
 (0)