-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
backend-https-vite-http.ts
96 lines (81 loc) · 2.25 KB
/
backend-https-vite-http.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { test, expect } from '@playwright/test'
import { spawn } from 'cross-spawn'
import {
editFile,
getWorkspaceFileURL,
killProcess,
ports,
collectAndWaitUntilOutput,
createSetupAndGotoPage
} from '../utils/index.js'
const workspaceFileURL = getWorkspaceFileURL(
'fixture',
'backend-https-vite-http'
)
const accessURL = `https://localhost:${ports.backendHttpsViteHttp}/`
const startVite = async () => {
// pnpm run dev cannot be used because killing process does not work
const viteDevProcess = spawn('pnpm', ['run', 'dev:vite'], {
cwd: workspaceFileURL
})
const backendProcess = spawn('pnpm', ['run', 'dev:backend'], {
cwd: workspaceFileURL
})
await Promise.all([
collectAndWaitUntilOutput(
viteDevProcess.stdout,
viteDevProcess.stderr,
'use --host to expose'
),
collectAndWaitUntilOutput(
backendProcess.stdout,
backendProcess.stderr,
'Open your browser.'
)
])
return async () => {
try {
await killProcess(viteDevProcess)
} catch {}
try {
await killProcess(backendProcess)
} catch {}
}
}
const setupAndGotoPage = createSetupAndGotoPage(accessURL, 1000)
test('hmr test', async ({ page }) => {
const finishVite = await startVite()
try {
await setupAndGotoPage(page)
const title = page.locator('h1')
await expect(title).toHaveText('Hello Vite!')
await editFile('./frontend-src/main.js', workspaceFileURL, content =>
content.replace('Vite!</h1>', 'Vite!!!</h1>')
)
await expect(title).toHaveText('Hello Vite!!!')
} finally {
await finishVite()
}
})
test('restart test', async ({ page }) => {
let finishVite1: (() => Promise<void>) | undefined
let finishVite2: (() => Promise<void>) | undefined
try {
finishVite1 = await startVite()
await setupAndGotoPage(page, { waitUntil: 'load' })
const loadPromise = page.waitForEvent('load', { timeout: 3000 })
await finishVite1()
finishVite1 = undefined
finishVite2 = await startVite()
await loadPromise
} finally {
await finishVite1?.()
await finishVite2?.()
}
})
test.afterAll(async () => {
// cleanup
await editFile('./frontend-src/main.js', workspaceFileURL, content =>
content.replace('Vite!!!</h1>', 'Vite!</h1>')
)
})