forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-trace-events-vm.js
41 lines (36 loc) · 1.12 KB
/
test-trace-events-vm.js
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
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const names = [
'ContextifyScript::New',
'RunInContext',
];
if (process.argv[2] === 'child') {
const vm = require('vm');
vm.runInNewContext('1 + 1');
} else {
tmpdir.refresh();
const proc = cp.fork(__filename,
[ 'child' ], {
cwd: tmpdir.path,
execArgv: [
'--trace-event-categories',
'node.vm.script',
]
});
proc.once('exit', common.mustCall(() => {
const file = tmpdir.resolve('node_trace.1.log');
assert(fs.existsSync(file));
fs.readFile(file, common.mustCall((err, data) => {
const traces = JSON.parse(data.toString()).traceEvents
.filter((trace) => trace.cat !== '__metadata');
for (const trace of traces) {
assert.strictEqual(trace.pid, proc.pid);
assert(names.includes(trace.name));
}
}));
}));
}