Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(ct): Don't bloat metainfo.json file when # or ? is present in id (#39074)
Michael Balitskya7bcfe37bc8d
diff --git a/packages/playwright-ct-core/src/vitePlugin.ts b/packages/playwright-ct-core/src/vitePlugin.tsindex 95992f4abf..ad9cd4adc9 100644--- a/packages/playwright-ct-core/src/vitePlugin.ts+++ b/packages/playwright-ct-core/src/vitePlugin.ts@@ -289,9 +289,11 @@ function vitePlugin(registerSource: string, templateDir: string, buildInfo: Buil}function collectViteModuleDependencies(context: PluginContext, id: string, deps: Set<string>) {- if (!path.isAbsolute(id))+ // Example: "src/Component.tsx?raw" or "src/Component.tsx?import" should resolve to the file path.+ const cleanedId = id.split(/[?#]/)[0];+ const normalizedId = path.normalize(cleanedId);+ if (!path.isAbsolute(normalizedId))return;- const normalizedId = path.normalize(id);if (deps.has(normalizedId))return;deps.add(normalizedId);diff --git a/tests/playwright-test/playwright.ct-build.spec.ts b/tests/playwright-test/playwright.ct-build.spec.tsindex ecf9d6d1fa..7dcd64aa57 100644--- a/tests/playwright-test/playwright.ct-build.spec.ts+++ b/tests/playwright-test/playwright.ct-build.spec.ts@@ -736,3 +736,62 @@ test('should resolve components imported from node_modules', async ({ runInlineTexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);});++test('should remove ? or # from deps in metainfo.json', async ({ runInlineTest }, testInfo) => {+ const result = await runInlineTest({+ 'playwright.config.ts': playwrightCtConfigText,+ 'playwright/index.html': `<script type="module" src="./index.js"></script>`,+ 'playwright/index.js': ``,+ 'button.tsx': `+ export const Button = () => <button>Button</button>;+ `,+ 'button2.tsx': `+ export const Button2 = () => <button>Button2</button>;+ `,+ 'button3.tsx': `+ export const Button3 = () => <button>Button3</button>;+ `,+ 'button.story.tsx': `+ import { Button as Button1 } from './button';+ import { Button } from './button';+ import { Button as ButtonA } from './button?a';+ import { Button as ButtonB } from './button#b';+ import { Button2 } from './button2?c';+ import { Button3 } from './button3#d';++ export const ButtonStory = () => (+ <div>+ <Button />+ <Button2 />+ <ButtonA />+ <Button3 />+ <ButtonB />+ </div>+ )+ `,+ 'a.test.tsx': `+ import { test, expect } from '@playwright/experimental-ct-react';+ import { ButtonStory } from './button.story.tsx';++ test('Button', async ({ mount }) => {+ const component = await mount(<ButtonStory />);+ await expect(component).toHaveText('ButtonButton2ButtonButton3Button');+ });+ `,+ }, { workers: 1 });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+ const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8'));++ for (const [, value] of Object.entries(metainfo.deps))+ (value as string[]).sort();++ expect(Object.entries(metainfo.deps)).toEqual([+ [expect.stringContaining('button.story.tsx'), [+ expect.stringContaining('button.story.tsx'),+ expect.stringContaining('button.tsx'),+ expect.stringContaining('button2.tsx'),+ expect.stringContaining('button3.tsx'),+ ]],+ ]);+});diff --git a/tests/playwright-test/ui-mode-test-ct.spec.ts b/tests/playwright-test/ui-mode-test-ct.spec.tsindex c4cc2492a9..48683580a7 100644--- a/tests/playwright-test/ui-mode-test-ct.spec.ts+++ b/tests/playwright-test/ui-mode-test-ct.spec.ts@@ -289,3 +289,99 @@ test('should watch component when editing util', async ({ runUITest, writeFiles❌ pass <=`);});++test('should watch component when editing inline css', async ({ runUITest, writeFiles }) => {+ const { page } = await runUITest({+ ...basicTestTree,+ 'src/button.tsx': undefined,+ 'src/button.ts': `+ import { Button } from './buttonComponent';+ export { Button };+ `,+ 'src/buttonComponent.tsx': `+ import cssText from './style.css?inline';+ export const Button = () => <button>{cssText.trim()}</button>;+ `,+ 'src/style.css': `+ .button{color:red}+ `,+ 'src/button.test.tsx': `+ import { test, expect } from '@playwright/experimental-ct-react';+ import { Button } from './button';++ test('pass', async ({ mount }) => {+ const component = await mount(<Button></Button>);+ await expect(component).toHaveText('.button{color:red}', { timeout: 1 });+ });+ `,+ });+ await expect.poll(dumpTestTree(page)).toBe(`+ ▼ ◯ button.test.tsx+ ◯ pass+ `);++ await page.getByTitle('Watch all').click();+ await page.getByTitle('Run all').click();++ await expect.poll(dumpTestTree(page)).toBe(`+ ▼ ✅ button.test.tsx+ ✅ pass+ `);++ await writeFiles({+ 'src/style.css': `+ .button{color:blue}+ `,+ });++ await expect.poll(dumpTestTree(page)).toBe(`+ ▼ ❌ button.test.tsx+ ❌ pass <=+ `);+});++test('should watch component when editing story import chain', async ({ runUITest, writeFiles }) => {+ const { page } = await runUITest({+ ...basicTestTree,+ 'src/button.tsx': undefined,+ 'src/button.test.tsx': `+ import { test, expect } from '@playwright/experimental-ct-react';+ import { StoryButton } from './button.story';++ test('pass', async ({ mount }) => {+ const component = await mount(<StoryButton></StoryButton>);+ await expect(component).toHaveText('Button', { timeout: 1 });+ });+ `,+ 'src/button.story.tsx': `+ import { Button } from './buttonComponent';+ export const StoryButton = () => <Button></Button>;+ `,+ 'src/buttonComponent.tsx': `+ export const Button = () => <button>Button</button>;+ `,+ });+ await expect.poll(dumpTestTree(page)).toBe(`+ ▼ ◯ button.test.tsx+ ◯ pass+ `);++ await page.getByTitle('Watch all').click();+ await page.getByTitle('Run all').click();++ await expect.poll(dumpTestTree(page)).toBe(`+ ▼ ✅ button.test.tsx+ ✅ pass+ `);++ await writeFiles({+ 'src/buttonComponent.tsx': `+ export const Button = () => <button>Button2</button>;+ `,+ });++ await expect.poll(dumpTestTree(page)).toBe(`+ ▼ ❌ button.test.tsx+ ❌ pass <=+ `);+});