mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test runner): do not resolve relative imports through baseUrl (#16395)
This commit is contained in:
parent
0c7f086096
commit
f58c376443
@ -100,7 +100,7 @@ export function resolveHook(filename: string, specifier: string): string | undef
|
|||||||
if (!isTypeScript)
|
if (!isTypeScript)
|
||||||
return;
|
return;
|
||||||
const tsconfig = loadAndValidateTsconfigForFile(filename);
|
const tsconfig = loadAndValidateTsconfigForFile(filename);
|
||||||
if (tsconfig) {
|
if (tsconfig && !isRelativeSpecifier(specifier)) {
|
||||||
let longestPrefixLength = -1;
|
let longestPrefixLength = -1;
|
||||||
let pathMatchedByLongestPrefix: string | undefined;
|
let pathMatchedByLongestPrefix: string | undefined;
|
||||||
|
|
||||||
@ -258,3 +258,7 @@ export function belongsToNodeModules(file: string) {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isRelativeSpecifier(specifier: string) {
|
||||||
|
return specifier === '.' || specifier === '..' || specifier.startsWith('./') || specifier.startsWith('../');
|
||||||
|
}
|
||||||
|
@ -298,8 +298,8 @@ test('should not use baseurl for relative imports', async ({ runInlineTest }) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should not use baseurl for relative imports when dir with same name exists', async ({ runInlineTest }) => {
|
test('should not use baseurl for relative imports when dir with same name exists', async ({ runInlineTest }) => {
|
||||||
test.fail();
|
|
||||||
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15891' });
|
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/15891' });
|
||||||
|
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'frontend/tsconfig.json': `{
|
'frontend/tsconfig.json': `{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
@ -309,15 +309,31 @@ test('should not use baseurl for relative imports when dir with same name exists
|
|||||||
'frontend/src/utils/foo.js': `
|
'frontend/src/utils/foo.js': `
|
||||||
export const foo = -1;
|
export const foo = -1;
|
||||||
`,
|
`,
|
||||||
|
'frontend/src/index.js': `
|
||||||
|
export const index = -1;
|
||||||
|
`,
|
||||||
|
'frontend/src/.bar.js': `
|
||||||
|
export const bar = 42;
|
||||||
|
`,
|
||||||
'frontend/playwright/tests/utils.ts': `
|
'frontend/playwright/tests/utils.ts': `
|
||||||
export const foo = 42;
|
export const foo = 42;
|
||||||
`,
|
`,
|
||||||
|
'frontend/playwright/tests/index.js': `
|
||||||
|
export const index = 42;
|
||||||
|
`,
|
||||||
'frontend/playwright/tests/forms_cms_standard.spec.ts': `
|
'frontend/playwright/tests/forms_cms_standard.spec.ts': `
|
||||||
// This relative import should not use baseUrl
|
// These relative imports should not use baseUrl
|
||||||
import { foo } from './utils';
|
import { foo } from './utils';
|
||||||
|
import { index } from '.';
|
||||||
|
|
||||||
|
// This absolute import should use baseUrl
|
||||||
|
import { bar } from '.bar';
|
||||||
|
|
||||||
const { test } = pwt;
|
const { test } = pwt;
|
||||||
test('test', ({}, testInfo) => {
|
test('test', ({}, testInfo) => {
|
||||||
expect(foo).toBe(42);
|
expect(foo).toBe(42);
|
||||||
|
expect(index).toBe(42);
|
||||||
|
expect(bar).toBe(42);
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
@ -325,4 +341,5 @@ test('should not use baseurl for relative imports when dir with same name exists
|
|||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
expect(result.output).not.toContain(`Could not`);
|
expect(result.output).not.toContain(`Could not`);
|
||||||
|
expect(result.output).not.toContain(`Cannot`);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user