feat(pageSnapshot): add header comment with info

This commit is contained in:
Simon Knott 2025-02-27 08:42:34 +01:00
parent 17c4d8e5ec
commit c66c4fdf64
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 8 additions and 1 deletions

View file

@ -630,7 +630,8 @@ class ArtifactsRecorder {
this._pageSnapshotRecorder = new SnapshotRecorder(this, pageSnapshot, 'pageSnapshot', 'text/plain', '.snapshot.yml', async (page, path) => {
const ariaSnapshot = await page.locator('body').ariaSnapshot({ timeout: 5000 });
await fs.promises.writeFile(path, ariaSnapshot);
const header = `# ${this._testInfo.titlePath.join(' >> ')}\n# ARIA snapshot of the page contents after test ${this._testInfo._isFailure() ? 'failed' : 'finished'}\n`;
await fs.promises.writeFile(path, header + ariaSnapshot);
});
}

View file

@ -459,6 +459,12 @@ test('should work with pageSnapshot: on', async ({ runInlineTest }, testInfo) =>
' test-failed-1.snapshot.yml',
' test-failed-2.snapshot.yml',
]);
expect(fs.readFileSync(testInfo.outputPath('test-results', 'artifacts-failing', 'test-failed-1.snapshot.yml'), { encoding: 'utf-8' })).toEqual(`
# artifacts.spec.ts >> failing
# ARIA snapshot of the page contents after test failed
- text: I am the page
`.trim());
});
test('should work with pageSnapshot: only-on-failure', async ({ runInlineTest }, testInfo) => {