Skip to content

Commit 474ebca

Browse files
committed
fix: setup tests
1 parent 03112f8 commit 474ebca

File tree

5 files changed

+71
-20
lines changed

5 files changed

+71
-20
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"typecheck": "tsc -p scripts && tsc -p playground && tsc -p packages/plugin-react",
2424
"test": "pnpm run test-serve && pnpm run test-build && pnpm --filter ./packages/plugin-react-swc run test",
2525
"test-serve": "vitest run -c playground/vitest.config.e2e.ts",
26+
"test-full-bundle-mode-serve": "VITE_TEST_FULL_BUNDLE_MODE=1 vitest run -c playground/vitest.config.e2e.ts",
2627
"test-build": "VITE_TEST_BUILD=1 vitest run -c playground/vitest.config.e2e.ts",
2728
"debug-serve": "VITE_DEBUG_SERVE=1 vitest run -c playground/vitest.config.e2e.ts",
2829
"debug-build": "VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 vitest run -c playground/vitest.config.e2e.ts",

packages/plugin-react-oxc/src/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
102102
}
103103

104104
let skipFastRefresh = false
105-
105+
let base: string | undefined
106106
const viteRefreshWrapper: Plugin = {
107107
name: 'vite:react-oxc:refresh-wrapper',
108108
apply: 'serve',
109109
configResolved(config) {
110+
base = config.base
110111
skipFastRefresh = config.isProduction || config.server.hmr === false
111112
},
112113
transform: {
@@ -135,15 +136,22 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
135136
return { code: newCode, map: null }
136137
},
137138
},
138-
transformIndexHtml(_, config) {
139-
if (!skipFastRefresh)
140-
return [
141-
{
142-
tag: 'script',
143-
attrs: { type: 'module' },
144-
children: getPreambleCode(config.server!.config.base),
145-
},
146-
]
139+
transformIndexHtml: {
140+
handler() {
141+
if (!skipFastRefresh)
142+
return [
143+
{
144+
tag: 'script',
145+
attrs: { type: 'module' },
146+
// !!! Rolldown vite full bunlde module break changes, config.server is invalid
147+
// children: getPreambleCode(config.server!.config.base),
148+
children: getPreambleCode(base!),
149+
},
150+
]
151+
},
152+
// Rolldown vite full bunlde module break changes.
153+
// Changed it to make sure the inject module could be bundled
154+
order: 'pre',
147155
},
148156
}
149157

packages/plugin-react-swc/src/index.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const react = (_options?: Options): PluginOption[] => {
9191
_options?.useAtYourOwnRisk_mutateSwcOptions,
9292
}
9393

94+
let base: string | undefined
9495
return [
9596
{
9697
name: 'vite:react-swc:resolve-runtime',
@@ -118,6 +119,7 @@ const react = (_options?: Options): PluginOption[] => {
118119
},
119120
}),
120121
configResolved(config) {
122+
base = config.base
121123
if (config.server.hmr === false) hmrDisabled = true
122124
const mdxIndex = config.plugins.findIndex(
123125
(p) => p.name === '@mdx-js/rollup',
@@ -132,13 +134,22 @@ const react = (_options?: Options): PluginOption[] => {
132134
)
133135
}
134136
},
135-
transformIndexHtml: (_, config) => [
136-
{
137-
tag: 'script',
138-
attrs: { type: 'module' },
139-
children: getPreambleCode(config.server!.config.base),
137+
transformIndexHtml: {
138+
handler() {
139+
return [
140+
{
141+
tag: 'script',
142+
attrs: { type: 'module' },
143+
// !!! Rolldown vite full bunlde module break changes, config.server is invalid
144+
// children: getPreambleCode(config.server!.config.base),
145+
children: getPreambleCode(base!),
146+
},
147+
]
140148
},
141-
],
149+
// Rolldown vite full bunlde module break changes.
150+
// Changed it to make sure the inject module could be bundled
151+
order: 'pre',
152+
},
142153
async transform(code, _id, transformOptions) {
143154
const id = _id.split('?')[0]
144155
const refresh = !transformOptions?.ssr && !hmrDisabled

playground/vitest.config.e2e.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ export default defineConfig({
1111
},
1212
test: {
1313
pool: 'forks',
14-
include: ['./playground/**/*.spec.[tj]s'],
14+
include: process.env.VITE_TEST_FULL_BUNDLE_MODE
15+
? [
16+
'./playground/class-components/**/*.spec.[tj]s',
17+
'./playground/compiler/**/*.spec.[tj]s',
18+
'./playground/compiler-react-18/**/*.spec.[tj]s',
19+
'./playground/mdx/**/*.spec.[tj]s',
20+
// './playground/react/**/*.spec.[tj]s',
21+
// './playground/react-classic/**/*.spec.[tj]s',
22+
'./playground/react-emotion/**/*.spec.[tj]s',
23+
'./playground/react-env/**/*.spec.[tj]s',
24+
'./playground/react-sourcemap/**/*.spec.[tj]s',
25+
// './playground/ssr-react/**/*.spec.[tj]s',
26+
]
27+
: ['./playground/**/*.spec.[tj]s'],
1528
setupFiles: ['./playground/vitestSetup.ts'],
1629
globalSetup: ['./playground/vitestGlobalSetup.ts'],
1730
testTimeout: timeout,

playground/vitestSetup.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,39 @@ async function loadConfig(configEnv: ConfigEnv) {
214214
// tests are flaky when `emptyOutDir` is `true`
215215
emptyOutDir: false,
216216
},
217+
experimental: {
218+
fullBundleMode: !!process.env.VITE_TEST_FULL_BUNDLE_MODE,
219+
},
217220
customLogger: createInMemoryLogger(serverLogs),
218221
}
219222
return mergeConfig(options, config || {})
220223
}
221224

222225
export async function startDefaultServe(): Promise<void> {
223-
const { build, createBuilder, createServer, mergeConfig, preview } =
224-
await importVite()
226+
const {
227+
build,
228+
createBuilder,
229+
createServer,
230+
mergeConfig,
231+
preview,
232+
createServerWithResolvedConfig,
233+
} = await importVite()
225234

226235
setupConsoleWarnCollector(serverLogs)
227236

228237
if (!isBuild) {
229238
process.env.VITE_INLINE = 'inline-serve'
230239
const config = await loadConfig({ command: 'serve', mode: 'development' })
231-
viteServer = server = await (await createServer(config)).listen()
240+
241+
if (process.env.VITE_TEST_FULL_BUNDLE_MODE) {
242+
const builder = await createBuilder(config, null, 'serve')
243+
viteServer = server = await createServerWithResolvedConfig(builder.config)
244+
await server.listen()
245+
await builder.buildApp(server)
246+
} else {
247+
viteServer = server = await (await createServer(config)).listen()
248+
}
249+
232250
viteTestUrl = stripTrailingSlashIfNeeded(
233251
server.resolvedUrls.local[0],
234252
server.config.base,

0 commit comments

Comments
 (0)