-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
test_runner: add env option to run function #61367
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,7 +403,7 @@ function runTestFile(path, filesWatcher, opts) { | |
| const subtest = opts.root.createSubtest(FileTest, testPath, testOpts, async (t) => { | ||
| const args = getRunArgs(path, opts); | ||
| const stdio = ['pipe', 'pipe', 'pipe']; | ||
| const env = { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' }; | ||
| const env = opts.env || { __proto__: null, ...process.env, NODE_TEST_CONTEXT: 'child-v8' }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It must be preserved even if the user passes I would suggest, in any case, adding a snapshot test when using this option to cover the E2E once the option has been provided! |
||
| if (watchMode) { | ||
| stdio.push('ipc'); | ||
| env.WATCH_REPORT_DEPENDENCIES = '1'; | ||
|
|
@@ -610,6 +610,7 @@ function run(options = kEmptyObject) { | |
| argv = [], | ||
| cwd = process.cwd(), | ||
| rerunFailuresFilePath, | ||
| env, | ||
| } = options; | ||
|
|
||
| if (files != null) { | ||
|
|
@@ -718,6 +719,14 @@ function run(options = kEmptyObject) { | |
| validatePath(globalSetupPath, 'options.globalSetupPath'); | ||
| } | ||
|
|
||
| if (env != null) { | ||
| validateObject(env); | ||
|
|
||
| if (isolation === 'none') { | ||
| throw new ERR_INVALID_ARG_VALUE('options.env', env, 'is not supported with isolation=\'none\''); | ||
| } | ||
| } | ||
|
|
||
| const rootTestOptions = { __proto__: null, concurrency, timeout, signal }; | ||
| const globalOptions = { | ||
| __proto__: null, | ||
|
|
@@ -763,6 +772,7 @@ function run(options = kEmptyObject) { | |
| argv, | ||
| execArgv, | ||
| rerunFailuresFilePath, | ||
| env, | ||
| }; | ||
|
|
||
| if (isolation === 'process') { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| const { test } = require('node:test'); | ||
|
|
||
| test('process.env is correct', (t) => { | ||
| t.assert.strictEqual(process.env.FOOBAR, 'FUZZBUZZ'); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be worth specifying here that these variables will override those from the main process