MCPcopy Create free account
hub / github.com/nodejs/node / expect

Function expect

test/parallel/test-cli-node-options.js:98–133  ·  view source on GitHub ↗
(
  opt, want, command = 'console.log("B")', wantsError = false, testWorker = true
)

Source from the content-addressed store, hash-verified

96}
97
98function 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
135async function collectStream(readable) {
136 readable.setEncoding('utf8');

Callers 4

expectNoWorkerFunction · 0.70

Calls 7

workerTestFunction · 0.85
assignMethod · 0.80
testFunction · 0.70
execFunction · 0.50
okMethod · 0.45
testMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected