node/test/parallel/test-trace-events-promises.js
Livia Medeiros e738edce6a
test: use tmpdir.resolve()
Subsystems: blob, child_process, common, crypto, http, http2,
readline, repl, snapshot, trace_events

PR-URL: https://github.com/nodejs/node/pull/49127
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
2023-08-15 13:45:34 +00:00

43 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
if (process.argv[2] === 'child') {
const p = Promise.reject(1); // Handled later
Promise.reject(2); // Unhandled
setImmediate(() => {
p.catch(() => { /* intentional noop */ });
});
} else {
tmpdir.refresh();
const proc = cp.fork(__filename,
[ 'child' ], {
cwd: tmpdir.path,
execArgv: [
'--no-warnings',
'--trace-event-categories',
'node.promises.rejections',
]
});
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');
traces.forEach((trace) => {
assert.strictEqual(trace.pid, proc.pid);
assert.strictEqual(trace.name, 'rejections');
assert(trace.args.unhandled <= 2);
assert(trace.args.handledAfter <= 1);
});
}));
}));
}