@@ -6,6 +6,7 @@ import fs from 'fs'
6
6
import path from 'path'
7
7
import colors from 'css-color-names'
8
8
import { ElementHandle } from 'playwright-chromium'
9
+ import type { Manifest } from 'vite'
9
10
10
11
export function slash ( p : string ) : string {
11
12
return p . replace ( / \\ / g, '/' )
@@ -51,18 +52,18 @@ async function toEl(el: string | ElementHandle): Promise<ElementHandle> {
51
52
return el
52
53
}
53
54
54
- export async function getColor ( el : string | ElementHandle ) {
55
+ export async function getColor ( el : string | ElementHandle ) : Promise < string > {
55
56
el = await toEl ( el )
56
57
const rgb = await el . evaluate ( ( el ) => getComputedStyle ( el as Element ) . color )
57
58
return hexToNameMap [ rgbToHex ( rgb ) ] || rgb
58
59
}
59
60
60
- export async function getBg ( el : string | ElementHandle ) {
61
+ export async function getBg ( el : string | ElementHandle ) : Promise < string > {
61
62
el = await toEl ( el )
62
63
return el . evaluate ( ( el ) => getComputedStyle ( el as Element ) . backgroundImage )
63
64
}
64
65
65
- export function readFile ( filename : string ) {
66
+ export function readFile ( filename : string ) : string {
66
67
return fs . readFileSync ( path . resolve ( testDir , filename ) , 'utf-8' )
67
68
}
68
69
@@ -78,20 +79,20 @@ export function editFile(
78
79
fs . writeFileSync ( filename , modified )
79
80
}
80
81
81
- export function addFile ( filename : string , content : string ) {
82
+ export function addFile ( filename : string , content : string ) : void {
82
83
fs . writeFileSync ( path . resolve ( testDir , filename ) , content )
83
84
}
84
85
85
- export function removeFile ( filename : string ) {
86
+ export function removeFile ( filename : string ) : void {
86
87
fs . unlinkSync ( path . resolve ( testDir , filename ) )
87
88
}
88
89
89
- export function listAssets ( base = '' ) {
90
+ export function listAssets ( base = '' ) : string [ ] {
90
91
const assetsDir = path . join ( testDir , 'dist' , base , 'assets' )
91
92
return fs . readdirSync ( assetsDir )
92
93
}
93
94
94
- export function findAssetFile ( match : string | RegExp , base = '' ) {
95
+ export function findAssetFile ( match : string | RegExp , base = '' ) : string {
95
96
const assetsDir = path . join ( testDir , 'dist' , base , 'assets' )
96
97
const files = fs . readdirSync ( assetsDir )
97
98
const file = files . find ( ( file ) => {
@@ -100,7 +101,7 @@ export function findAssetFile(match: string | RegExp, base = '') {
100
101
return file ? fs . readFileSync ( path . resolve ( assetsDir , file ) , 'utf-8' ) : ''
101
102
}
102
103
103
- export function readManifest ( base = '' ) {
104
+ export function readManifest ( base = '' ) : Manifest {
104
105
return JSON . parse (
105
106
fs . readFileSync ( path . join ( testDir , 'dist' , base , 'manifest.json' ) , 'utf-8' )
106
107
)
@@ -113,7 +114,7 @@ export async function untilUpdated(
113
114
poll : ( ) => string | Promise < string > ,
114
115
expected : string ,
115
116
runInBuild = false
116
- ) {
117
+ ) : Promise < void > {
117
118
if ( isBuild && ! runInBuild ) return
118
119
const maxTries = process . env . CI ? 100 : 50
119
120
for ( let tries = 0 ; tries < maxTries ; tries ++ ) {
0 commit comments