Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add isolation test cases to test runner run watch
  • Loading branch information
pmarchini committed Oct 1, 2024
commit 18138e974f9f5108d357a693cd07003bed31368a
20 changes: 19 additions & 1 deletion test/fixtures/test-runner-watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,37 @@ const options = {
file: {
type: 'string',
},
cwd: {
type: 'string',
},
isolation: {
type: 'string',
},
};
const {
values,
positionals,
} = parseArgs({ args: process.argv.slice(2), options });

let files;
let cwd;
let isolation;

if (values.file) {
files = [values.file];
}

if (values.cwd) {
cwd = values.cwd;
}

if (values.isolation) {
isolation = values.isolation;
}

run({
files,
watch: true
watch: true,
...(cwd ? { cwd } : {}),
...(isolation ? { isolation } : {}),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be simplified to:

Suggested change
...(cwd ? { cwd } : {}),
...(isolation ? { isolation } : {}),
cwd,
isolation,

}).compose(tap).pipe(process.stdout);
65 changes: 61 additions & 4 deletions test/parallel/test-runner-run-watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ function refresh() {

const runner = join(import.meta.dirname, '..', 'fixtures', 'test-runner-watch.mjs');

async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.path, fileToCreate }) {
async function testWatch(
{
fileToUpdate,
file,
action = 'update',
cwd = tmpdir.path,
fileToCreate,
runnerCwd,
isolation
}
) {
const ran1 = util.createDeferredPromise();
const ran2 = util.createDeferredPromise();
const args = [runner];
if (file) args.push('--file', file);
if (runnerCwd) args.push('--cwd', runnerCwd);
if (isolation) args.push('--isolation', isolation);
const child = spawn(process.execPath,
args,
{ encoding: 'utf8', stdio: 'pipe', cwd });
Expand Down Expand Up @@ -221,7 +233,52 @@ describe('test runner watch mode', () => {
});
});

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' });
});
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' });
});

it(
'should execute run using a different cwd for the runner than the process cwd',
async () => {
await testWatch(
{
fileToUpdate: 'test.js',
action: 'rename',
cwd: import.meta.dirname,
runnerCwd: tmpdir.path
}
);
});

it(
'should execute run using a different cwd for the runner than the process cwd with isolation process',
async () => {
await testWatch(
{
fileToUpdate: 'test.js',
action: 'rename',
cwd: import.meta.dirname,
runnerCwd: tmpdir.path,
isolation: 'process'
}
);
});

// TODO: fix this case
// it(
// 'should execute run using a different cwd for the runner than the process cwd with isolation none',
// async () => {
// await testWatch(
// {
// fileToUpdate: 'test.js',
// action: 'rename',
// cwd: import.meta.dirname,
// runnerCwd: tmpdir.path,
// isolation: 'none'
// }
// );
// }
// );
});