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
2 changes: 1 addition & 1 deletion lib/adapters/test-result/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const getHistory = (steps?: PlaywrightTestResult['steps']): TestStepCompressed[]
[TestStepKey.Name]: step.title,
[TestStepKey.Args]: [],
[TestStepKey.IsFailed]: Boolean(step.error),
[TestStepKey.TimeStart]: step.startTime.getTime(),
[TestStepKey.TimeStart]: step.startTime instanceof Date ? step.startTime.getTime() : new Date(step.startTime).getTime(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When launched via "npx playwright test", its intance of Date.
When launched via "npx html-reporter --tool playwright", its ISO string

[TestStepKey.Duration]: step.duration,
[TestStepKey.Children]: getHistory(step.steps),
[TestStepKey.IsGroup]: step.steps?.length > 0
Expand Down
21 changes: 21 additions & 0 deletions test/unit/lib/adapters/test-result/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ describe('PlaywrightTestResultAdapter', () => {

assert.deepEqual(adapter.history, expectedHistory);
});

it('should work if step.startTime is ISO datetime string', () => {
const steps = [
{title: 'Step1', duration: 100, startTime: new Date(1000).toISOString()},
{title: 'Step2', duration: 200, startTime: new Date(2000).toISOString()}
];
const adapter = new PlaywrightTestResultAdapter(mkTestCase(), mkTestResult({steps} as any), UNKNOWN_ATTEMPT);
const expectedHistory = [mkTestStepCompressed({
[TestStepKey.Name]: 'Step1',
[TestStepKey.Duration]: 100,
[TestStepKey.TimeStart]: 1000,
[TestStepKey.Children]: []
}), mkTestStepCompressed({
[TestStepKey.Name]: 'Step2',
[TestStepKey.Duration]: 200,
[TestStepKey.TimeStart]: 2000,
[TestStepKey.Children]: []
})];

assert.deepEqual(adapter.history, expectedHistory);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the test differs from the previous one only by the field startTime. It seems we can get rid of duplication by using forEach

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

as those are just 2 tests, i think its more readable that way

});

describe('id', () => {
Expand Down