mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
384f5d44a8
Some tests are assuming they will be run from a directory that do not contain any quote or special character in its path. That assumption is not necessary, using `JSON.stringify` or `pathToFileURL` ensures the test can be run whatever the path looks like. PR-URL: https://github.com/nodejs/node/pull/48958 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Michaël Zasso <targos@protonmail.com>
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cp = require('child_process');
|
|
const fs = require('fs');
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
const CODE = 'const { Worker } = require(\'worker_threads\'); ' +
|
|
`new Worker(${JSON.stringify(__filename)}, { name: 'foo' })`;
|
|
const FILE_NAME = 'node_trace.1.log';
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
process.chdir(tmpdir.path);
|
|
|
|
const proc = cp.spawn(process.execPath,
|
|
[ '--trace-event-categories', 'node',
|
|
'-e', CODE ]);
|
|
proc.once('exit', common.mustCall(() => {
|
|
assert(fs.existsSync(FILE_NAME));
|
|
fs.readFile(FILE_NAME, common.mustCall((err, data) => {
|
|
const traces = JSON.parse(data.toString()).traceEvents;
|
|
assert(traces.length > 0);
|
|
assert(traces.some((trace) =>
|
|
trace.cat === '__metadata' && trace.name === 'thread_name' &&
|
|
trace.args.name === '[worker 1] foo'));
|
|
}));
|
|
}));
|
|
} else {
|
|
// Do nothing here.
|
|
}
|