fix playwright.trace tests

This commit is contained in:
Simon Knott 2024-12-17 09:58:34 +01:00
parent 617dfcc738
commit 0861d29630
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 6 additions and 8 deletions

View file

@ -638,7 +638,7 @@ class ArtifactsRecorder {
try {
const screenshotPath = this._createScreenshotAttachmentPath();
await fs.promises.rename(file, screenshotPath);
this._attachScreenshot(screenshotPath);
await this._attachScreenshot(screenshotPath);
} catch {
}
}
@ -665,14 +665,14 @@ class ArtifactsRecorder {
if (temporary)
this._temporaryScreenshots.push(screenshotPath);
else
this._attachScreenshot(screenshotPath);
await this._attachScreenshot(screenshotPath);
} catch {
// Screenshot may fail, just ignore.
}
}
private _attachScreenshot(screenshotPath: string) {
this._testInfo.attachments.push({ name: 'screenshot', path: screenshotPath, contentType: 'image/png' });
private async _attachScreenshot(screenshotPath: string) {
await this._testInfo.attach('screenshot', { path: screenshotPath, contentType: 'image/png' });
}
private async _screenshotOnTestFailure() {

View file

@ -540,7 +540,7 @@ test('should include attachments by default', async ({ runInlineTest, server },
contentType: 'text/plain',
sha1: expect.any(String),
}]);
expect([...trace.resources.keys()].filter(f => f.startsWith('resources/'))).toHaveLength(1);
expect([...trace.resources.keys()]).toContain(`resources/${trace.actions[1].attachments[0].sha1}`);
});
test('should opt out of attachments', async ({ runInlineTest, server }, testInfo) => {
@ -566,7 +566,7 @@ test('should opt out of attachments', async ({ runInlineTest, server }, testInfo
'After Hooks',
]);
expect(trace.actions[1].attachments).toEqual(undefined);
expect([...trace.resources.keys()].filter(f => f.startsWith('resources/'))).toHaveLength(0);
expect([...trace.resources.keys()].filter(f => f.startsWith('resources/'))).toEqual([expect.stringMatching(/^resources\/src@.*$/)]);
});
test('should record with custom page fixture', async ({ runInlineTest }, testInfo) => {
@ -730,8 +730,6 @@ test('should not throw when attachment is missing', async ({ runInlineTest }, te
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
const trace = await parseTrace(testInfo.outputPath('test-results', 'a-passes', 'trace.zip'));
expect(trace.actionTree).toContain('attach "screenshot"');
});
test('should not throw when screenshot on failure fails', async ({ runInlineTest, server }, testInfo) => {