mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	chore: tolerate css imports (#26626)
Fixes https://github.com/microsoft/playwright/issues/24580
This commit is contained in:
		
							parent
							
								
									91b784e15e
								
							
						
					
					
						commit
						f4f9e526a2
					
				| @ -15,7 +15,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import type { BabelFileResult, NodePath, PluginObj, TransformOptions } from '@babel/core'; | 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 type { TemplateBuilder } from '@babel/template'; | ||||||
| import * as babel from '@babel/core'; | 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')]); |     plugins.push([require('@babel/plugin-transform-modules-commonjs')]); | ||||||
|     // This converts async imports to require() calls so that we can intercept them with pirates.
 |     // 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([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 { |   } else { | ||||||
|     plugins.push([require('@babel/plugin-syntax-import-assertions')]); |     plugins.push([require('@babel/plugin-syntax-import-assertions')]); | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -1007,3 +1007,18 @@ test('should allow test.extend.ts and test.ts files', async ({ runInlineTest }) | |||||||
|   expect(result.exitCode).toBe(0); |   expect(result.exitCode).toBe(0); | ||||||
|   expect(result.passed).toBe(1); |   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); | ||||||
|  | }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pavel Feldman
						Pavel Feldman