• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --no-warnings
2
3'use strict';
4const common = require('../common');
5const assert = require('assert');
6const cp = require('child_process');
7const path = require('path');
8const fs = require('fs');
9const tmpdir = require('../common/tmpdir');
10
11// This tests the emission of node.environment trace events
12
13const names = new Set([
14  'Environment',
15  'RunAndClearNativeImmediates',
16  'CheckImmediate',
17  'RunTimers',
18  'BeforeExit',
19  'RunCleanup',
20  'AtExit'
21]);
22
23if (process.argv[2] === 'child') {
24  // This is just so that the child has something to do.
25  1 + 1;
26  // These ensure that the RunTimers, CheckImmediate, and
27  // RunAndClearNativeImmediates appear in the list.
28  setImmediate(() => { 1 + 1; });
29  setTimeout(() => { 1 + 1; }, 1);
30} else {
31  tmpdir.refresh();
32
33  const proc = cp.fork(__filename,
34                       [ 'child' ], {
35                         cwd: tmpdir.path,
36                         execArgv: [
37                           '--trace-event-categories',
38                           'node.environment'
39                         ]
40                       });
41
42  proc.once('exit', common.mustCall(async () => {
43    const file = path.join(tmpdir.path, 'node_trace.1.log');
44    const checkSet = new Set();
45
46    assert(fs.existsSync(file));
47    const data = await fs.promises.readFile(file);
48    JSON.parse(data.toString()).traceEvents
49      .filter((trace) => trace.cat !== '__metadata')
50      .forEach((trace) => {
51        assert.strictEqual(trace.pid, proc.pid);
52        assert(names.has(trace.name));
53        checkSet.add(trace.name);
54      });
55
56    assert.deepStrictEqual(names, checkSet);
57  }));
58}
59