Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/internal/main/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ if (isUsingInspector() && options.isolation === 'process') {
options.inspectPort = process.debugPort;
}

// Capture process state before passing to run() to avoid reading from process.cwd() inside run()
options.cwd = process.cwd();
options.globPatterns = ArrayPrototypeSlice(process.argv, 1);

debug('test runner configuration:', options);
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeShift,
ArrayPrototypeSlice,
ArrayPrototypeSome,
ArrayPrototypeSort,
ObjectAssign,
Expand Down Expand Up @@ -151,7 +150,8 @@ function getRunArgs(path, { forceExit,
execArgv,
rerunFailuresFilePath,
root: { timeout },
cwd }) {
cwd,
globPatterns }) {
const processNodeOptions = getOptionsAsFlagsFromBinding();
const runArgs = ArrayPrototypeFilter(processNodeOptions, filterExecArgv);

Expand Down Expand Up @@ -196,7 +196,7 @@ function getRunArgs(path, { forceExit,

if (path === kIsolatedProcessName) {
ArrayPrototypePush(runArgs, '--test');
ArrayPrototypePushApply(runArgs, ArrayPrototypeSlice(process.argv, 1));
ArrayPrototypePushApply(runArgs, globPatterns);
} else {
ArrayPrototypePush(runArgs, path);
}
Expand Down Expand Up @@ -888,7 +888,7 @@ function run(options = kEmptyObject) {
await root.harness.bootstrapPromise;
}
if (typeof setup === 'function') {
await setup(root.reporter);
await setup(root.reporter, cwd);
}

await runFiles();
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function parsePreviousRuns(rerunFailuresFilePath) {
return JSONParse(data);
}

async function getReportersMap(reporters, destinations) {
async function getReportersMap(reporters, destinations, cwd) {
return SafePromiseAllReturnArrayLike(reporters, async (name, i) => {
const destination = kBuiltinDestinations.get(destinations[i]) ??
createWriteStream(destinations[i], { __proto__: null, flush: true });
Expand All @@ -177,7 +177,7 @@ async function getReportersMap(reporters, destinations) {
let parentURL;

try {
parentURL = pathToFileURL(process.cwd() + '/').href;
parentURL = pathToFileURL((cwd ?? process.cwd()) + '/').href;
} catch {
parentURL = 'file:///';
}
Expand Down Expand Up @@ -328,8 +328,8 @@ function parseCommandLine() {
validatePath(rerunFailuresFilePath, '--test-rerun-failures');
}

const setup = reporterScope.bind(async (rootReporter) => {
const reportersMap = await getReportersMap(reporters, destinations);
const setup = reporterScope.bind(async (rootReporter, cwd) => {
const reportersMap = await getReportersMap(reporters, destinations, cwd);
for (let i = 0; i < reportersMap.length; i++) {
const { reporter, destination } = reportersMap[i];
compose(rootReporter, reporter).pipe(destination);
Expand Down