Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozman9fe72a1da85b
diff --git a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts
index 14389f8df4..8b13eb680d 100644
--- a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts
+++ b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts
@@ -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',
diff --git a/tests/playwright-test/hooks.spec.ts b/tests/playwright-test/hooks.spec.ts
index 035b5c4eb3..7ed25b4470 100644
--- a/tests/playwright-test/hooks.spec.ts
+++ b/tests/playwright-test/hooks.spec.ts
@@ -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';
diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts
index 734400a10f..351550d40a 100644
--- a/tests/playwright-test/loader.spec.ts
+++ b/tests/playwright-test/loader.spec.ts
@@ -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);
+});