Skip to content

Commit 3a43813

Browse files
committed
cherry-pick(#29744): fix(ct): stop-gap for shared file import
1 parent d23fb00 commit 3a43813

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

packages/playwright-ct-core/src/tsxTransform.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default declare((api: BabelAPI) => {
7575
const ext = path.extname(importNode.source.value);
7676

7777
// Convert all non-JS imports into refs.
78-
if (!allJsExtensions.has(ext)) {
78+
if (artifactExtensions.has(ext)) {
7979
for (const specifier of importNode.specifiers) {
8080
if (t.isImportNamespaceSpecifier(specifier))
8181
continue;
@@ -171,4 +171,29 @@ export function importInfo(importNode: T.ImportDeclaration, specifier: T.ImportS
171171
return { localName: specifier.local.name, info: result };
172172
}
173173

174-
const allJsExtensions = new Set(['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts', '']);
174+
const artifactExtensions = new Set([
175+
// Frameworks
176+
'.vue',
177+
'.svelte',
178+
179+
// Images
180+
'.jpg', '.jpeg',
181+
'.png',
182+
'.gif',
183+
'.svg',
184+
'.bmp',
185+
'.webp',
186+
'.ico',
187+
188+
// CSS
189+
'.css',
190+
191+
// Fonts
192+
'.woff', '.woff2',
193+
'.ttf',
194+
'.otf',
195+
'.eot',
196+
197+
// Other assets
198+
'.json',
199+
]);

tests/playwright-test/playwright.ct-react.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,37 @@ test('should allow props children', async ({ runInlineTest }) => {
511511
expect(result.exitCode).toBe(0);
512512
expect(result.passed).toBe(1);
513513
});
514+
515+
test('should allow import from shared file', async ({ runInlineTest }) => {
516+
const result = await runInlineTest({
517+
'playwright.config.ts': playwrightCtConfigText,
518+
'playwright/index.html': `<script type="module" src="./index.ts"></script>`,
519+
'playwright/index.ts': ``,
520+
'src/component.tsx': `
521+
export const Component = (props: { content: string }) => {
522+
return <div>{props.content}</div>
523+
};
524+
`,
525+
'src/component.shared.tsx': `
526+
export const componentMock = { content: 'This is a content.' };
527+
`,
528+
'src/component.render.tsx': `
529+
import {Component} from './component';
530+
import {componentMock} from './component.shared';
531+
export const ComponentTest = () => {
532+
return <Component content={componentMock.content} />;
533+
};
534+
`,
535+
'src/component.spec.tsx': `
536+
import { expect, test } from '@playwright/experimental-ct-react';
537+
import { ComponentTest } from './component.render';
538+
import { componentMock } from './component.shared';
539+
test('component renders', async ({ mount }) => {
540+
const component = await mount(<ComponentTest />);
541+
await expect(component).toContainText(componentMock.content)
542+
})`
543+
}, { workers: 1 });
544+
545+
expect(result.exitCode).toBe(0);
546+
expect(result.passed).toBe(1);
547+
});

0 commit comments

Comments
 (0)