Skip to content

Commit 75034b4

Browse files
committed
Fix --expose-gc flag inheritance for --test in node 24+
1 parent 134f74a commit 75034b4

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"output": []
204204
},
205205
"test:codeactions": {
206-
"command": "node --test --test-reporter=spec lib/test/codeactions.test.js",
206+
"command": "node --test --test-reporter=dot lib/test/codeactions.test.js",
207207
"env": {
208208
"NODE_OPTIONS": "--enable-source-maps"
209209
},
@@ -236,7 +236,7 @@
236236
"output": []
237237
},
238238
"test:diagnostic": {
239-
"command": "node --test --test-reporter=spec lib/test/diagnostic.test.js",
239+
"command": "node --test --test-reporter=dot lib/test/diagnostic.test.js",
240240
"env": {
241241
"NODE_OPTIONS": "--enable-source-maps"
242242
},
@@ -291,7 +291,7 @@
291291
"output": []
292292
},
293293
"test:gc": {
294-
"command": "node --test --test-reporter=spec --expose-gc lib/test/gc.test.js",
294+
"command": "node --test --test-reporter=dot lib/test/gc.test.js",
295295
"env": {
296296
"NODE_OPTIONS": "--enable-source-maps"
297297
},

src/test/gc.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ import {SimpleLogger} from '../logging/simple-logger.js';
1717
import {WorkerPool} from '../util/worker-pool.js';
1818
import {registerExecutionConstructorHook} from '../execution/base.js';
1919
import {Console} from '../logging/logger.js';
20+
import v8 from 'node:v8';
21+
import vm from 'node:vm';
2022

2123
let numLiveExecutors = 0;
2224
let numLiveExecutions = 0;
2325

24-
const collectGarbage = (() => {
25-
if (global.gc == null) {
26-
throw new Error('gc.test must be invoked with --expose-gc');
26+
const collectGarbage = () => {
27+
if (!global.gc) {
28+
v8.setFlagsFromString('--expose_gc');
29+
global.gc = vm.runInNewContext('gc');
2730
}
28-
return global.gc;
29-
})();
31+
global.gc!();
32+
};
3033

3134
beforeEach(() => {
3235
const executorFinalizationRegistry = new FinalizationRegistry(() => {

0 commit comments

Comments
 (0)