Skip to content
Merged
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
5 changes: 4 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ function watchFiles(testFiles, opts) {
return; // Avoid rerunning files when file deleted
}
}

// Reset the root start time to recalculate the duration
// of the run
opts.root.clearExecutionTime();
// Restart test files
if (opts.isolation === 'none') {
PromisePrototypeThen(restartTestFile(kIsolatedProcessName), undefined, (error) => {
triggerUncaughtException(error, true /* fromPromise */);
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,11 @@ class Test extends AsyncResource {
this.parent.reportStarted();
this.reporter.start(this.nesting, this.loc, this.name);
}

clearExecutionTime() {
this.startTime = hrtime();
this.endTime = null;
}
}

class TestHook extends Test {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-runner-run-watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ async function testWatch(
action === 'rename2' && await testRename();
action === 'delete' && await testDelete();
action === 'create' && await testCreate();

return runs;
}

describe('test runner watch mode', () => {
Expand Down Expand Up @@ -241,6 +243,20 @@ describe('test runner watch mode', () => {
await testWatch({ action: 'create', fileToCreate: 'new-test-file.test.js' });
});

// This test is flaky by its nature as it relies on the timing of 2 different runs
// considering the number of digits in the duration_ms is 9
// the chances of having the same duration_ms are very low
// but not impossible
// In case of costant failures, consider increasing the number of tests
it('should recalculate the run duration on a watch restart', async () => {
const testRuns = await testWatch({ file: 'test.js', fileToUpdate: 'test.js' });
const durations = testRuns.map((run) => {
const runDuration = run.match(/# duration_ms\s([\d.]+)/);
return runDuration;
});
assert.notDeepStrictEqual(durations[0][1], durations[1][1]);
});

describe('test runner watch mode with different cwd', () => {
it(
'should execute run using a different cwd for the runner than the process cwd',
Expand Down
Loading