fix(esm): allow importing ts from esm (#16735)
This commit is contained in:
parent
e7fa9432fb
commit
d7be1fcca8
|
|
@ -239,8 +239,6 @@ function restartWithExperimentalTsEsm(configFile: string | null): boolean {
|
||||||
return false;
|
return false;
|
||||||
if (process.env.PW_TS_ESM_ON)
|
if (process.env.PW_TS_ESM_ON)
|
||||||
return false;
|
return false;
|
||||||
if (!configFile.endsWith('.ts'))
|
|
||||||
return false;
|
|
||||||
if (!fileIsModule(configFile))
|
if (!fileIsModule(configFile))
|
||||||
return false;
|
return false;
|
||||||
const NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ` --experimental-loader=${url.pathToFileURL(require.resolve('@playwright/test/lib/experimentalLoader')).toString()}`;
|
const NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ` --experimental-loader=${url.pathToFileURL(require.resolve('@playwright/test/lib/experimentalLoader')).toString()}`;
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,7 @@ export function resolveHook(filename: string, specifier: string): string | undef
|
||||||
if (builtins.has(specifier))
|
if (builtins.has(specifier))
|
||||||
return;
|
return;
|
||||||
const isTypeScript = filename.endsWith('.ts') || filename.endsWith('.tsx');
|
const isTypeScript = filename.endsWith('.ts') || filename.endsWith('.tsx');
|
||||||
if (!isTypeScript)
|
const tsconfig = isTypeScript ? loadAndValidateTsconfigForFile(filename) : undefined;
|
||||||
return;
|
|
||||||
const tsconfig = loadAndValidateTsconfigForFile(filename);
|
|
||||||
if (tsconfig && !isRelativeSpecifier(specifier)) {
|
if (tsconfig && !isRelativeSpecifier(specifier)) {
|
||||||
let longestPrefixLength = -1;
|
let longestPrefixLength = -1;
|
||||||
let pathMatchedByLongestPrefix: string | undefined;
|
let pathMatchedByLongestPrefix: string | undefined;
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,9 @@ test('should load esm config files', async ({ runInlineTest }) => {
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should fail to load ts from esm when package.json has type module', async ({ runInlineTest }) => {
|
test('should load ts from esm when package.json has type module', async ({ runInlineTest, nodeVersion }) => {
|
||||||
|
// We only support experimental esm mode on Node 16+
|
||||||
|
test.skip(nodeVersion.major < 16);
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.js': `
|
'playwright.config.js': `
|
||||||
//@no-header
|
//@no-header
|
||||||
|
|
@ -225,19 +227,24 @@ test('should fail to load ts from esm when package.json has type module', async
|
||||||
`,
|
`,
|
||||||
'package.json': JSON.stringify({ type: 'module' }),
|
'package.json': JSON.stringify({ type: 'module' }),
|
||||||
'a.test.js': `
|
'a.test.js': `
|
||||||
import { foo } from './b.ts';
|
//@no-header
|
||||||
const { test } = pwt;
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { bar } from './bar.js';
|
||||||
test('check project name', ({}, testInfo) => {
|
test('check project name', ({}, testInfo) => {
|
||||||
expect(testInfo.project.name).toBe('foo');
|
expect(testInfo.project.name).toBe('foo');
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
'b.ts': `
|
'bar.ts': `
|
||||||
|
import { foo } from './foo.js';
|
||||||
|
export const bar = foo;
|
||||||
|
`,
|
||||||
|
'foo.ts': `
|
||||||
export const foo: string = 'foo';
|
export const foo: string = 'foo';
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.output).toContain('Unknown file extension ".ts"');
|
expect(result.passed).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should filter stack trace for simple expect', async ({ runInlineTest }) => {
|
test('should filter stack trace for simple expect', async ({ runInlineTest }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue