MCPcopy Index your code
hub / github.com/nodejs/node / testApiInChildProcess

Function testApiInChildProcess

test/parallel/test-trace-events-api.js:133–187  ·  view source on GitHub ↗
(execArgs, cb)

Source from the content-addressed store, hash-verified

131}
132
133function testApiInChildProcess(execArgs, cb) {
134 tmpdir.refresh();
135 // Save the current directory so we can chdir back to it later
136 const parentDir = process.cwd();
137 process.chdir(tmpdir.path);
138
139 const expectedBegins = [{ cat: 'foo', name: 'test1' }];
140 const expectedEnds = [{ cat: 'foo', name: 'test1' }];
141
142 const proc = cp.fork(__filename,
143 ['child'],
144 {
145 execArgv: [
146 '--expose-gc',
147 '--expose-internals',
148 '--no-warnings',
149 ...execArgs,
150 ]
151 });
152
153 proc.once('exit', common.mustCall(() => {
154 const file = tmpdir.resolve('node_trace.1.log');
155
156 assert(fs.existsSync(file));
157 fs.readFile(file, common.mustSucceed((data) => {
158 const traces = JSON.parse(data.toString()).traceEvents
159 .filter((trace) => trace.cat !== '__metadata');
160
161 assert.strictEqual(
162 traces.length,
163 expectedBegins.length + expectedEnds.length);
164 for (const trace of traces) {
165 assert.strictEqual(trace.pid, proc.pid);
166 switch (trace.ph) {
167 case 'b': {
168 const expectedBegin = expectedBegins.shift();
169 assert.strictEqual(trace.cat, expectedBegin.cat);
170 assert.strictEqual(trace.name, expectedBegin.name);
171 break;
172 }
173 case 'e': {
174 const expectedEnd = expectedEnds.shift();
175 assert.strictEqual(trace.cat, expectedEnd.cat);
176 assert.strictEqual(trace.name, expectedEnd.name);
177 break;
178 }
179 default:
180 assert.fail('Unexpected trace event phase');
181 }
182 }
183 process.chdir(parentDir);
184 cb && process.nextTick(cb);
185 }));
186 }));
187}

Callers 1

Calls 12

chdirMethod · 0.80
filterMethod · 0.65
parseMethod · 0.65
assertFunction · 0.50
refreshMethod · 0.45
onceMethod · 0.45
resolveMethod · 0.45
existsSyncMethod · 0.45
readFileMethod · 0.45
toStringMethod · 0.45
shiftMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…