microsoft / microsoft/playwright
[Feature]: Add `endTime` to `TestResult`
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
### 🚀 Feature Request
Add `endTime` property to `TestResult` which would be the end time of this particular test run.
(and probably add it to `TestStep` as well)
### Example
_No response_
### Motivation
Currently `testResult.startTime` + `testResult.duration` is smaller than the actual end time. So computing the end time from these two properties is not accurate.
In our use case, we need a more accurate timestamp because we match server logs to a specific test based on time.
Test showing this behaviour
```ts
test('should approximate end time from with startTime + duration', async ({ runInlineTest }) => {
const result = await runInlineTest({
'reporter.ts': `
class Reporter {
onTestEnd(test, result) {
console.log('%%start=' + result.startTime.getTime());
console.log('%%duration=' + result.duration);
}
onStdOut(data) {
// forward test stdout so %%actualEndTest lines reach outputLines
process.stdout.write(data.toString());
}
}
module.exports = Reporter;
`,
'playwright.config.ts': `module.exports = { reporter: './reporter' };`,
'a.spec.ts': `
import { test } from '@playwright/test';
test('timing', async () => {
await new Promise(f => setTimeout(f, 250));
console.log('%%actualEndTest=' + Date.now());
});
`,
}, { reporter: '', workers: 1 });
const start = Number(result.outputLines.find(l => l.startsWith('start='))!.split('=')[1]);
const duration = Number(result.outputLines.find(l => l.startsWith('duration='))!.split('=')[1]);
const actualEndTest = Number(result.outputLines.find(l => l.startsWith('actualEndTest='))!.split('=')[1]);
const reportedTestEnd = start + duration;
const delta = actualEndTest - reportedTestEnd;
const dateToTime = (ms: number) => new Date(ms).toISOString().slice(11, 23); // HH:MM:SS.mmm
console.log([
`start\t\t${dateToTime(start)}`,
`reportedEnd\t${dateToTime(reportedTestEnd)}`,
`actualEnd\t${dateToTime(actualEndTest)}`,
`durationMs\t${duration} ms`,
`deltaMs\t\t${delta} ms`,
].join('\n'));
});
```
Relative: #38604
Contributor guide
Research direction
Start at the TestResult and TestStep API definitions and trace the reporter's onTestEnd path, focusing on how startTime and duration are populated. Use the supplied runInlineTest reproduction for coverage and verify that the exposed endTime matches actual test completion; done when TestResult provides an accurate timestamp, with TestStep covered if included.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- playwright, typescript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100