From 7d8a18b2575dae9e5bdb975c910841abf1bb4319 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Mon, 23 Oct 2023 22:03:25 +0300 Subject: [PATCH] test: improve watch mode test PR-URL: https://github.com/nodejs/node/pull/50319 Reviewed-By: Geoffrey Booth Reviewed-By: Colin Ihrig Reviewed-By: Yagiz Nizipli --- test/sequential/test-watch-mode.mjs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index c6dcb0fcbffb1b..444e296bb9f062 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -62,7 +62,7 @@ async function runWriteSucceed({ child.kill(); cancelRestarts(); } - return { stdout, stderr }; + return { stdout, stderr, pid: child.pid }; } async function failWriteSucceed({ file, watchedFile }) { @@ -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)}`, @@ -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)}`,