From 9a3a03a960076966271469ee45e33453754e2d88 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 22 Mar 2024 13:32:36 -0700 Subject: [PATCH] fix(ct): allow importing json files --- .../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,