Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(screenshot): infer mime type from file extension case-insensitively (#43339)

Yury Semikhatsky02890ef9f1bb
diff --git a/packages/isomorphic/mimeType.ts b/packages/isomorphic/mimeType.ts
index ebe47d82ea..9d22727ae4 100644
--- a/packages/isomorphic/mimeType.ts
+++ b/packages/isomorphic/mimeType.ts
@@ -29,7 +29,7 @@ export function getMimeTypeForPath(path: string): string | null {
const dotIndex = path.lastIndexOf('.');
if (dotIndex === -1)
return null;
- const extension = path.substring(dotIndex + 1);
+ const extension = path.substring(dotIndex + 1).toLowerCase();
return types.get(extension) || null;
}
diff --git a/tests/page/page-screenshot.spec.ts b/tests/page/page-screenshot.spec.ts
index 6daca69121..a386f0692b 100644
--- a/tests/page/page-screenshot.spec.ts
+++ b/tests/page/page-screenshot.spec.ts
@@ -443,13 +443,18 @@ it.describe('page screenshot', () => {
expect(await fs.promises.readFile(outputPath)).toMatchSnapshot('screenshot-sanity.png');
});
- it('path option should detect jpeg', async ({ page, server, isElectron }, testInfo) => {
+ it('path option should detect jpeg', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43323' },
+ }, async ({ page, server, isElectron }, testInfo) => {
await page.setViewportSize({ width: 300, height: 300 });
await page.goto(server.EMPTY_PAGE);
const outputPath = testInfo.outputPath('screenshot.jpg');
const screenshot = await page.screenshot({ omitBackground: true, path: outputPath });
expect(await fs.promises.readFile(outputPath)).toMatchSnapshot('white.jpg');
expect(screenshot).toMatchSnapshot('white.jpg');
+ const upperCasePath = testInfo.outputPath('screenshot.JPG');
+ await page.screenshot({ omitBackground: true, path: upperCasePath });
+ expect(await fs.promises.readFile(upperCasePath)).toMatchSnapshot('white.jpg');
});
it('path option should throw for unsupported mime type', async ({ page }) => {