|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const { spawnSync } = require('child_process'); |
| 6 | + |
| 7 | +const spawnTimeout = common.platformTimeout(30_000); |
| 8 | + |
| 9 | +function spawnNode(args, options = undefined) { |
| 10 | + const result = spawnSync(process.execPath, args, { |
| 11 | + __proto__: null, |
| 12 | + encoding: 'utf8', |
| 13 | + timeout: spawnTimeout, |
| 14 | + ...options, |
| 15 | + }); |
| 16 | + assert.ifError(result.error); |
| 17 | + assert.strictEqual(result.signal, null); |
| 18 | + return result; |
| 19 | +} |
| 20 | + |
| 21 | +function spawnBench(args, options = undefined) { |
| 22 | + return spawnNode(['--no-warnings', '--bench', ...args], options); |
| 23 | +} |
| 24 | + |
| 25 | +for (const { args, message } of [ |
| 26 | + { |
| 27 | + args: ['--bench-isolation=invalid', 'unused.js'], |
| 28 | + message: /invalid value for --bench-isolation/, |
| 29 | + }, |
| 30 | + { |
| 31 | + args: ['--bench-samples=0', 'unused.js'], |
| 32 | + message: /--bench-samples must be greater than 0/, |
| 33 | + }, |
| 34 | + { |
| 35 | + args: ['--bench-warmup=4294967296', 'unused.js'], |
| 36 | + message: /--bench-warmup.*out of range/, |
| 37 | + }, |
| 38 | + { |
| 39 | + args: ['--bench-samples=2x', 'unused.js'], |
| 40 | + message: /invalid value for --bench-samples/, |
| 41 | + }, |
| 42 | + { |
| 43 | + args: ['--bench-warmup=abc', 'unused.js'], |
| 44 | + message: /invalid value for --bench-warmup/, |
| 45 | + }, |
| 46 | + { |
| 47 | + args: ['--bench-name-pattern=[', 'unused.js'], |
| 48 | + message: /invalid regular expression/, |
| 49 | + }, |
| 50 | + { |
| 51 | + args: ['--eval=1', 'unused.js'], |
| 52 | + message: /either --bench or --eval can be used, not both/, |
| 53 | + }, |
| 54 | + { |
| 55 | + args: ['--interactive', 'unused.js'], |
| 56 | + message: /either --bench or --interactive can be used, not both/, |
| 57 | + }, |
| 58 | + { |
| 59 | + args: ['--watch', 'unused.js'], |
| 60 | + message: /either --bench or --watch can be used, not both/, |
| 61 | + }, |
| 62 | + { |
| 63 | + args: ['--watch-path=.', 'unused.js'], |
| 64 | + message: /either --bench or --watch can be used, not both/, |
| 65 | + }, |
| 66 | + { |
| 67 | + args: ['--check', 'unused.js'], |
| 68 | + message: /either --bench or --check can be used, not both/, |
| 69 | + }, |
| 70 | + { |
| 71 | + args: ['--test', 'unused.js'], |
| 72 | + message: /either --bench or --test can be used, not both/, |
| 73 | + }, |
| 74 | +]) { |
| 75 | + const result = spawnBench(args); |
| 76 | + assert.notStrictEqual(result.status, 0); |
| 77 | + assert.match(result.stderr, message); |
| 78 | +} |
0 commit comments