Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add runner watch mode isolation tests #54888

Merged
Merged
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
64 changes: 37 additions & 27 deletions test/parallel/test-runner-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ async function testWatch({
file,
action = 'update',
fileToCreate,
isolation,
}) {
const ran1 = util.createDeferredPromise();
const ran2 = util.createDeferredPromise();
const child = spawn(process.execPath,
['--watch', '--test', '--test-reporter=spec',
isolation ? `--experimental-test-isolation=${isolation}` : '',
file ? fixturePaths[file] : undefined].filter(Boolean),
{ encoding: 'utf8', stdio: 'pipe', cwd: tmpdir.path });
let stdout = '';
Expand Down Expand Up @@ -166,31 +168,39 @@ async function testWatch({

describe('test runner watch mode', () => {
beforeEach(refresh);
it('should run tests repeatedly', async () => {
await testWatch({ file: 'test.js', fileToUpdate: 'test.js' });
});

it('should run tests with dependency repeatedly', async () => {
await testWatch({ file: 'test.js', fileToUpdate: 'dependency.js' });
});

it('should run tests with ESM dependency', async () => {
await testWatch({ file: 'test.js', fileToUpdate: 'dependency.mjs' });
});

it('should support running tests without a file', async () => {
await testWatch({ fileToUpdate: 'test.js' });
});

it('should support a watched test file rename', async () => {
await testWatch({ fileToUpdate: 'test.js', action: 'rename' });
});

it('should not throw when delete a watched test file', async () => {
await testWatch({ fileToUpdate: 'test.js', action: 'delete' });
});

it('should run new tests when a new file is created in the watched directory', async () => {
await testWatch({ action: 'create', fileToCreate: 'new-test-file.test.js' });
});
for (const isolation of ['none', 'process']) {
describe(`isolation: ${isolation}`, () => {
it('should run tests repeatedly', async () => {
await testWatch({ file: 'test.js', fileToUpdate: 'test.js', isolation });
});

it('should run tests with dependency repeatedly', async () => {
await testWatch({ file: 'test.js', fileToUpdate: 'dependency.js', isolation });
});

it('should run tests with ESM dependency', async () => {
await testWatch({ file: 'test.js', fileToUpdate: 'dependency.mjs', isolation });
});

it('should support running tests without a file', async () => {
await testWatch({ fileToUpdate: 'test.js', isolation });
});

it('should support a watched test file rename', async () => {
await testWatch({ fileToUpdate: 'test.js', action: 'rename', isolation });
});

it('should not throw when delete a watched test file', async () => {
await testWatch({ fileToUpdate: 'test.js', action: 'delete', isolation });
});

it('should run new tests when a new file is created in the watched directory', {
todo: isolation === 'none' ?
'This test is failing when isolation is set to none and must be fixed' :
undefined,
}, async () => {
await testWatch({ action: 'create', fileToCreate: 'new-test-file.test.js', isolation });
});
});
}
});
Loading