Skip to content

node:test watch mode with isolation: 'none' ignores cwd-scoped discovery and reuses parent argv #63689

@trivikr

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { run } from 'node:test';
import { mkdtemp, writeFile, readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { tmpdir } from 'node:os';

const cwd = await mkdtemp(join(tmpdir(), 'node-test-'));
const marker = join(cwd, 'ran');

await writeFile(join(cwd, 'test.js'), `
  const test = require('node:test');
  const { writeFileSync } = require('node:fs');
  test('from cwd', () => writeFileSync(${JSON.stringify(marker)}, 'yes'));
`);

const ac = new AbortController();
const stream = run({
  cwd,
  watch: true,
  isolation: 'none',
  signal: ac.signal,
});

stream.on('data', ({ type }) => {
  if (type === 'test:watch:drained') ac.abort();
});

for await (const _ of stream);

const ran = await readFile(marker, 'utf8').catch(() => 'no');
console.log({ ran });

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

{ ran: 'yes' }

run({ cwd, watch: true, isolation: 'none' }) should discover and execute tests from the supplied cwd, then report the result of those tests. In the repro, the cwd fixture should run and write the marker file.

What do you see instead?

{ ran: 'no' }

The isolation-none watch child is spawned using the parent process argv while its working directory is changed to the supplied cwd. This can run the wrong entry point, recurse into the driver, or execute no intended cwd test, so the marker is not written.

Additional information

This is likely the same failure mode behind test-runner/test-run-watch-cwd-isolation-none: that test expects one pass from the fixture copied into tmpdir.path, but the implementation can spawn a watch child using the outer test’s argv instead of the cwd-scoped fixture. Depending on invocation and tmpdir state, it may report zero passes, fail recursively, or exit with code 1, making the CI failure flaky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions