mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-06 03:16:17 +03:00
fix(ct): allow importing components from node_modules (#30493)
Fixes https://github.com/microsoft/playwright/issues/29854
This commit is contained in:
parent
7a9fd27146
commit
e91d372544
@ -183,7 +183,7 @@ export function transformIndexFile(id: string, content: string, templateDir: str
|
||||
lines.push(registerSource);
|
||||
|
||||
for (const value of importInfos.values()) {
|
||||
const importPath = resolveHook(value.filename, value.importSource);
|
||||
const importPath = resolveHook(value.filename, value.importSource) || value.importSource;
|
||||
lines.push(`const ${value.id} = () => import('${importPath?.replaceAll(path.sep, '/')}').then((mod) => mod.${value.remoteName || 'default'});`);
|
||||
}
|
||||
|
||||
|
@ -665,3 +665,33 @@ test('should pass undefined value as param', async ({ runInlineTest }) => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
});
|
||||
|
||||
test('should resolve components imported from node_modules', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'package.json': `{ "name": "test-project" }`,
|
||||
'playwright.config.ts': playwrightCtConfigText,
|
||||
'playwright/index.html': `<script type="module" src="./index.js"></script>`,
|
||||
'playwright/index.js': ``,
|
||||
|
||||
'node_modules/@mui/material/index.js': `
|
||||
const TextField = () => 'input';
|
||||
module.exports = { TextField };
|
||||
`,
|
||||
'node_modules/@mui/material/package.json': JSON.stringify({
|
||||
name: '@mui/material',
|
||||
main: './index.js',
|
||||
}),
|
||||
|
||||
'src/component.spec.tsx': `
|
||||
import { test } from '@playwright/experimental-ct-react';
|
||||
import { TextField } from '@mui/material';
|
||||
|
||||
test("passes", async ({ mount }) => {
|
||||
await mount(<TextField />);
|
||||
});
|
||||
`,
|
||||
}, { workers: 1 });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user