@@ -4,11 +4,15 @@ import glob from 'tiny-glob/sync';
4
4
import * as path from 'path' ;
5
5
import * as fs from 'fs' ;
6
6
import * as colors from 'kleur' ;
7
- export const assert = ( assert$1 as unknown ) as typeof assert$1 & { htmlEqual : ( actual : string , expected : string , message ?: string ) => void , htmlEqualWithOptions : ( actual : string , expected : string , options : { preserveComments ?: boolean , withoutNormalizeHtml ?: boolean } , message ?: string ) => void } ;
7
+
8
+ /**
9
+ * @type {typeof assert$1 & { htmlEqual: (actual: string, expected: string, message?: string) => void, htmlEqualWithOptions: (actual: string, expected: string, options: { preserveComments?: boolean, withoutNormalizeHtml?: boolean }, message?: string) => void } }
10
+ */
11
+ export const assert = /** @type {any } */ ( assert$1 ) ;
8
12
9
13
// for coverage purposes, we need to test source files,
10
14
// but for sanity purposes, we need to test dist files
11
- export function loadSvelte ( test : boolean = false ) {
15
+ export function loadSvelte ( test = false ) {
12
16
process . env . TEST = test ? 'true' : '' ;
13
17
14
18
const resolved = require . resolve ( '../compiler.js' ) ;
@@ -68,7 +72,7 @@ for (const key of Object.getOwnPropertyNames(global)) {
68
72
}
69
73
70
74
// implement mock scroll
71
- window . scrollTo = function ( pageXOffset , pageYOffset ) {
75
+ window . scrollTo = function ( pageXOffset , pageYOffset ) {
72
76
window . pageXOffset = pageXOffset ;
73
77
window . pageYOffset = pageYOffset ;
74
78
} ;
@@ -140,7 +144,14 @@ function cleanChildren(node) {
140
144
}
141
145
}
142
146
143
- export function normalizeHtml ( window , html , { removeDataSvelte = false , preserveComments = false } : { removeDataSvelte ?: boolean , preserveComments ?: boolean } ) {
147
+ /**
148
+ *
149
+ * @param {Window } window
150
+ * @param {string } html
151
+ * @param {{ removeDataSvelte?: boolean, preserveComments?: boolean } } param2
152
+ * @returns
153
+ */
154
+ export function normalizeHtml ( window , html , { removeDataSvelte = false , preserveComments = false } ) {
144
155
try {
145
156
const node = window . document . createElement ( 'div' ) ;
146
157
node . innerHTML = html
@@ -155,11 +166,18 @@ export function normalizeHtml(window, html, { removeDataSvelte = false, preserve
155
166
}
156
167
}
157
168
158
- export function normalizeNewline ( html : string ) {
169
+ /**
170
+ * @param {string } html
171
+ * @returns {string }
172
+ */
173
+ export function normalizeNewline ( html ) {
159
174
return html . replace ( / \r \n / g, '\n' ) ;
160
175
}
161
176
162
- export function setupHtmlEqual ( options : { removeDataSvelte ?: boolean } = { } ) {
177
+ /**
178
+ * @param {{ removeDataSvelte?: boolean } } options
179
+ */
180
+ export function setupHtmlEqual ( options = { } ) {
163
181
const window = env ( ) ;
164
182
165
183
// eslint-disable-next-line no-import-assign
@@ -170,8 +188,15 @@ export function setupHtmlEqual(options: { removeDataSvelte?: boolean } = {}) {
170
188
message
171
189
) ;
172
190
} ;
173
- // eslint-disable-next-line no-import-assign
174
- assert . htmlEqualWithOptions = ( actual : string , expected : string , { preserveComments, withoutNormalizeHtml } : { preserveComments ?: boolean , withoutNormalizeHtml ?: boolean } , message ?: string ) => {
191
+
192
+ /**
193
+ *
194
+ * @param {string } actual
195
+ * @param {string } expected
196
+ * @param {{ preserveComments?: boolean, withoutNormalizeHtml?: boolean } } param2
197
+ * @param {string? } message
198
+ */
199
+ assert . htmlEqualWithOptions = ( actual , expected , { preserveComments, withoutNormalizeHtml } , message ) => {
175
200
assert . deepEqual (
176
201
withoutNormalizeHtml
177
202
? normalizeNewline ( actual ) . replace ( / ( \s d a t a - s v e l t e - h = " [ ^ " ] + " ) / g, options . removeDataSvelte ? '' : '$1' )
@@ -252,7 +277,8 @@ const original_set_timeout = global.setTimeout;
252
277
export function useFakeTimers ( ) {
253
278
const callbacks = [ ] ;
254
279
255
- global . setTimeout = function ( fn ) {
280
+ // @ts -ignore
281
+ global . setTimeout = function ( fn ) {
256
282
callbacks . push ( fn ) ;
257
283
} ;
258
284
@@ -289,7 +315,14 @@ export function prettyPrintPuppeteerAssertionError(message) {
289
315
}
290
316
}
291
317
292
- export async function retryAsync < T > ( fn : ( ) => Promise < T > , maxAttempts : number = 3 , interval : number = 1000 ) : Promise < T > {
318
+ /**
319
+ *
320
+ * @param {() => Promise<import ('puppeteer').Browser> } fn
321
+ * @param {number } maxAttempts
322
+ * @param {number } interval
323
+ * @returns {Promise<import ('puppeteer').Browser> }
324
+ */
325
+ export async function retryAsync ( fn , maxAttempts = 3 , interval = 1000 ) {
293
326
let attempts = 0 ;
294
327
while ( attempts <= maxAttempts ) {
295
328
try {
@@ -301,15 +334,23 @@ export async function retryAsync<T>(fn: () => Promise<T>, maxAttempts: number =
301
334
}
302
335
}
303
336
304
- // NOTE: Chromium may exit with SIGSEGV, so retry in that case
305
- export async function executeBrowserTest < T > ( browser , launchPuppeteer : ( ) => Promise < T > , additionalAssertion : ( ) => void , onError : ( err : Error ) => void ) {
337
+ /**
338
+ * NOTE: Chromium may exit with SIGSEGV, so retry in that case
339
+ * @param {import ('puppeteer').Browser } browser
340
+ * @param {() => Promise<import ('puppeteer').Browser> } launchPuppeteer
341
+ * @param {() => void } additionalAssertion
342
+ * @param {(err: Error) => void } onError
343
+ * @returns {Promise<import ('puppeteer').Browser> }
344
+ */
345
+ export async function executeBrowserTest ( browser , launchPuppeteer , additionalAssertion , onError ) {
306
346
let count = 0 ;
307
347
do {
308
348
count ++ ;
309
349
try {
310
350
const page = await browser . newPage ( ) ;
311
351
312
352
page . on ( 'console' , ( type ) => {
353
+ // @ts -ignore -- TODO: Fix type
313
354
console [ type . _type ] ( type . _text ) ;
314
355
} ) ;
315
356
@@ -318,7 +359,10 @@ export async function executeBrowserTest<T>(browser, launchPuppeteer: () => Prom
318
359
console . error ( error ) ;
319
360
} ) ;
320
361
await page . goto ( 'http://localhost:6789' ) ;
321
- const result = await page . evaluate ( ( ) => test ( document . querySelector ( 'main' ) ) ) ;
362
+ const result = await page . evaluate ( ( ) => {
363
+ // @ts -ignore -- It runs in browser context.
364
+ return test ( document . querySelector ( 'main' ) ) ;
365
+ } ) ;
322
366
if ( result ) console . log ( result ) ;
323
367
additionalAssertion ( ) ;
324
368
await page . close ( ) ;
0 commit comments