|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { test, expect, playwrightCtConfigText } from './playwright-test-fixtures'; |
| 18 | +import fs from 'fs'; |
18 | 19 | import path from 'path'; |
19 | 20 | import url from 'url'; |
20 | 21 |
|
@@ -913,6 +914,44 @@ test('should resolve no-extension import of module into .ts file', async ({ runI |
913 | 914 | expect(result.exitCode).toBe(0); |
914 | 915 | }); |
915 | 916 |
|
| 917 | +test('should resolve extensionless .ts subpath import across a workspace symlink in ESM', { |
| 918 | + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/41371' }, |
| 919 | +}, async ({ runInlineTest }, testInfo) => { |
| 920 | + const baseDir = testInfo.outputPath(); |
| 921 | + const symlinkType = process.platform === 'win32' ? 'junction' : 'dir'; |
| 922 | + const link = async (target: string, linkPath: string) => { |
| 923 | + await fs.promises.mkdir(path.dirname(linkPath), { recursive: true }); |
| 924 | + await fs.promises.symlink(path.join(baseDir, target), linkPath, symlinkType); |
| 925 | + }; |
| 926 | + // It is important to symlink so that our belongsToNodeModules() check does not trigger. |
| 927 | + await link('packages/shared', path.join(baseDir, 'packages/core/node_modules/@repro/shared')); |
| 928 | + await link('packages/core', path.join(baseDir, 'apps/e2e/node_modules/@repro/core')); |
| 929 | + |
| 930 | + const result = await runInlineTest({ |
| 931 | + // Root package.json is required for workspace:* dependencies to work. |
| 932 | + 'package.json': JSON.stringify({ name: 'repro-root', private: true }), |
| 933 | + 'packages/shared/package.json': JSON.stringify({ name: '@repro/shared', private: true, type: 'module' }), |
| 934 | + 'packages/shared/lib/text.utils.ts': ` |
| 935 | + export function greet(name: string) { |
| 936 | + return 'Hello, ' + name; |
| 937 | + } |
| 938 | + `, |
| 939 | + 'packages/core/package.json': JSON.stringify({ name: '@repro/core', private: true, type: 'module', dependencies: { '@repro/shared': 'workspace:*' } }), |
| 940 | + 'packages/core/lib/conversations.ts': ` |
| 941 | + export { greet } from '@repro/shared/lib/text.utils'; |
| 942 | + `, |
| 943 | + 'apps/e2e/tests/basic.spec.ts': ` |
| 944 | + import { test, expect } from '@playwright/test'; |
| 945 | + import { greet } from '@repro/core/lib/conversations'; |
| 946 | + test('greet returns expected string', () => { |
| 947 | + expect(greet('world')).toBe('Hello, world'); |
| 948 | + }); |
| 949 | + `, |
| 950 | + }); |
| 951 | + expect(result.passed).toBe(1); |
| 952 | + expect(result.exitCode).toBe(0); |
| 953 | +}); |
| 954 | + |
916 | 955 | test('should support node imports', async ({ runInlineTest }) => { |
917 | 956 | const result = await runInlineTest({ |
918 | 957 | 'playwright.config.ts': 'export default {}', |
|
0 commit comments