GeezerVison is showing github.com — test_runner: recalculate run duration on watch restart · nodejs/node@8207828
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -503,7 +503,10 @@ function watchFiles(testFiles, opts) { |
503 | 503 | return; // Avoid rerunning files when file deleted |
504 | 504 | } |
505 | 505 | } |
506 | | - |
| 506 | + // Reset the root start time to recalculate the duration |
| 507 | + // of the run |
| 508 | + opts.root.clearExecutionTime(); |
| 509 | + // Restart test files |
507 | 510 | if (opts.isolation === 'none') { |
508 | 511 | PromisePrototypeThen(restartTestFile(kIsolatedProcessName), undefined, (error) => { |
509 | 512 | triggerUncaughtException(error, true /* fromPromise */); |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1341,6 +1341,11 @@ class Test extends AsyncResource { |
1341 | 1341 | this.parent.reportStarted(); |
1342 | 1342 | this.reporter.start(this.nesting, this.loc, this.name); |
1343 | 1343 | } |
| 1344 | + |
| 1345 | + clearExecutionTime() { |
| 1346 | + this.startTime = hrtime(); |
| 1347 | + this.endTime = null; |
| 1348 | + } |
1344 | 1349 | } |
1345 | 1350 |
|
1346 | 1351 | class TestHook extends Test { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-runner-run-watch.mjs +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -189,6 +189,8 @@ async function testWatch( |
189 | 189 | action === 'rename2' && await testRename(); |
190 | 190 | action === 'delete' && await testDelete(); |
191 | 191 | action === 'create' && await testCreate(); |
| 192 | + |
| 193 | + return runs; |
192 | 194 | } |
193 | 195 |
|
194 | 196 | describe('test runner watch mode', () => { |
@@ -241,6 +243,20 @@ describe('test runner watch mode', () => { |
241 | 243 | await testWatch({ action: 'create', fileToCreate: 'new-test-file.test.js' }); |
242 | 244 | }); |
243 | 245 |
|
| 246 | + // This test is flaky by its nature as it relies on the timing of 2 different runs |
| 247 | + // considering the number of digits in the duration_ms is 9 |
| 248 | + // the chances of having the same duration_ms are very low |
| 249 | + // but not impossible |
| 250 | + // In case of costant failures, consider increasing the number of tests |
| 251 | + it('should recalculate the run duration on a watch restart', async () => { |
| 252 | + const testRuns = await testWatch({ file: 'test.js', fileToUpdate: 'test.js' }); |
| 253 | + const durations = testRuns.map((run) => { |
| 254 | + const runDuration = run.match(/# duration_ms\s([\d.]+)/); |
| 255 | + return runDuration; |
| 256 | + }); |
| 257 | + assert.notDeepStrictEqual(durations[0][1], durations[1][1]); |
| 258 | + }); |
| 259 | + |
244 | 260 | describe('test runner watch mode with different cwd', () => { |
245 | 261 | it( |
246 | 262 | 'should execute run using a different cwd for the runner than the process cwd', |
|