cherry-pick(#15422): fix(ct): tolerate compiled react components
This commit is contained in:
parent
19790a0e70
commit
741e338fb1
|
|
@ -27,7 +27,7 @@ import { assert, calculateSha1 } from 'playwright-core/lib/utils';
|
||||||
import type { AddressInfo } from 'net';
|
import type { AddressInfo } from 'net';
|
||||||
|
|
||||||
let previewServer: PreviewServer;
|
let previewServer: PreviewServer;
|
||||||
const VERSION = 4;
|
const VERSION = 5;
|
||||||
|
|
||||||
type CtConfig = {
|
type CtConfig = {
|
||||||
ctPort?: number;
|
ctPort?: number;
|
||||||
|
|
@ -37,6 +37,7 @@ type CtConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
|
const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
|
||||||
|
const compiledReactRE = /(const|var)\s+React\s*=/;
|
||||||
|
|
||||||
export function createPlugin(
|
export function createPlugin(
|
||||||
registerSourceFile: string,
|
registerSourceFile: string,
|
||||||
|
|
@ -275,7 +276,7 @@ function vitePlugin(registerSource: string, relativeTemplateDir: string, buildIn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vite React plugin will do this for .jsx files, but not .js files.
|
// Vite React plugin will do this for .jsx files, but not .js files.
|
||||||
if (id.endsWith('.js') && content.includes('React.createElement') && !content.match(importReactRE)) {
|
if (id.endsWith('.js') && content.includes('React.createElement') && !content.match(importReactRE) && !content.match(compiledReactRE)) {
|
||||||
const code = `import React from 'react';\n${content}`;
|
const code = `import React from 'react';\n${content}`;
|
||||||
return { code, map: { mappings: '' } };
|
return { code, map: { mappings: '' } };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import { tsConfigLoader } from './third_party/tsconfig-loader';
|
||||||
import Module from 'module';
|
import Module from 'module';
|
||||||
import type { BabelTransformFunction } from './babelBundle';
|
import type { BabelTransformFunction } from './babelBundle';
|
||||||
|
|
||||||
const version = 12;
|
const version = 13;
|
||||||
const cacheDir = process.env.PWTEST_CACHE_DIR || path.join(os.tmpdir(), 'playwright-transform-cache');
|
const cacheDir = process.env.PWTEST_CACHE_DIR || path.join(os.tmpdir(), 'playwright-transform-cache');
|
||||||
const sourceMaps: Map<string, string> = new Map();
|
const sourceMaps: Map<string, string> = new Map();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue