Skip to content

Commit 9f345a9

Browse files
committed
test: add test for worker NODE_OPTIONS without env option
1 parent a352178 commit 9f345a9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
// Tests that NODE_OPTIONS set at runtime in the parent process
4+
// are picked up by a worker thread even when the env option is
5+
// not explicitly provided to the Worker constructor.
6+
const { Worker, isMainThread } = require('worker_threads');
7+
8+
if (isMainThread) {
9+
process.env.NODE_OPTIONS = '--trace-exit';
10+
new Worker(__filename);
11+
} else {
12+
setImmediate(() => {
13+
process.nextTick(() => {
14+
process.exit(0);
15+
});
16+
});
17+
}

test/parallel/test-worker-node-options.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,20 @@ spawnSyncAndAssert(
3838
stderr: /spawn-worker-with-trace-exit\.js:17/
3939
}
4040
);
41+
42+
// Test that NODE_OPTIONS set at runtime in the parent process are
43+
// picked up by a worker even when the env option is not provided.
44+
spawnSyncAndAssert(
45+
process.execPath,
46+
[
47+
fixtures.path('spawn-worker-without-env-option'),
48+
],
49+
{
50+
env: {
51+
...process.env,
52+
}
53+
},
54+
{
55+
stderr: /spawn-worker-without-env-option\.js:14/
56+
}
57+
);

0 commit comments

Comments
 (0)