Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: extra test for environment variables and .env
This tests that if an environment variable is present in the environment, then .env does not override it, but that other variables in .env that aren't present are still set.
  • Loading branch information
philnash committed Sep 4, 2023
commit 005da17581ceb74eb405a7491a8f39ad8059c21c
2 changes: 2 additions & 0 deletions test/fixtures/dotenv/simple.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A=1
B=2
14 changes: 14 additions & 0 deletions test/parallel/test-dotenv-edge-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { describe, it } = require('node:test');

const validEnvFilePath = '../fixtures/dotenv/valid.env';
const relativePath = '../fixtures/dotenv/node-options.env';
const simpleEnvFilePath = '../fixtures/dotenv/simple.env';

describe('.env supports edge cases', () => {

Expand Down Expand Up @@ -47,4 +48,17 @@ describe('.env supports edge cases', () => {
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});

it('should not override existing environment variables but introduce new vars', async () => {
const code = `
require('assert').strictEqual(process.env.A + "," + process.env.B, '3,2');
`.trim();
const child = await common.spawnPromisified(
process.execPath,
[ `--env-file=${simpleEnvFilePath}`, '--eval', code ],
{ cwd: __dirname, env: { A: '3' } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 tests can be merged

);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});
});