Files
node/test/parallel/test-bench-cli-arguments.js
James M Snell dff7a160fe lib: put node:bench behind an --experimental-bench flag
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65920
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-09-12 08:29:12 +00:00

81 lines
2.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const spawnTimeout = common.platformTimeout(30_000);
function spawnNode(args, options = undefined) {
const result = spawnSync(process.execPath, args, {
__proto__: null,
encoding: 'utf8',
timeout: spawnTimeout,
...options,
});
assert.ifError(result.error);
assert.strictEqual(result.signal, null);
return result;
}
function spawnBench(args, options = undefined) {
return spawnNode([
'--no-warnings', '--experimental-bench', '--bench', ...args,
], options);
}
for (const { args, message } of [
{
args: ['--bench-isolation=invalid', 'unused.js'],
message: /invalid value for --bench-isolation/,
},
{
args: ['--bench-samples=0', 'unused.js'],
message: /--bench-samples must be greater than 0/,
},
{
args: ['--bench-warmup=4294967296', 'unused.js'],
message: /--bench-warmup.*out of range/,
},
{
args: ['--bench-samples=2x', 'unused.js'],
message: /invalid value for --bench-samples/,
},
{
args: ['--bench-warmup=abc', 'unused.js'],
message: /invalid value for --bench-warmup/,
},
{
args: ['--bench-name-pattern=[', 'unused.js'],
message: /invalid regular expression/,
},
{
args: ['--eval=1', 'unused.js'],
message: /either --bench or --eval can be used, not both/,
},
{
args: ['--interactive', 'unused.js'],
message: /either --bench or --interactive can be used, not both/,
},
{
args: ['--watch', 'unused.js'],
message: /either --bench or --watch can be used, not both/,
},
{
args: ['--watch-path=.', 'unused.js'],
message: /either --bench or --watch can be used, not both/,
},
{
args: ['--check', 'unused.js'],
message: /either --bench or --check can be used, not both/,
},
{
args: ['--test', 'unused.js'],
message: /either --bench or --test can be used, not both/,
},
]) {
const result = spawnBench(args);
assert.notStrictEqual(result.status, 0);
assert.match(result.stderr, message);
}