Skip to content

Commit 00075e9

Browse files
authored
test(e2e): add test case for constant inlining optimization (#6044)
1 parent c6482d5 commit 00075e9

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { build, dev, rspackOnlyTest } from '@e2e/helper';
2+
import { expect, test } from '@playwright/test';
3+
4+
rspackOnlyTest(
5+
'should inline the constants in production mode',
6+
async ({ page }) => {
7+
const rsbuild = await build({
8+
cwd: __dirname,
9+
page,
10+
});
11+
expect(await page.evaluate(() => window.test1)).toBe('Fish fish, Cat cat');
12+
expect(await page.evaluate(() => window.test2)).toBe('Fish FISH, Cat CAT');
13+
14+
const indexJs = await rsbuild.getIndexBundle();
15+
expect(indexJs).toContain('window.test1="Fish fish, Cat cat"');
16+
expect(indexJs).toContain('window.test2="Fish FISH, Cat CAT"');
17+
18+
await rsbuild.close();
19+
},
20+
);
21+
22+
test('should import the constants as expected in development mode', async ({
23+
page,
24+
}) => {
25+
const rsbuild = await dev({
26+
cwd: __dirname,
27+
page,
28+
});
29+
expect(await page.evaluate(() => window.test1)).toBe('Fish fish, Cat cat');
30+
expect(await page.evaluate(() => window.test2)).toBe('Fish FISH, Cat CAT');
31+
await rsbuild.close();
32+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const FISH = 'fish';
2+
export const CAT = 'cat';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { CAT, FISH } from './constants';
2+
3+
declare global {
4+
interface Window {
5+
test1: string;
6+
test2: string;
7+
}
8+
}
9+
10+
window.test1 = `Fish ${FISH}, Cat ${CAT}`;
11+
window.test2 = `Fish ${FISH.toUpperCase()}, Cat ${CAT.toUpperCase()}`;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@rsbuild/config/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "./dist"
5+
},
6+
"include": ["src", "*.test.ts"]
7+
}

0 commit comments

Comments
 (0)