fix(test runner): remove unused type imports during transform (#18157)

Fixes #18117.
This commit is contained in:
Dmitry Gozman 2022-10-19 13:06:11 -07:00 committed by GitHub
parent 909eda2432
commit 9fe72a1da8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -65,7 +65,7 @@ export function babelTransform(filename: string, isTypeScript: boolean, isModule
setPublicClassFields: true,
},
presets: [
[require('@babel/preset-typescript'), { onlyRemoveTypeImports: true }],
[require('@babel/preset-typescript'), { onlyRemoveTypeImports: false }],
],
plugins,
sourceMaps: 'both',

View file

@ -185,6 +185,7 @@ test('beforeAll from a helper file should throw', async ({ runInlineTest }) => {
`,
'playwright.config.ts': `
import { test } from './my-test';
test.extend({});
`,
'a.test.ts': `
import { test } from './my-test';

View file

@ -471,3 +471,20 @@ test('should load a jsx/tsx files', async ({ runInlineTest }) => {
expect(passed).toBe(2);
expect(exitCode).toBe(0);
});
test('should remove type imports from ts', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
import { Point } from 'helper';
const p: Point = {};
const { test } = pwt;
test('pass', ({}) => {});
`,
'node_modules/helper/index.d.ts': `
export type Point = {};
`,
});
expect(result.passed).toBe(1);
expect(result.exitCode).toBe(0);
});