Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(ct): support cra w/ .js (#14326)
Pavel Feldman9440f52b888f
diff --git a/packages/playwright-test/ThirdPartyNotices.txt b/packages/playwright-test/ThirdPartyNotices.txtindex f12634efc3..4860f17c3d 100644--- a/packages/playwright-test/ThirdPartyNotices.txt+++ b/packages/playwright-test/ThirdPartyNotices.txt@@ -42,99 +42,100 @@ This project incorporates components from the projects listed below. The origina36. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-dynamic-import)37. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-export-namespace-from)38. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-json-strings)-39. @babel/[email protected] (https://github.com/babel/babel)-40. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-nullish-coalescing-operator)-41. @babel/[email protected] (https://github.com/babel/babel)-42. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-object-rest-spread)-43. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-optional-catch-binding)-44. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-optional-chaining)-45. @babel/[email protected] (https://github.com/babel/babel)-46. @babel/[email protected] (https://github.com/babel/babel)-47. @babel/[email protected] (https://github.com/babel/babel)-48. @babel/[email protected] (https://github.com/babel/babel)-49. @babel/[email protected] (https://github.com/babel/babel)-50. @babel/[email protected] (https://github.com/babel/babel)-51. @babel/[email protected] (https://github.com/babel/babel)-52. @babel/[email protected] (https://github.com/babel/babel)-53. @jridgewell/[email protected] (https://github.com/jridgewell/resolve-uri)-54. @jridgewell/[email protected] (https://github.com/jridgewell/sourcemap-codec)-55. @jridgewell/[email protected] (https://github.com/jridgewell/trace-mapping)-56. [email protected] (https://github.com/chalk/ansi-styles)-57. [email protected] (https://github.com/airbnb/babel-plugin-dynamic-import-node)-58. [email protected] (https://github.com/browserslist/browserslist)-59. [email protected] (https://github.com/ljharb/call-bind)-60. [email protected] (https://github.com/browserslist/caniuse-lite)-61. [email protected] (https://github.com/chalk/chalk)-62. [email protected] (https://github.com/Qix-/color-convert)-63. [email protected] (https://github.com/dfcreative/color-name)-64. [email protected] (https://github.com/thlorenz/convert-source-map)-65. [email protected] (https://github.com/debug-js/debug)-66. [email protected] (https://github.com/ljharb/define-properties)-67. [email protected] (https://github.com/kilian/electron-to-chromium)-68. [email protected] (https://github.com/lukeed/escalade)-69. [email protected] (https://github.com/sindresorhus/escape-string-regexp)-70. [email protected] (https://github.com/Raynos/function-bind)-71. [email protected] (https://github.com/loganfsmyth/gensync)-72. [email protected] (https://github.com/ljharb/get-intrinsic)-73. [email protected] (https://github.com/sindresorhus/globals)-74. [email protected] (https://github.com/sindresorhus/has-flag)-75. [email protected] (https://github.com/inspect-js/has-property-descriptors)-76. [email protected] (https://github.com/inspect-js/has-symbols)-77. [email protected] (https://github.com/tarruda/has)-78. [email protected] (https://github.com/lydell/js-tokens)-79. [email protected] (https://github.com/mathiasbynens/jsesc)-80. [email protected] (https://github.com/json5/json5)-81. [email protected] (https://github.com/zeit/ms)-82. [email protected] (https://github.com/chicoxyzzy/node-releases)-83. [email protected] (https://github.com/ljharb/object-keys)-84. [email protected] (https://github.com/ljharb/object.assign)-85. [email protected] (https://github.com/alexeyraspopov/picocolors)-86. [email protected] (https://github.com/feross/safe-buffer)-87. [email protected] (https://github.com/npm/node-semver)-88. [email protected] (https://github.com/mozilla/source-map)-89. [email protected] (https://github.com/chalk/supports-color)-90. [email protected] (https://github.com/sindresorhus/to-fast-properties)-91. @jest/[email protected] (https://github.com/facebook/jest)-92. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-93. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-94. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-95. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-96. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-97. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-98. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)-99. [email protected] (https://github.com/chalk/ansi-regex)-100. [email protected] (https://github.com/chalk/ansi-styles)-101. [email protected] (https://github.com/chalk/ansi-styles)-102. [email protected] (https://github.com/micromatch/braces)-103. [email protected] (https://github.com/chalk/chalk)-104. [email protected] (https://github.com/Qix-/color-convert)-105. [email protected] (https://github.com/colorjs/color-name)-106. [email protected] (https://github.com/facebook/jest)-107. [email protected] (https://github.com/sindresorhus/escape-string-regexp)-108. [email protected] (https://github.com/facebook/jest)-109. [email protected] (https://github.com/jonschlinkert/fill-range)-110. [email protected] (https://github.com/isaacs/node-graceful-fs)-111. [email protected] (https://github.com/sindresorhus/has-flag)-112. [email protected] (https://github.com/jonschlinkert/is-number)-113. [email protected] (https://github.com/facebook/jest)-114. [email protected] (https://github.com/facebook/jest)-115. [email protected] (https://github.com/facebook/jest)-116. [email protected] (https://github.com/facebook/jest)-117. [email protected] (https://github.com/facebook/jest)-118. [email protected] (https://github.com/micromatch/micromatch)-119. [email protected] (https://github.com/micromatch/picomatch)-120. [email protected] (https://github.com/facebook/jest)-121. [email protected] (https://github.com/facebook/react)-122. [email protected] (https://github.com/sindresorhus/slash)-123. [email protected] (https://github.com/tapjs/stack-utils)-124. [email protected] (https://github.com/chalk/supports-color)-125. [email protected] (https://github.com/micromatch/to-regex-range)-126. [email protected] (https://github.com/sindresorhus/define-lazy-prop)-127. [email protected] (https://github.com/sindresorhus/is-docker)-128. [email protected] (https://github.com/sindresorhus/is-wsl)-129. [email protected] (https://github.com/sindresorhus/open)-130. [email protected] (https://github.com/danez/pirates)-131. [email protected] (https://github.com/evanw/node-source-map-support)+39. @babel/[email protected] (https://github.com/babel/babel)+40. @babel/[email protected] (https://github.com/babel/babel)+41. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-nullish-coalescing-operator)+42. @babel/[email protected] (https://github.com/babel/babel)+43. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-object-rest-spread)+44. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-optional-catch-binding)+45. @babel/[email protected] (https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-optional-chaining)+46. @babel/[email protected] (https://github.com/babel/babel)+47. @babel/[email protected] (https://github.com/babel/babel)+48. @babel/[email protected] (https://github.com/babel/babel)+49. @babel/[email protected] (https://github.com/babel/babel)+50. @babel/[email protected] (https://github.com/babel/babel)+51. @babel/[email protected] (https://github.com/babel/babel)+52. @babel/[email protected] (https://github.com/babel/babel)+53. @babel/[email protected] (https://github.com/babel/babel)+54. @jridgewell/[email protected] (https://github.com/jridgewell/resolve-uri)+55. @jridgewell/[email protected] (https://github.com/jridgewell/sourcemap-codec)+56. @jridgewell/[email protected] (https://github.com/jridgewell/trace-mapping)+57. [email protected] (https://github.com/chalk/ansi-styles)+58. [email protected] (https://github.com/airbnb/babel-plugin-dynamic-import-node)+59. [email protected] (https://github.com/browserslist/browserslist)+60. [email protected] (https://github.com/ljharb/call-bind)+61. [email protected] (https://github.com/browserslist/caniuse-lite)+62. [email protected] (https://github.com/chalk/chalk)+63. [email protected] (https://github.com/Qix-/color-convert)+64. [email protected] (https://github.com/dfcreative/color-name)+65. [email protected] (https://github.com/thlorenz/convert-source-map)+66. [email protected] (https://github.com/debug-js/debug)+67. [email protected] (https://github.com/ljharb/define-properties)+68. [email protected] (https://github.com/kilian/electron-to-chromium)+69. [email protected] (https://github.com/lukeed/escalade)+70. [email protected] (https://github.com/sindresorhus/escape-string-regexp)+71. [email protected] (https://github.com/Raynos/function-bind)+72. [email protected] (https://github.com/loganfsmyth/gensync)+73. [email protected] (https://github.com/ljharb/get-intrinsic)+74. [email protected] (https://github.com/sindresorhus/globals)+75. [email protected] (https://github.com/sindresorhus/has-flag)+76. [email protected] (https://github.com/inspect-js/has-property-descriptors)+77. [email protected] (https://github.com/inspect-js/has-symbols)+78. [email protected] (https://github.com/tarruda/has)+79. [email protected] (https://github.com/lydell/js-tokens)+80. [email protected] (https://github.com/mathiasbynens/jsesc)+81. [email protected] (https://github.com/json5/json5)+82. [email protected] (https://github.com/zeit/ms)+83. [email protected] (https://github.com/chicoxyzzy/node-releases)+84. [email protected] (https://github.com/ljharb/object-keys)+85. [email protected] (https://github.com/ljharb/object.assign)+86. [email protected] (https://github.com/alexeyraspopov/picocolors)+87. [email protected] (https://github.com/feross/safe-buffer)+88. [email protected] (https://github.com/npm/node-semver)+89. [email protected] (https://github.com/mozilla/source-map)+90. [email protected] (https://github.com/chalk/supports-color)+91. [email protected] (https://github.com/sindresorhus/to-fast-properties)+92. @jest/[email protected] (https://github.com/facebook/jest)+93. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+94. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+95. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+96. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+97. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+98. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+99. @types/[email protected] (https://github.com/DefinitelyTyped/DefinitelyTyped)+100. [email protected] (https://github.com/chalk/ansi-regex)+101. [email protected] (https://github.com/chalk/ansi-styles)+102. [email protected] (https://github.com/chalk/ansi-styles)+103. [email protected] (https://github.com/micromatch/braces)+104. [email protected] (https://github.com/chalk/chalk)+105. [email protected] (https://github.com/Qix-/color-convert)+106. [email protected] (https://github.com/colorjs/color-name)+107. [email protected] (https://github.com/facebook/jest)+108. [email protected] (https://github.com/sindresorhus/escape-string-regexp)+109. [email protected] (https://github.com/facebook/jest)+110. [email protected] (https://github.com/jonschlinkert/fill-range)+111. [email protected] (https://github.com/isaacs/node-graceful-fs)+112. [email protected] (https://github.com/sindresorhus/has-flag)+113. [email protected] (https://github.com/jonschlinkert/is-number)+114. [email protected] (https://github.com/facebook/jest)+115. [email protected] (https://github.com/facebook/jest)+116. [email protected] (https://github.com/facebook/jest)+117. [email protected] (https://github.com/facebook/jest)+118. [email protected] (https://github.com/facebook/jest)+119. [email protected] (https://github.com/micromatch/micromatch)+120. [email protected] (https://github.com/micromatch/picomatch)+121. [email protected] (https://github.com/facebook/jest)+122. [email protected] (https://github.com/facebook/react)+123. [email protected] (https://github.com/sindresorhus/slash)+124. [email protected] (https://github.com/tapjs/stack-utils)+125. [email protected] (https://github.com/chalk/supports-color)+126. [email protected] (https://github.com/micromatch/to-regex-range)+127. [email protected] (https://github.com/sindresorhus/define-lazy-prop)+128. [email protected] (https://github.com/sindresorhus/is-docker)+129. [email protected] (https://github.com/sindresorhus/is-wsl)+130. [email protected] (https://github.com/sindresorhus/open)+131. [email protected] (https://github.com/danez/pirates)+132. [email protected] (https://github.com/evanw/node-source-map-support)%% @ampproject/[email protected] NOTICES AND INFORMATION BEGIN HERE=========================================@@ -1338,6 +1339,33 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.=========================================END OF @babel/[email protected] AND INFORMATION+%% @babel/[email protected] NOTICES AND INFORMATION BEGIN HERE+=========================================+MIT License++Copyright (c) 2014-present Sebastian McKenzie and other contributors++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+=========================================+END OF @babel/[email protected] AND INFORMATION+%% @babel/[email protected] NOTICES AND INFORMATION BEGIN HERE=========================================MIT Licensediff --git a/packages/playwright-test/bundles/babel/package-lock.json b/packages/playwright-test/bundles/babel/package-lock.jsonindex 1e9d080d16..3cbe8e1144 100644--- a/packages/playwright-test/bundles/babel/package-lock.json+++ b/packages/playwright-test/bundles/babel/package-lock.json@@ -23,6 +23,7 @@"@babel/plugin-proposal-private-property-in-object": "^7.16.7","@babel/plugin-syntax-async-generators": "^7.8.4","@babel/plugin-syntax-json-strings": "^7.8.3",+ "@babel/plugin-syntax-jsx": "^7.16.7","@babel/plugin-syntax-object-rest-spread": "^7.8.3","@babel/plugin-syntax-optional-catch-binding": "^7.8.3","@babel/plugin-transform-modules-commonjs": "^7.16.8",@@ -531,6 +532,20 @@"@babel/core": "^7.0.0-0"}},+ "node_modules/@babel/plugin-syntax-jsx": {+ "version": "7.16.7",+ "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.16.7.tgz",+ "integrity": "sha512-Esxmk7YjA8QysKeT3VhTXvF6y77f/a91SIs4pWb4H2eWGQkCKFgQaG6hdoEVZtGsrAcb2K5BW66XsOErD4WU3Q==",+ "dependencies": {+ "@babel/helper-plugin-utils": "^7.16.7"+ },+ "engines": {+ "node": ">=6.9.0"+ },+ "peerDependencies": {+ "@babel/core": "^7.0.0-0"+ }+ },"node_modules/@babel/plugin-syntax-logical-assignment-operators": {"version": "7.10.4","resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz",@@ -1484,6 +1499,14 @@"@babel/helper-plugin-utils": "^7.8.0"}},+ "@babel/plugin-syntax-jsx": {+ "version": "7.16.7",+ "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.16.7.tgz",+ "integrity": "sha512-Esxmk7YjA8QysKeT3VhTXvF6y77f/a91SIs4pWb4H2eWGQkCKFgQaG6hdoEVZtGsrAcb2K5BW66XsOErD4WU3Q==",+ "requires": {+ "@babel/helper-plugin-utils": "^7.16.7"+ }+ },"@babel/plugin-syntax-logical-assignment-operators": {"version": "7.10.4","resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz",diff --git a/packages/playwright-test/bundles/babel/package.json b/packages/playwright-test/bundles/babel/package.jsonindex 840ee2aef2..d9a56cdade 100644--- a/packages/playwright-test/bundles/babel/package.json+++ b/packages/playwright-test/bundles/babel/package.json@@ -24,6 +24,7 @@"@babel/plugin-proposal-private-property-in-object": "^7.16.7","@babel/plugin-syntax-async-generators": "^7.8.4","@babel/plugin-syntax-json-strings": "^7.8.3",+ "@babel/plugin-syntax-jsx": "^7.16.7","@babel/plugin-syntax-object-rest-spread": "^7.8.3","@babel/plugin-syntax-optional-catch-binding": "^7.8.3","@babel/plugin-transform-modules-commonjs": "^7.16.8",diff --git a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts b/packages/playwright-test/bundles/babel/src/babelBundleImpl.tsindex b53a8dfb61..13c0059afb 100644--- a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts+++ b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts@@ -41,11 +41,13 @@ export function babelTransform(filename: string, isTypeScript: boolean, isModule[require('@babel/plugin-syntax-object-rest-spread')],[require('@babel/plugin-proposal-export-namespace-from')]);+ } else {+ plugins.push([require('@babel/plugin-syntax-jsx')]);+ }- if (!isModule) {- plugins.push([require('@babel/plugin-transform-modules-commonjs')]);- plugins.push([require('@babel/plugin-proposal-dynamic-import')]);- }+ if (!isModule) {+ plugins.push([require('@babel/plugin-transform-modules-commonjs')]);+ plugins.push([require('@babel/plugin-proposal-dynamic-import')]);}plugins.unshift(additionalPlugin);diff --git a/packages/playwright-test/src/loader.ts b/packages/playwright-test/src/loader.tsindex aa3820057c..13f662259e 100644--- a/packages/playwright-test/src/loader.ts+++ b/packages/playwright-test/src/loader.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { installTransform, setCurrentlyLoadingTestFile } from './transform';+import { installTransform } from './transform';import type { Config, Project, ReporterDescription, FullProjectInternal, FullConfigInternal, Fixtures, FixturesWithLocation } from './types';import { getPackageJsonPath, mergeObjects, errorWithFile } from './util';import { setCurrentlyLoadingFileSuite } from './globals';@@ -153,7 +153,6 @@ export class Loader {suite._requireFile = file;suite.location = { file, line: 0, column: 0 };- setCurrentlyLoadingTestFile(file);setCurrentlyLoadingFileSuite(suite);try {await this._requireOrImport(file);@@ -163,7 +162,6 @@ export class Loader {throw e;suite._loadError = serializeError(e);} finally {- setCurrentlyLoadingTestFile(null);setCurrentlyLoadingFileSuite(undefined);}diff --git a/packages/playwright-test/src/plugins/vitePlugin.ts b/packages/playwright-test/src/plugins/vitePlugin.tsindex 61c60d606c..0782f3e405 100644--- a/packages/playwright-test/src/plugins/vitePlugin.ts+++ b/packages/playwright-test/src/plugins/vitePlugin.ts@@ -80,10 +80,27 @@ export function createPlugin(const sourcesDirty = !buildExists || hasNewComponents || await checkSources(buildInfo);viteConfig.root = rootDir;+ viteConfig.publicDir = false;viteConfig.preview = { port };viteConfig.build = {outDir};++ // React heuristic. If we see a component in a file with .js extension,+ // consider it a potential JSX-in-JS scenario and enable JSX loader for all+ // .js files.+ if (hasJSComponents(buildInfo.components)) {+ viteConfig.esbuild = {+ loader: 'jsx',+ include: /.*\.jsx?$/,+ exclude: [],+ };+ viteConfig.optimizeDeps = {+ esbuildOptions: {+ loader: { '.js': 'jsx' },+ }+ };+ }const { build, preview } = require('vite');if (sourcesDirty) {viteConfig.plugins = viteConfig.plugins || [@@ -250,6 +267,12 @@ function vitePlugin(registerSource: string, relativeTemplateDir: string, buildIn}}+ // Vite React plugin will do this for .jsx files, but not .js files.+ if (id.endsWith('.js') && content.includes('React.createElement') && !content.includes('import React')) {+ const code = `import React from 'react';\n${content}`;+ return { code, map: { mappings: '' } };+ }+if (!id.endsWith(`${relativeTemplateDir}/index.ts`) && !id.endsWith(`${relativeTemplateDir}/index.tsx`) && !id.endsWith(`${relativeTemplateDir}/index.js`))return;@@ -273,3 +296,12 @@ function vitePlugin(registerSource: string, relativeTemplateDir: string, buildIn},};}++function hasJSComponents(components: ComponentInfo[]): boolean {+ for (const component of components) {+ const extname = path.extname(component.importPath);+ if (extname === '.js' || !extname && fs.existsSync(component.importPath + '.js'))+ return true;+ }+ return false;+}diff --git a/packages/playwright-test/src/transform.ts b/packages/playwright-test/src/transform.tsindex 3a472a7812..a6e4ffe5c6 100644--- a/packages/playwright-test/src/transform.ts+++ b/packages/playwright-test/src/transform.ts@@ -26,7 +26,7 @@ import { tsConfigLoader } from './third_party/tsconfig-loader';import Module from 'module';import type { BabelTransformFunction } from './babelBundle';-const version = 9;+const version = 10;const cacheDir = process.env.PWTEST_CACHE_DIR || path.join(os.tmpdir(), 'playwright-transform-cache');const sourceMaps: Map<string, string> = new Map();@@ -159,17 +159,15 @@ export function resolveHook(filename: string, specifier: string): string | undef}export function transformHook(code: string, filename: string, isModule = false): string {- if (isComponentImport(filename))- return componentStub();-// If we are not TypeScript and there is no applicable preprocessor - bail out.const isTypeScript = filename.endsWith('.ts') || filename.endsWith('.tsx');+ const isJSX = filename.endsWith('.jsx');const hasPreprocessor =process.env.PW_TEST_SOURCE_TRANSFORM &&process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE &&process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE.split(pathSeparator).some(f => filename.startsWith(f));- if (!isTypeScript && !hasPreprocessor)+ if (!isTypeScript && !isJSX && !hasPreprocessor)return code;const cachePath = calculateCachePath(code, filename, isModule);@@ -213,7 +211,7 @@ export function installTransform(): () => void {}(Module as any)._resolveFilename = resolveFilename;- const exts = ['.ts', '.tsx'];+ const exts = ['.ts', '.tsx', '.jsx'];// When script preprocessor is engaged, we transpile JS as well.if (scriptPreprocessor)exts.push('.js', '.mjs');@@ -249,22 +247,3 @@ export function wrapFunctionWithLocation<A extends any[], R>(func: (location: Loreturn func(location, ...args);};}---let currentlyLoadingTestFile: string | null = null;--export function setCurrentlyLoadingTestFile(file: string | null) {- currentlyLoadingTestFile = file;-}--function isComponentImport(filename: string): boolean {- if (filename === currentlyLoadingTestFile)- return false;- return filename.endsWith('.tsx') || filename.endsWith('.jsx');-}--function componentStub(): string {- return `module.exports = new Proxy({}, {- get: (obj, prop) => prop- });`;-}diff --git a/tests/playwright-test/babel.spec.ts b/tests/playwright-test/babel.spec.tsindex 0e2c8a47d9..7eae2e1bb6 100644--- a/tests/playwright-test/babel.spec.ts+++ b/tests/playwright-test/babel.spec.ts@@ -38,8 +38,6 @@ test('should succeed', async ({ runInlineTest }) => {});test('should treat enums equally', async ({ runInlineTest }) => {- test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/13265' });- test.fail();const result = await runInlineTest({'component.tsx': `export enum MyEnum {diff --git a/tests/playwright-test/playwright.ct-build.spec.ts b/tests/playwright-test/playwright.ct-build.spec.tsindex 7c78201722..fd465308b9 100644--- a/tests/playwright-test/playwright.ct-build.spec.ts+++ b/tests/playwright-test/playwright.ct-build.spec.ts@@ -16,7 +16,6 @@import { test, expect, stripAnsi } from './playwright-test-fixtures';import fs from 'fs';-import path from 'path';test.describe.configure({ mode: 'parallel' });@@ -35,7 +34,7 @@ test('should work with the empty component list', async ({ runInlineTest }, testexpect(result.passed).toBe(1);const output = stripAnsi(result.output);expect(output).toContain('transforming...');- expect(output).toContain(path.join('playwright', '.cache', 'playwright', 'index.html'));+ expect(output.replace(/\\+/g, '/')).toContain('playwright/.cache/playwright/index.html');const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8'));expect(metainfo.version).toEqual(expect.any(Number));diff --git a/tests/playwright-test/playwright.ct-react.spec.ts b/tests/playwright-test/playwright.ct-react.spec.tsindex 6523e3a293..5b16f91cb5 100644--- a/tests/playwright-test/playwright.ct-react.spec.ts+++ b/tests/playwright-test/playwright.ct-react.spec.ts@@ -16,11 +16,14 @@import { test, expect } from './playwright-test-fixtures';-test('should work with TSX', async ({ runInlineTest }, testInfo) => {+test('should work with TSX', async ({ runInlineTest }) => {const result = await runInlineTest({'playwright/index.html': `<script type="module" src="/playwright/index.ts"></script>`,- 'playwright/index.ts': ``,+ 'playwright/index.ts': `+ //@no-header+ `,'src/button.tsx': `+ //@no-headerexport const Button = () => <button>Button</button>;`,@@ -40,12 +43,15 @@ test('should work with TSX', async ({ runInlineTest }, testInfo) => {expect(result.passed).toBe(1);});-test.fixme('should work with JSX', async ({ runInlineTest }, testInfo) => {+test('should work with JSX', async ({ runInlineTest }) => {const result = await runInlineTest({'playwright/index.html': `<script type="module" src="/playwright/index.js"></script>`,- 'playwright/index.js': ``,+ 'playwright/index.js': `+ //@no-header+ `,'src/button.jsx': `+ //@no-headerexport const Button = () => <button>Button</button>;`,@@ -65,12 +71,15 @@ test.fixme('should work with JSX', async ({ runInlineTest }, testInfo) => {expect(result.passed).toBe(1);});-test.fixme('should work with JS in JSX', async ({ runInlineTest }, testInfo) => {+test('should work with JSX in JS', async ({ runInlineTest }) => {const result = await runInlineTest({'playwright/index.html': `<script type="module" src="/playwright/index.js"></script>`,- 'playwright/index.js': ``,+ 'playwright/index.js': `+ //@no-header+ `,'src/button.js': `+ //@no-headerexport const Button = () => <button>Button</button>;`,@@ -89,3 +98,145 @@ test.fixme('should work with JS in JSX', async ({ runInlineTest }, testInfo) =>expect(result.exitCode).toBe(0);expect(result.passed).toBe(1);});++test('should work with JSX in JS and in JSX', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright/index.html': `<script type="module" src="/playwright/index.js"></script>`,+ 'playwright/index.js': `+ //@no-header+ `,++ 'src/button.js': `+ //@no-header+ export const Button = () => <button>Button</button>;+ `,++ 'src/list.jsx': `+ //@no-header+ export const List = () => <ul><li>List</li></ul>;+ `,++ 'src/button.test.jsx': `+ //@no-header+ import { test, expect } from '@playwright/experimental-ct-react';+ import { Button } from './button';+ import { List } from './list';++ test('pass button', async ({ mount }) => {+ const component = await mount(<Button></Button>);+ await expect(component).toHaveText('Button');+ });++ test('pass list', async ({ mount }) => {+ const component = await mount(<List></List>);+ await expect(component).toHaveText('List');+ });+ `,+ }, { workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(2);+});+++test('should work with stray TSX import', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright/index.html': `<script type="module" src="/playwright/index.ts"></script>`,+ 'playwright/index.ts': `+ //@no-header+ `,++ 'src/button.tsx': `+ //@no-header+ export const Button = () => <button>Button</button>;+ `,++ 'src/list.tsx': `+ //@no-header+ export const List = () => <ul><li>List</li></ul>;+ `,++ 'src/button.test.tsx': `+ //@no-header+ import { test, expect } from '@playwright/experimental-ct-react';+ import { Button } from './button';+ import { List } from './list';++ test('pass button', async ({ mount }) => {+ const component = await mount(<Button></Button>);+ await expect(component).toHaveText('Button');+ });+ `,+ }, { workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});++test('should work with stray JSX import', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright/index.html': `<script type="module" src="/playwright/index.js"></script>`,+ 'playwright/index.js': `+ //@no-header+ `,++ 'src/button.jsx': `+ //@no-header+ export const Button = () => <button>Button</button>;+ `,++ 'src/list.jsx': `+ //@no-header+ export const List = () => <ul><li>List</li></ul>;+ `,++ 'src/button.test.jsx': `+ //@no-header+ import { test, expect } from '@playwright/experimental-ct-react';+ import { Button } from './button';+ import { List } from './list';++ test('pass button', async ({ mount }) => {+ const component = await mount(<Button></Button>);+ await expect(component).toHaveText('Button');+ });+ `,+ }, { workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});++test.fixme('should work with stray JS import', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright/index.html': `<script type="module" src="/playwright/index.js"></script>`,+ 'playwright/index.js': `+ //@no-header+ `,++ 'src/button.js': `+ //@no-header+ export const Button = () => <button>Button</button>;+ `,++ 'src/list.js': `+ //@no-header+ export const List = () => <ul><li>List</li></ul>;+ `,++ 'src/button.test.jsx': `+ //@no-header+ import { test, expect } from '@playwright/experimental-ct-react';+ import { Button } from './button';+ import { List } from './list';++ test('pass button', async ({ mount }) => {+ const component = await mount(<Button></Button>);+ await expect(component).toHaveText('Button');+ });+ `,+ }, { workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});