fix(toHaveScreenshot): stylePath as first arg (#29372)

This commit is contained in:
Max Schmitt 2024-02-05 22:52:16 +01:00 committed by GitHub
parent 57d841ffae
commit 8c007fd3fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -351,7 +351,7 @@ export async function toHaveScreenshot(
expectTypes(pageOrLocator, ['Page', 'Locator'], 'toHaveScreenshot');
return await zones.preserve(async () => {
// Loading from filesystem resets zones.
const style = await loadScreenshotStyles(optOptions.stylePath || config?.stylePath);
const style = await loadScreenshotStyles(helper.allOptions.stylePath || config?.stylePath);
return toHaveScreenshotContinuation.call(this, helper, page, locator, config, style);
});
}

View File

@ -1272,6 +1272,7 @@ test('should support stylePath option', async ({ runInlineTest }) => {
snapshotPathTemplate: '__screenshots__/{testFilePath}/{arg}{ext}',
}),
'__screenshots__/tests/a.spec.js/snapshot.png': createImage(IMG_WIDTH, IMG_HEIGHT, 0, 255, 0),
'__screenshots__/tests/a.spec.js/png-1.png': createImage(IMG_WIDTH, IMG_HEIGHT, 0, 255, 0),
'screenshot.css': 'body { background: #00FF00; }',
'tests/a.spec.js': `
const { test, expect } = require('@playwright/test');
@ -1280,6 +1281,9 @@ test('should support stylePath option', async ({ runInlineTest }) => {
await expect(page).toHaveScreenshot('snapshot.png', {
stylePath: './screenshot.css',
});
await expect(page).toHaveScreenshot({
stylePath: './screenshot.css',
});
});
`,
});