add test for case without snapshots and screenshots

This commit is contained in:
Simon Knott 2024-09-06 11:08:56 +02:00
parent e24a5ba8f9
commit 21fb8d84a0
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 15 additions and 3 deletions

View file

@ -31,7 +31,7 @@ type BaseWorkerFixtures = {
export type TraceViewerFixtures = { export type TraceViewerFixtures = {
showTraceViewer: (trace: string[], options?: {host?: string, port?: number}) => Promise<TraceViewerPage>; showTraceViewer: (trace: string[], options?: {host?: string, port?: number}) => Promise<TraceViewerPage>;
runAndTrace: (body: () => Promise<void>) => Promise<TraceViewerPage>; runAndTrace: (body: () => Promise<void>, optsOverrides?: Parameters<BrowserContext['tracing']['start']>[0]) => Promise<TraceViewerPage>;
}; };
class TraceViewerPage { class TraceViewerPage {
@ -127,9 +127,9 @@ export const traceViewerFixtures: Fixtures<TraceViewerFixtures, {}, BaseTestFixt
}, },
runAndTrace: async ({ context, showTraceViewer }, use, testInfo) => { runAndTrace: async ({ context, showTraceViewer }, use, testInfo) => {
await use(async (body: () => Promise<void>) => { await use(async (body: () => Promise<void>, optsOverrides = {}) => {
const traceFile = testInfo.outputPath('trace.zip'); const traceFile = testInfo.outputPath('trace.zip');
await context.tracing.start({ snapshots: true, screenshots: true, sources: true }); await context.tracing.start({ snapshots: true, screenshots: true, sources: true, ...optsOverrides });
await body(); await body();
await context.tracing.stop({ path: traceFile }); await context.tracing.stop({ path: traceFile });
return showTraceViewer([traceFile]); return showTraceViewer([traceFile]);

View file

@ -1483,3 +1483,15 @@ test('should allow showing screenshots instead of snapshots', async ({ runAndTra
await expect(screenshot).toBeVisible(); await expect(screenshot).toBeVisible();
}); });
test('should handle case where neither snapshots nor screenshots exist', async ({ runAndTrace, page, server }) => {
const traceViewer = await runAndTrace(async () => {
await page.goto(server.PREFIX + '/one-style.html');
}, { snapshots: false, screenshots: false });
await traceViewer.page.getByTitle('Settings').click();
await traceViewer.page.getByText('Show screenshot instead of snapshot').setChecked(true);
const screenshot = traceViewer.page.getByAltText(`Screenshot of page.goto > Action`);
await expect(screenshot).not.toBeVisible();
});