Skip to content

Commit

Permalink
test: refactor watch cwd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Oct 1, 2024
1 parent e995bec commit c6d0cec
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 51 deletions.
58 changes: 57 additions & 1 deletion test/parallel/test-runner-run-watch.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Flags: --expose-internals
import * as common from '../common/index.mjs';
import { describe, it, beforeEach } from 'node:test';
import { describe, it, beforeEach, run } from 'node:test';
import assert from 'node:assert';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
Expand Down Expand Up @@ -269,4 +269,60 @@ describe('test runner watch mode', () => {
}
);
});

it('should run with different cwd while in watch mode', async () => {
const controller = new AbortController();
const stream = run({
cwd: tmpdir.path,
watch: true,
signal: controller.signal,
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should run with different cwd while in watch mode and isolation "none"', async () => {
const controller = new AbortController();
const stream = run({
cwd: tmpdir.path,
watch: true,
signal: controller.signal,
isolation: 'none',
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});

it('should run with different cwd while in watch mode and isolation "process"', async () => {
const controller = new AbortController();
const stream = run({
cwd: tmpdir.path,
watch: true,
signal: controller.signal,
isolation: 'process',
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
});
});
50 changes: 0 additions & 50 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -602,56 +602,6 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
assert.strictEqual(diagnostics.includes(entry), true);
}
});

it('should run with different cwd while in watch mode', async () => {
const controller = new AbortController();
const stream = run({
cwd: fixtures.path('test-runner', 'cwd'),
watch: true,
signal: controller.signal,
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
});

it('should run with different cwd while in watch mode and isolation "none"', async () => {
const controller = new AbortController();
const stream = run({
cwd: fixtures.path('test-runner', 'cwd'),
watch: true,
signal: controller.signal,
isolation: 'none',
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
});

it('should run with different cwd while in watch mode and isolation "process"', async () => {
const controller = new AbortController();
const stream = run({
cwd: fixtures.path('test-runner', 'cwd'),
watch: true,
signal: controller.signal,
isolation: 'process',
}).on('data', function({ type }) {
if (type === 'test:watch:drained') {
controller.abort();
}
});

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall(1));
});
});

describe('forceExit', () => {
Expand Down

0 comments on commit c6d0cec

Please sign in to comment.