summaryrefslogtreecommitdiff
path: root/test/parallel/test-trace-events-category-used.js
blob: 3d584b1f2a85dd3574fb4203a1e1bf4519a72f9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');

const CODE = `
  const { internalBinding } = require('internal/test/binding');
  const { isTraceCategoryEnabled } = internalBinding('trace_events');
  console.log(
    isTraceCategoryEnabled("custom")
  );
`;

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const procEnabled = cp.spawn(
  process.execPath,
  [ '--trace-event-categories', 'custom',
    // Make test less noisy since internal/test/binding
    // emits a warning.
    '--no-warnings',
    '--expose-internals',
    '-e', CODE ],
  { cwd: tmpdir.path }
);
let procEnabledOutput = '';

procEnabled.stdout.on('data', (data) => procEnabledOutput += data);
procEnabled.stderr.pipe(process.stderr);
procEnabled.once('close', common.mustCall(() => {
  assert.strictEqual(procEnabledOutput, 'true\n');
}));

const procDisabled = cp.spawn(
  process.execPath,
  [ '--trace-event-categories', 'other',
    // Make test less noisy since internal/test/binding
    // emits a warning.
    '--no-warnings',
    '--expose-internals',
    '-e', CODE ],
  { cwd: tmpdir.path }
);
let procDisabledOutput = '';

procDisabled.stdout.on('data', (data) => procDisabledOutput += data);
procDisabled.stderr.pipe(process.stderr);
procDisabled.once('close', common.mustCall(() => {
  assert.strictEqual(procDisabledOutput, 'false\n');
}));