From 7a3c00294457f17f568d992b8993f1332fb3a792 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 25 Mar 2024 07:41:54 -0700 Subject: [PATCH] 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. --- .../playwright-ct-core/src/tsxTransform.ts | 5 +---- .../playwright.ct-build.spec.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/playwright-ct-core/src/tsxTransform.ts b/packages/playwright-ct-core/src/tsxTransform.ts index ab33c114ba..a01bfdfa63 100644 --- a/packages/playwright-ct-core/src/tsxTransform.ts +++ b/packages/playwright-ct-core/src/tsxTransform.ts @@ -193,7 +193,4 @@ const artifactExtensions = new Set([ '.ttf', '.otf', '.eot', - - // Other assets - '.json', -]); \ No newline at end of file +]); diff --git a/tests/playwright-test/playwright.ct-build.spec.ts b/tests/playwright-test/playwright.ct-build.spec.ts index 38bae33604..aa053a6d8b 100644 --- a/tests/playwright-test/playwright.ct-build.spec.ts +++ b/tests/playwright-test/playwright.ct-build.spec.ts @@ -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': ``, + '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,