Skip to content

Commit 1a8bd61

Browse files
committed
test: cover global scriptRegex in a dedicated build
1 parent 81bcfe2 commit 1a8bd61

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎test/basic/index.test.ts‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ for (const compiler of ['native', 'babel']) {
1313
test(`renders typed SSR output with ${compiler}`, async () => {
1414
const cwd = await mkdtemp(path.join(playground, 'test-temp-'));
1515
try {
16-
await writeFile(
17-
path.join(cwd, 'Title.tsx'),
18-
'export const Title = () => <h1>Hello</h1>;',
19-
);
2016
await writeFile(
2117
path.join(cwd, 'app.tsx'),
2218
`
2319
import { renderToString } from '@solidjs/web';
24-
import { Title } from './Title.tsx';
25-
export const html: string = renderToString(() => <Title />);
20+
const title: string = 'Hello';
21+
export const html = renderToString(() => <h1>{title}</h1>);
2622
`,
2723
);
2824
await new Promise<void>((resolve, reject) => {
@@ -50,11 +46,7 @@ for (const compiler of ['native', 'babel']) {
5046
},
5147
{
5248
loader: 'solid-loader',
53-
options: {
54-
compiler,
55-
scriptRegex: /\.tsx$/g,
56-
solid: { generate: 'ssr' },
57-
},
49+
options: { compiler, solid: { generate: 'ssr' } },
5850
},
5951
],
6052
},

‎test/basic/scriptRegex.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { promisify } from 'node:util';
4+
import { rspack } from '@rspack/core';
5+
import { expect, test } from '@rstest/playwright';
6+
7+
test('compiles consecutive JSX files with a global scriptRegex', async () => {
8+
const playground = path.resolve(import.meta.dirname, '../../playground');
9+
const cwd = await mkdtemp(path.join(playground, 'test-temp-'));
10+
try {
11+
await writeFile(
12+
path.join(cwd, 'app.jsx'),
13+
"import './view.jsx'; export default <main />;",
14+
);
15+
await writeFile(path.join(cwd, 'view.jsx'), 'export default <p />;');
16+
17+
const stats = await promisify(rspack)({
18+
context: cwd,
19+
mode: 'development',
20+
entry: './app.jsx',
21+
output: { path: cwd },
22+
module: {
23+
rules: [
24+
{
25+
test: /\.jsx$/,
26+
loader: 'solid-loader',
27+
options: { scriptRegex: /\.jsx$/g },
28+
},
29+
],
30+
},
31+
});
32+
expect(stats?.toJson({ all: false, errors: true }).errors).toEqual([]);
33+
} finally {
34+
await rm(cwd, { recursive: true, force: true });
35+
}
36+
});

0 commit comments

Comments
 (0)