We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 49405bd commit 5dd7116Copy full SHA for 5dd7116
2 files changed
lib/internal/main/watch_mode.js
@@ -33,7 +33,7 @@ markBootstrapComplete();
33
// TODO(MoLow): Make kill signal configurable
34
const kKillSignal = 'SIGTERM';
35
const kShouldFilterModules = getOptionValue('--watch-path').length === 0;
36
-const kEnvFile = getOptionValue('--env-file');
+const kEnvFile = getOptionValue('--env-file') || getOptionValue('--env-file-if-exists');
37
const kWatchedPaths = ArrayPrototypeMap(getOptionValue('--watch-path'), (path) => resolve(path));
38
const kPreserveOutput = getOptionValue('--watch-preserve-output');
39
const kCommand = ArrayPrototypeSlice(process.argv, 1);
test/sequential/test-watch-mode.mjs
@@ -242,6 +242,32 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00
242
}
243
});
244
245
+ it('should load new env variables when --env-file-if-exists changes', async () => {
246
+ const envKey = `TEST_ENV_${Date.now()}`;
247
+ const envKey2 = `TEST_ENV_2_${Date.now()}`;
248
+ const jsFile = createTmpFile(`console.log('ENV: ' + process.env.${envKey} + '\\n' + 'ENV2: ' + process.env.${envKey2});`);
249
+ const envFile = createTmpFile(`${envKey}=value1`, '.env');
250
+ const { done, restart } = runInBackground({ args: ['--watch', `--env-file-if-exists=${envFile}`, jsFile] });
251
+
252
+ try {
253
+ await restart();
254
+ writeFileSync(envFile, `${envKey}=value1\n${envKey2}=newValue`);
255
256
+ // Second restart, after env change
257
+ const { stderr, stdout } = await restart();
258
259
+ assert.strictEqual(stderr, '');
260
+ assert.deepStrictEqual(stdout, [
261
+ `Restarting ${inspect(jsFile)}`,
262
+ 'ENV: value1',
263
+ 'ENV2: newValue',
264
+ `Completed running ${inspect(jsFile)}`,
265
+ ]);
266
+ } finally {
267
+ await done();
268
+ }
269
+ });
270
271
it('should watch changes to a failing file', async () => {
272
const file = createTmpFile('throw new Error("fails");');
273
const { stderr, stdout } = await runWriteSucceed({
0 commit comments