chore: tolerate css imports (#26626)

Fixes https://github.com/microsoft/playwright/issues/24580
This commit is contained in:
Pavel Feldman 2023-08-23 08:32:23 -07:00 committed by GitHub
parent 91b784e15e
commit f4f9e526a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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<ImportDeclaration>) {
if (path.node.source.value.match(/\.(css|less|scss)$/))
path.remove();
}
}
})
]);
} else {
plugins.push([require('@babel/plugin-syntax-import-assertions')]);
}

View File

@ -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);
});