| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,7 @@ markBootstrapComplete(); | |||
| 33 | 33 | // TODO(MoLow): Make kill signal configurable | |
| 34 | 34 | const kKillSignal = 'SIGTERM'; | |
| 35 | 35 | const kShouldFilterModules = getOptionValue('--watch-path').length === 0; | |
| 36 | - const kEnvFile = getOptionValue('--env-file'); | ||
| 36 | + const kEnvFile = getOptionValue('--env-file') || getOptionValue('--env-file-if-exists'); | ||
| 37 | 37 | const kWatchedPaths = ArrayPrototypeMap(getOptionValue('--watch-path'), (path) => resolve(path)); | |
| 38 | 38 | const kPreserveOutput = getOptionValue('--watch-preserve-output'); | |
| 39 | 39 | const kCommand = ArrayPrototypeSlice(process.argv, 1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,6 +242,32 @@ describe('watch mode', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_00 | |||
| 242 | 242 | } | |
| 243 | 243 | }); | |
| 244 | 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 | + | ||
| 245 | 271 | it('should watch changes to a failing file', async () => { | |
| 246 | 272 | const file = createTmpFile('throw new Error("fails");'); | |
| 247 | 273 | const { stderr, stdout } = await runWriteSucceed({ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments