Skip to content

Commit 0b8f0f6

Browse files
committed
test: simplify
1 parent 1dc3574 commit 0b8f0f6

File tree

4 files changed

+22
-80
lines changed

4 files changed

+22
-80
lines changed

playground/ssr-react/__tests__/serve.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

playground/ssr-react/__tests__/ssr-react.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import fetch from 'node-fetch'
22
import { expect, test } from 'vitest'
3-
import { port } from './serve'
43
import {
54
browserLogs,
65
editFile,
76
isBuild,
87
page,
98
untilBrowserLogAfter,
109
untilUpdated,
10+
viteTestUrl as url,
1111
} from '~utils'
1212

13-
const url = `http://localhost:${port}`
14-
1513
test('/env', async () => {
16-
await untilBrowserLogAfter(() => page.goto(url + '/env'), 'hydrated')
14+
await untilBrowserLogAfter(() => page.goto(url + `/env`), 'hydrated')
1715

16+
await page.pause()
1817
expect(await page.textContent('h1')).toMatch('default message here')
1918

2019
// raw http request

playground/ssr-react/vite.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import react from '@vitejs/plugin-react'
33
import fs from 'node:fs'
44
import path from 'node:path'
55

6+
process.env.MY_CUSTOM_SECRET = 'API_KEY_qwertyuiop'
7+
68
export default defineConfig({
79
appType: 'custom',
810
build: {
@@ -72,4 +74,6 @@ export default defineConfig({
7274
},
7375
},
7476
],
77+
// tell vitestSetup.ts to use buildApp API
78+
builder: {},
7579
})

playground/vitestSetup.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from 'vite'
1515
import {
1616
build,
17+
createBuilder,
1718
createServer,
1819
loadConfigFromFile,
1920
mergeConfig,
@@ -253,6 +254,7 @@ export async function startDefaultServe(): Promise<void> {
253254
viteTestUrl = `http://localhost:${server.config.server.port}${
254255
devBase === '/' ? '' : devBase
255256
}`
257+
setViteUrl(viteTestUrl)
256258
await page.goto(viteTestUrl)
257259
} else {
258260
process.env.VITE_INLINE = 'inline-build'
@@ -267,12 +269,17 @@ export async function startDefaultServe(): Promise<void> {
267269
const testConfig = mergeConfig(options, config || {})
268270
viteConfig = testConfig
269271
process.chdir(rootDir)
270-
const rollupOutput = await build(testConfig)
271-
const isWatch = !!resolvedConfig!.build.watch
272-
// in build watch,call startStaticServer after the build is complete
273-
if (isWatch) {
274-
watcher = rollupOutput as Rollup.RollupWatcher
275-
await notifyRebuildComplete(watcher)
272+
if (testConfig.builder) {
273+
const builder = await createBuilder(testConfig)
274+
await builder.buildApp()
275+
} else {
276+
const rollupOutput = await build(testConfig)
277+
const isWatch = !!resolvedConfig!.build.watch
278+
// in build watch,call startStaticServer after the build is complete
279+
if (isWatch) {
280+
watcher = rollupOutput as Rollup.RollupWatcher
281+
await notifyRebuildComplete(watcher)
282+
}
276283
}
277284
// @ts-ignore
278285
if (config && config.__test__) {
@@ -284,6 +291,8 @@ export async function startDefaultServe(): Promise<void> {
284291
// prevent preview change NODE_ENV
285292
process.env.NODE_ENV = _nodeEnv
286293
viteTestUrl = previewServer.resolvedUrls.local[0]
294+
viteTestUrl = viteTestUrl.replace(/\/+$/, '')
295+
setViteUrl(viteTestUrl)
287296
await page.goto(viteTestUrl)
288297
}
289298
}

0 commit comments

Comments
 (0)