Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add built-in .env file support #48890

Merged
merged 15 commits into from
Aug 17, 2023
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
test: move edge cases into different file
  • Loading branch information
anonrig committed Aug 13, 2023
commit bb7479a92d7dfbdddb3fa634cae16fdb8e0ea0ec
36 changes: 36 additions & 0 deletions test/parallel/test-dotenv-edge-cases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const common = require('../common');
const assert = require('node:assert');
const { describe, it } = require('node:test');

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

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

it('should use the last --env-file declaration', async () => {
anonrig marked this conversation as resolved.
Show resolved Hide resolved
const code = `
require('assert').strictEqual(process.env.BASIC, 'basic');
`.trim();
const child = await common.spawnPromisified(process.execPath,
[ `--env-file=${relativePath}`, `--env-file=${validEnvFilePath}`, '--eval', code ], {
cwd: __dirname,
});
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});

it('should handle unexisting .env file', async () => {
anonrig marked this conversation as resolved.
Show resolved Hide resolved
anonrig marked this conversation as resolved.
Show resolved Hide resolved
const code = `
require('assert').strictEqual(1, 1)
`.trim();
const child = await common.spawnPromisified(process.execPath,
[ '--env-file=.env', '--eval', code ], {
cwd: __dirname,
});
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});

});
36 changes: 0 additions & 36 deletions test/parallel/test-dotenv-edge-cases.mjs

This file was deleted.

anonrig marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as common from '../common/index.mjs';
import assert from 'node:assert';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
'use strict';

const common = require('../common');
const assert = require('node:assert');
const { describe, it } = require('node:test');

if (!common.isMainThread) {
common.skip(
'test-esm-resolve-type.mjs: process.chdir is not available in Workers'
'test-dotenv-node-options.mjs: NODE_OPTIONS is not available in Workers'
);
}

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const relativePath = '../fixtures/dotenv/node-options.env';

describe('.env supports NODE_OPTIONS', () => {
Expand Down
Loading