Skip to content

Commit 55eebad

Browse files
committed
cherry-pick(#23211): chore: allow stub JSX instances in type module
1 parent bc9f9b7 commit 55eebad

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

packages/playwright-test/jsx-runtime.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ function jsxs(type, props) {
2828
};
2929
}
3030

31+
const Fragment = {};
32+
3133
module.exports = {
34+
Fragment,
3235
jsx,
3336
jsxs,
3437
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import jsxRuntime from './jsx-runtime.js';
18+
19+
export const jsx = jsxRuntime.jsx;
20+
export const jsxs = jsxRuntime.jsxs;
21+
export const Fragment = jsxRuntime.Fragment;

packages/playwright-test/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
"./lib/internalsForTest": "./lib/internalsForTest.js",
2323
"./lib/experimentalLoader": "./lib/experimentalLoader.js",
2424
"./lib/plugins": "./lib/plugins/index.js",
25-
"./jsx-runtime": "./jsx-runtime.js",
25+
"./jsx-runtime": {
26+
"import": "./jsx-runtime.mjs",
27+
"require": "./jsx-runtime.js",
28+
"default": "./jsx-runtime.js"
29+
},
2630
"./lib/util": "./lib/util.js",
2731
"./lib/utilsBundle": "./lib/utilsBundle.js",
2832
"./reporter": "./reporter.js"

tests/playwright-test/loader.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,34 @@ test('should load a jsx/tsx files', async ({ runInlineTest }) => {
488488
expect(exitCode).toBe(0);
489489
});
490490

491+
test('should load a jsx/tsx files in ESM mode', async ({ runInlineTest }) => {
492+
const { exitCode, passed } = await runInlineTest({
493+
'package.json': JSON.stringify({
494+
type: 'module'
495+
}),
496+
'playwright.config.ts': `
497+
import { defineConfig } from '@playwright/test';
498+
export default defineConfig({ projects: [{name: 'foo'}] });
499+
`,
500+
'a.spec.tsx': `
501+
import { test, expect } from '@playwright/test';
502+
const component = () => <div></div>;
503+
test('succeeds', () => {
504+
expect(1 + 1).toBe(2);
505+
});
506+
`,
507+
'b.spec.jsx': `
508+
import { test, expect } from '@playwright/test';
509+
const component = () => <div></div>;
510+
test('succeeds', () => {
511+
expect(1 + 1).toBe(2);
512+
});
513+
`
514+
});
515+
expect(passed).toBe(2);
516+
expect(exitCode).toBe(0);
517+
});
518+
491519
test('should load jsx with top-level component', async ({ runInlineTest }) => {
492520
const { exitCode, passed } = await runInlineTest({
493521
'a.spec.tsx': `

0 commit comments

Comments
 (0)