File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed
e2e/cases/optimization/inline-const Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 1+ export const FISH = 'fish' ;
2+ export const CAT = 'cat' ;
Original file line number Diff line number Diff line change 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 ( ) } ` ;
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " @rsbuild/config/tsconfig" ,
3+ "compilerOptions" : {
4+ "outDir" : " ./dist"
5+ },
6+ "include" : [" src" , " *.test.ts" ]
7+ }
You can’t perform that action at this time.
0 commit comments