From 4f3db237900c6bed7e2f91936d147c8a6bb40971 Mon Sep 17 00:00:00 2001 From: gorankarlic Date: Sun, 1 Dec 2024 17:52:48 +0800 Subject: [PATCH 1/3] Add test for #55913 --- test/sequential/test-watch-mode.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index 39bc7223dffdfc..c669624dbf1165 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -242,6 +242,25 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00 } }); + it('should not reload env variables when another file in the --env-file directory changes', async () => { + const envKey = `TEST_ENV_${Date.now()}`; + const dir = tmpdir.resolve('subdir0'); + const jsFile = createTmpFile(`console.log('ENV: ' + process.env.${envKey});`); + const envFile = createTmpFile(`${envKey}=value1`, '.env'); + const tmpFile = createTmpFile('', '.tmp'); + const { done, restart } = runInBackground({ args: ['--watch-path', dir, `--env-file=${envFile}`, jsFile] }); + + try { + await restart(); + writeFileSync(tmpFile, `${Date.now()}`); + + // Should not restart + await assert.rejects(restart(), {name: 'Error', message: 'Timed out waiting for restart'}); + } finally { + await done(); + } + }); + it('should watch changes to a failing file', async () => { const file = createTmpFile('throw new Error("fails");'); const { stderr, stdout } = await runWriteSucceed({ From 03ae6ae9d7b23e026405a78a6967e54bf5a1d4f0 Mon Sep 17 00:00:00 2001 From: gorankarlic Date: Sun, 1 Dec 2024 18:04:40 +0800 Subject: [PATCH 2/3] Fixed test to use isolated temporary directory. --- test/sequential/test-watch-mode.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index c669624dbf1165..2b9a25661cd9dc 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -246,8 +246,8 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00 const envKey = `TEST_ENV_${Date.now()}`; const dir = tmpdir.resolve('subdir0'); const jsFile = createTmpFile(`console.log('ENV: ' + process.env.${envKey});`); - const envFile = createTmpFile(`${envKey}=value1`, '.env'); - const tmpFile = createTmpFile('', '.tmp'); + const envFile = createTmpFile(`${envKey}=value1`, '.env', dir); + const tmpFile = createTmpFile('', '.tmp', dir); const { done, restart } = runInBackground({ args: ['--watch-path', dir, `--env-file=${envFile}`, jsFile] }); try { From 39bd1f8b5d97571be991b09fad7b3cc511b8101d Mon Sep 17 00:00:00 2001 From: gorankarlic Date: Mon, 2 Dec 2024 12:31:09 +0800 Subject: [PATCH 3/3] Fix linter issues and failing test (create subdirectory). --- test/sequential/test-watch-mode.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index 2b9a25661cd9dc..52aea0877f0b78 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -243,8 +243,9 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00 }); it('should not reload env variables when another file in the --env-file directory changes', async () => { - const envKey = `TEST_ENV_${Date.now()}`; const dir = tmpdir.resolve('subdir0'); + mkdirSync(dir); + const envKey = `TEST_ENV_${Date.now()}`; const jsFile = createTmpFile(`console.log('ENV: ' + process.env.${envKey});`); const envFile = createTmpFile(`${envKey}=value1`, '.env', dir); const tmpFile = createTmpFile('', '.tmp', dir); @@ -255,7 +256,7 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00 writeFileSync(tmpFile, `${Date.now()}`); // Should not restart - await assert.rejects(restart(), {name: 'Error', message: 'Timed out waiting for restart'}); + await assert.rejects(restart(), { name: 'Error', message: 'Timed out waiting for restart' }); } finally { await done(); }