Skip to content

Commit 06e95fb

Browse files
committed
benchmark: use options.filename when, for esm, require.main.filename is undefined
1 parent 4f70132 commit 06e95fb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

benchmark/common.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class Benchmark {
1919
this._time = 0n;
2020

2121
// Use the file name as the name of the benchmark
22-
this.name = require.main.filename.slice(__dirname.length + 1);
22+
// For esm, require.main is undefined so use options.filename
23+
this.filename = options.filename || require.main?.filename
24+
this.name = this.filename.replace(/.*\//, '')
2325

2426
// Execution arguments i.e. flags used to run the jobs
2527
this.flags = process.env.NODE_BENCHMARK_FLAGS?.split(/\s+/) ?? [];
@@ -224,7 +226,7 @@ class Benchmark {
224226
childArgs.push(`${key}=${value}`);
225227
}
226228

227-
const child = child_process.fork(require.main.filename, childArgs, {
229+
const child = child_process.fork(this.filename, childArgs, {
228230
env: childEnv,
229231
execArgv: this.flags.concat(process.execArgv),
230232
});

0 commit comments

Comments
 (0)