diff --git a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts index c71f24eec3..30cf969765 100644 --- a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts +++ b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts @@ -15,7 +15,7 @@ */ import type { BabelFileResult, NodePath, PluginObj, TransformOptions } from '@babel/core'; -import type { TSExportAssignment } from '@babel/types'; +import type { TSExportAssignment, ImportDeclaration } from '@babel/types'; import type { TemplateBuilder } from '@babel/template'; import * as babel from '@babel/core'; @@ -72,6 +72,17 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins plugins.push([require('@babel/plugin-transform-modules-commonjs')]); // This converts async imports to require() calls so that we can intercept them with pirates. plugins.push([require('@babel/plugin-proposal-dynamic-import')]); + plugins.push([ + (): PluginObj => ({ + name: 'css-to-identity-obj-proxy', + visitor: { + ImportDeclaration(path: NodePath) { + if (path.node.source.value.match(/\.(css|less|scss)$/)) + path.remove(); + } + } + }) + ]); } else { plugins.push([require('@babel/plugin-syntax-import-assertions')]); } diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts index ffd467c6ce..8a782ae0fe 100644 --- a/tests/playwright-test/loader.spec.ts +++ b/tests/playwright-test/loader.spec.ts @@ -1007,3 +1007,18 @@ test('should allow test.extend.ts and test.ts files', async ({ runInlineTest }) expect(result.exitCode).toBe(0); expect(result.passed).toBe(1); }); + +test('should remove import css', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.test.ts': ` + import './index.css'; + import foo from './index.css'; + import { bar } from './index.css'; + + import { test, expect } from '@playwright/test'; + test('pass', async () => {}); + `, + }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); +});