(
opt, want, command = 'console.log("B")', wantsError = false, testWorker = true
)
| 96 | } |
| 97 | |
| 98 | function expect( |
| 99 | opt, want, command = 'console.log("B")', wantsError = false, testWorker = true |
| 100 | ) { |
| 101 | const argv = [ |
| 102 | // --perf-basic-prof and --perf-basic-prof-only-functions write to /tmp by default. |
| 103 | `--perf-basic-prof-path=${tmpdir.path}`, |
| 104 | '-e', |
| 105 | command, |
| 106 | ]; |
| 107 | const opts = { |
| 108 | cwd: tmpdir.path, |
| 109 | env: Object.assign({}, process.env, { NODE_OPTIONS: opt }), |
| 110 | maxBuffer: 1e6, |
| 111 | }; |
| 112 | if (typeof want === 'string') |
| 113 | want = new RegExp(want); |
| 114 | |
| 115 | const test = common.mustCallAtLeast((type) => common.mustCall((err, stdout) => { |
| 116 | const o = JSON.stringify(opt); |
| 117 | if (wantsError) { |
| 118 | assert.ok(err, `${type}: expected error for ${o}`); |
| 119 | stdout = err.stack; |
| 120 | } else { |
| 121 | assert.ifError(err, `${type}: failed for ${o}`); |
| 122 | } |
| 123 | if (want.test(stdout)) return; |
| 124 | |
| 125 | assert.fail( |
| 126 | `${type}: for ${o}, failed to find ${want} in: <\n${stdout}\n>` |
| 127 | ); |
| 128 | })); |
| 129 | |
| 130 | exec(process.execPath, argv, opts, test('child process')); |
| 131 | if (testWorker) |
| 132 | workerTest(opts, command, wantsError, test('worker')); |
| 133 | } |
| 134 | |
| 135 | async function collectStream(readable) { |
| 136 | readable.setEncoding('utf8'); |
no test coverage detected