fix(ct): allow importing json files (#30067)

While we are not fully resolving imports during compilation, do not
treat `json` as a non-importable asset.

Fixes #29926.
This commit is contained in:
Dmitry Gozman 2024-03-25 07:41:54 -07:00 committed by GitHub
parent 1539cde034
commit 7a3c002944
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -193,7 +193,4 @@ const artifactExtensions = new Set([
'.ttf',
'.otf',
'.eot',
// Other assets
'.json',
]);
]);

View File

@ -497,6 +497,24 @@ test('should render component via re-export', async ({ runInlineTest }, testInfo
expect(result.passed).toBe(1);
});
test('should import json', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': playwrightCtConfigText,
'playwright/index.html': `<script type="module" src="./index.ts"></script>`,
'playwright/index.ts': ``,
'src/some.json': `{ "some": "value" }`,
'src/button.test.tsx': `
import { test, expect } from '@playwright/experimental-ct-react';
import json from './some.json';
test('pass', async ({}) => {
expect(json.some).toBe('value');
});
`,
}, { workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});
test('should render component exported via fixture', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': playwrightCtConfigText,