Skip to content

Commit f8ce783

Browse files
authored
test: fix server hmr port conflict (#8197)
1 parent a788f39 commit f8ce783

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

playground/ssr-vue/__tests__/serve.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import path from 'path'
55
import kill from 'kill-port'
6-
import { isBuild, ports, rootDir } from '~utils'
6+
import { hmrPorts, isBuild, ports, rootDir } from '~utils'
77

88
export const port = ports['ssr-vue']
99

@@ -37,7 +37,11 @@ export async function serve() {
3737
await kill(port)
3838

3939
const { createServer } = require(path.resolve(rootDir, 'server.js'))
40-
const { app, vite } = await createServer(rootDir, isBuild)
40+
const { app, vite } = await createServer(
41+
rootDir,
42+
isBuild,
43+
hmrPorts['ssr-vue']
44+
)
4145

4246
return new Promise((resolve, reject) => {
4347
try {

playground/ssr-vue/server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD
77

88
async function createServer(
99
root = process.cwd(),
10-
isProd = process.env.NODE_ENV === 'production'
10+
isProd = process.env.NODE_ENV === 'production',
11+
hmrPort
1112
) {
1213
const resolve = (p) => path.resolve(__dirname, p)
1314

@@ -37,6 +38,9 @@ async function createServer(
3738
// misses change events, so enforce polling for consistency
3839
usePolling: true,
3940
interval: 100
41+
},
42+
hmr: {
43+
port: hmrPort
4044
}
4145
}
4246
})

playground/test-utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export const ports = {
3434
'css/postcss-caching': 5005,
3535
'css/postcss-plugins-different-dir': 5006
3636
}
37+
export const hmrPorts = {
38+
'optimize-missing-deps': 24680,
39+
'ssr-deps': 24681,
40+
'ssr-html': 24682,
41+
'ssr-pug': 24683,
42+
'ssr-react': 24684,
43+
'ssr-vue': 24685
44+
}
3745

3846
const hexToNameMap: Record<string, string> = {}
3947
Object.keys(colors).forEach((color) => {

0 commit comments

Comments
 (0)