@@ -5,42 +5,17 @@ import fs from 'node:fs'
5
5
import path from 'node:path'
6
6
import colors from 'css-color-names'
7
7
import type { ConsoleMessage , ElementHandle } from 'playwright-chromium'
8
- import type { Manifest } from 'vite'
9
- import { normalizePath } from 'vite'
10
- import { fromComment } from 'convert-source-map'
11
8
import { expect } from 'vitest'
12
- import type { ExecaChildProcess } from 'execa'
13
- import { isBuild , isWindows , page , testDir } from './vitestSetup'
9
+ import { isBuild , page , testDir } from './vitestSetup'
14
10
15
11
export * from './vitestSetup'
16
12
17
13
// make sure these ports are unique
18
14
export const ports = {
19
- cli : 9510 ,
20
- 'cli-module' : 9511 ,
21
- 'legacy/ssr' : 9520 ,
22
- lib : 9521 ,
23
- 'optimize-missing-deps' : 9522 ,
24
- 'legacy/client-and-ssr' : 9523 ,
25
- 'ssr-deps' : 9600 ,
26
- 'ssr-html' : 9601 ,
27
- 'ssr-noexternal' : 9602 ,
28
- 'ssr-pug' : 9603 ,
29
15
'ssr-react' : 9604 ,
30
- 'ssr-vue' : 9605 ,
31
- 'ssr-webworker' : 9606 ,
32
- 'css/postcss-caching' : 5005 ,
33
- 'css/postcss-plugins-different-dir' : 5006 ,
34
- 'css/dynamic-import' : 5007 ,
35
16
}
36
17
export const hmrPorts = {
37
- 'optimize-missing-deps' : 24680 ,
38
- 'ssr-deps' : 24681 ,
39
- 'ssr-html' : 24682 ,
40
- 'ssr-noexternal' : 24683 ,
41
- 'ssr-pug' : 24684 ,
42
18
'ssr-react' : 24685 ,
43
- 'ssr-vue' : 24686 ,
44
19
}
45
20
46
21
const hexToNameMap : Record < string , string > = { }
@@ -117,38 +92,6 @@ export function removeFile(filename: string): void {
117
92
fs . unlinkSync ( path . resolve ( testDir , filename ) )
118
93
}
119
94
120
- export function listAssets ( base = '' ) : string [ ] {
121
- const assetsDir = path . join ( testDir , 'dist' , base , 'assets' )
122
- return fs . readdirSync ( assetsDir )
123
- }
124
-
125
- export function findAssetFile (
126
- match : string | RegExp ,
127
- base = '' ,
128
- assets = 'assets' ,
129
- ) : string {
130
- const assetsDir = path . join ( testDir , 'dist' , base , assets )
131
- let files : string [ ]
132
- try {
133
- files = fs . readdirSync ( assetsDir )
134
- } catch ( e ) {
135
- if ( e . code === 'ENOENT' ) {
136
- return ''
137
- }
138
- throw e
139
- }
140
- const file = files . find ( ( file ) => {
141
- return file . match ( match )
142
- } )
143
- return file ? fs . readFileSync ( path . resolve ( assetsDir , file ) , 'utf-8' ) : ''
144
- }
145
-
146
- export function readManifest ( base = '' ) : Manifest {
147
- return JSON . parse (
148
- fs . readFileSync ( path . join ( testDir , 'dist' , base , 'manifest.json' ) , 'utf-8' ) ,
149
- )
150
- }
151
-
152
95
/**
153
96
* Poll a getter until the value it returns includes the expected value.
154
97
*/
@@ -170,25 +113,6 @@ export async function untilUpdated(
170
113
}
171
114
}
172
115
173
- /**
174
- * Retry `func` until it does not throw error.
175
- */
176
- export async function withRetry (
177
- func : ( ) => Promise < void > ,
178
- runInBuild = false ,
179
- ) : Promise < void > {
180
- if ( isBuild && ! runInBuild ) return
181
- const maxTries = process . env . CI ? 200 : 50
182
- for ( let tries = 0 ; tries < maxTries ; tries ++ ) {
183
- try {
184
- await func ( )
185
- return
186
- } catch { }
187
- await timeout ( 50 )
188
- }
189
- await func ( )
190
- }
191
-
192
116
type UntilBrowserLogAfterCallback = ( logs : string [ ] ) => PromiseLike < void > | void
193
117
194
118
export async function untilBrowserLogAfter (
@@ -288,32 +212,6 @@ async function untilBrowserLog(
288
212
return logs
289
213
}
290
214
291
- export const extractSourcemap = ( content : string ) : any => {
292
- const lines = content . trim ( ) . split ( '\n' )
293
- return fromComment ( lines [ lines . length - 1 ] ) . toObject ( )
294
- }
295
-
296
- export const formatSourcemapForSnapshot = ( map : any ) : any => {
297
- const root = normalizePath ( testDir )
298
- const m = { ...map }
299
- delete m . file
300
- delete m . names
301
- m . sources = m . sources . map ( ( source ) => source . replace ( root , '/root' ) )
302
- return m
303
- }
304
-
305
- // helper function to kill process, uses taskkill on windows to ensure child process is killed too
306
- export async function killProcess (
307
- serverProcess : ExecaChildProcess ,
308
- ) : Promise < void > {
309
- if ( isWindows ) {
310
- try {
311
- const { execaCommandSync } = await import ( 'execa' )
312
- execaCommandSync ( `taskkill /pid ${ serverProcess . pid } /T /F` )
313
- } catch ( e ) {
314
- console . error ( 'failed to taskkill:' , e )
315
- }
316
- } else {
317
- serverProcess . kill ( 'SIGTERM' , { forceKillAfterTimeout : 2000 } )
318
- }
319
- }
215
+ /**
216
+ * Before implementing a new util, check if it's not available in core https://github.com/vitejs/vite/blob/main/playground/test-utils.ts
217
+ */
0 commit comments