@@ -10,7 +10,6 @@ const { puppeteer, executablePath } = await PCR({});
10
10
const __root = fileURLToPath ( new URL ( '..' , import . meta. url ) ) ;
11
11
12
12
const qps = getQPs ( ) ;
13
- const headless = process . argv . includes ( '--headless' ) ;
14
13
const check = process . argv . includes ( '--check' ) ;
15
14
const failingOnly = process . argv . includes ( '--failing-only' ) || check ;
16
15
@@ -126,207 +125,40 @@ stderr('[ci] puppeteer launched');
126
125
* FailedAssertion[]}} TestEnd
127
126
*/
128
127
129
- const headlessHandler = {
130
- /**
131
- * @param {RunStart } runStart
132
- */
133
- runStart ( runStart ) {
134
- console . log ( `[HARNESS] run start: ${ runStart . testCounts . total } ` ) ;
135
- } ,
136
-
137
- /**
138
- * @param {RunEnd } runEnd
139
- */
140
- runEnd ( runEnd ) {
141
- console . log (
142
- `[HARNESS] run end: ${ runEnd . status } (${ runEnd . runtime } ms, ${ runEnd . testCounts . total } tests)`
143
- ) ;
144
- } ,
145
-
146
- /**
147
- * @param {SuiteStart } suiteStart
148
- */
149
- suiteStart ( suiteStart ) {
150
- console . log ( `[HARNESS] suite start: ${ suiteStart . fullName . join ( ' ' ) } ` ) ;
151
- } ,
152
-
153
- /**
154
- * @param {SuiteEnd } suiteEnd
155
- */
156
- suiteEnd ( suiteEnd ) {
157
- console . log ( `[HARNESS] suite end: ${ suiteEnd . fullName . join ( ' ' ) } ` ) ;
158
- } ,
159
-
160
- /**
161
- * @param {TestStart } testStart
162
- */
163
- testStart ( testStart ) {
164
- console . log ( `[HARNESS] test start: ${ testStart . fullName . join ( ' ' ) } ` ) ;
165
- } ,
166
-
167
- /**
168
- * @param {TestEnd } testEnd
169
- */
170
- testEnd ( testEnd ) {
171
- if ( testEnd . status === 'failed' ) {
172
- console . error (
173
- `[HARNESS] test end: ${ testEnd . fullName . join ( ' ' ) } - failed (${ testEnd . runtime } ms)`
174
- ) ;
175
- for ( const error of testEnd . errors ) {
176
- console . error ( `- ${ error . message || 'Unknown error' } ` ) ;
177
- if ( error . stack ) {
178
- console . error ( error . stack ) ;
179
- }
180
- }
181
- } else {
182
- console . log (
183
- `[HARNESS] test end: ${ testEnd . fullName . join ( ' ' ) } - ${ testEnd . status } (${ testEnd . runtime } ms)`
184
- ) ;
185
- }
186
- } ,
187
-
188
- /**
189
- * @param {string } type
190
- * @param {...unknown } args
191
- */
192
- other ( type , ...args ) {
193
- stderr ( `[HARNESS] [${ type . toUpperCase ( ) } ]` , ...args ) ;
194
- } ,
195
- } ;
196
-
197
- class TapHandler {
198
- #current = 1 ;
199
-
200
- /**
201
- * @param {unknown } string
202
- * @returns {string }
203
- */
204
- #format( string ) {
205
- if ( typeof string === 'string' ) {
206
- return string . trim ( ) . replace ( / \n / gu, '\n# ' ) ;
207
- }
208
-
209
- const json = JSON . stringify ( string ) ?? 'undefined' ;
210
-
211
- if ( json . length > 100 || json . includes ( '\n' ) ) {
212
- return this . #format( JSON . stringify ( string , null , 2 ) ) ;
213
- } else {
214
- return json ;
215
- }
216
- }
217
-
218
- /**
219
- * @param {RunStart } runStart
220
- */
221
- runStart ( runStart ) {
222
- console . log ( `TAP version 13` ) ;
223
- console . log ( `# ${ runStart . testCounts . total } tests` ) ;
224
- }
225
-
226
- /**
227
- * @param {RunEnd } runEnd
228
- */
229
- runEnd ( runEnd ) {
230
- console . log ( `1..${ runEnd . testCounts . total } ` ) ;
231
- if ( runEnd . status === 'failed' ) {
232
- console . error ( `# tests failed: ${ runEnd . testCounts . failed } ` ) ;
233
- process . exit ( 1 ) ;
234
- } else {
235
- console . log ( `# tests passed: ${ runEnd . testCounts . passed } ` ) ;
236
- process . exit ( 0 ) ;
237
- }
238
- }
239
-
240
- /**
241
- * @param {SuiteStart } suiteStart
242
- */
243
- suiteStart ( suiteStart ) {
244
- console . log ( `# Suite: ${ suiteStart . fullName . join ( ' ' ) } ` ) ;
245
- }
246
-
247
- /**
248
- * @param {SuiteEnd } suiteEnd
249
- */
250
- suiteEnd ( suiteEnd ) {
251
- console . log ( `# End of suite: ${ suiteEnd . fullName . join ( ' ' ) } ` ) ;
252
- }
253
-
254
- /**
255
- * @param {TestStart } _testStart
256
- */
257
- testStart ( _testStart ) {
258
- // console.log(`# Test: ${testStart.fullName.join(' ')}`);
259
- }
260
-
261
- /**
262
- * @param {TestEnd } testEnd
263
- */
264
- testEnd ( testEnd ) {
265
- const fullName = this . #format( testEnd . fullName . join ( ' ' ) ) ;
266
- const msg = `${ this . #current++ } (${ testEnd . runtime } ms) ${ fullName } ` ;
267
- if ( testEnd . status === 'failed' ) {
268
- console . log ( `not ok ${ msg } ` ) ;
269
- for ( const error of testEnd . errors ) {
270
- this . failedAssertion ( error ) ;
128
+ /**
129
+ * @param {string } type
130
+ * @param {...unknown } args
131
+ */
132
+ function other ( type , ...args ) {
133
+ if ( ! failingOnly ) {
134
+ if ( args . length === 1 ) {
135
+ const [ arg ] = args ;
136
+ if ( typeof arg === 'string' && ! arg . includes ( '\n' ) ) {
137
+ console . error ( `# [${ type . toUpperCase ( ) } ] ${ arg } ` ) ;
138
+ return ;
139
+ } else if ( ( typeof arg !== 'object' && typeof arg !== 'string' ) || arg === null ) {
140
+ console . error ( `# [${ type . toUpperCase ( ) } ] ${ JSON . stringify ( arg ) } ` ) ;
141
+ return ;
271
142
}
272
- } else if ( ! failingOnly ) {
273
- console . log ( `ok ${ msg } ` ) ;
274
143
}
275
- }
276
144
277
- /**
278
- * @param {FailedAssertion } failedAssertion
279
- */
280
- failedAssertion ( failedAssertion ) {
281
- console . error ( `not ok - ${ failedAssertion . message || 'Unknown error' } ` ) ;
282
- if ( failedAssertion . stack ) {
283
- console . error ( `# ${ this . #format( failedAssertion . stack ) } ` ) ;
284
- } else {
285
- console . error ( `# ${ this . #format( failedAssertion . message || 'Unknown error' ) } ` ) ;
286
- }
287
- console . log ( ` ---` ) ;
288
- console . log ( ` Expected: ${ failedAssertion . expected } ` ) ;
289
- console . log ( ` Actual: ${ failedAssertion . actual } ` ) ;
290
- console . log ( ` ...` ) ;
291
- }
145
+ console . error ( `# [${ type . toUpperCase ( ) } ]` ) ;
292
146
293
- /**
294
- * @param {string } type
295
- * @param {...unknown } args
296
- */
297
- other ( type , ...args ) {
298
- if ( ! failingOnly ) {
299
- if ( args . length === 1 ) {
300
- const [ arg ] = args ;
301
- if ( typeof arg === 'string' && ! arg . includes ( '\n' ) ) {
302
- console . error ( `# [${ type . toUpperCase ( ) } ] ${ arg } ` ) ;
303
- return ;
304
- } else if ( ( typeof arg !== 'object' && typeof arg !== 'string' ) || arg === null ) {
305
- console . error ( `# [${ type . toUpperCase ( ) } ] ${ JSON . stringify ( arg ) } ` ) ;
306
- return ;
307
- }
308
- }
309
-
310
- console . error ( `# [${ type . toUpperCase ( ) } ]` ) ;
311
-
312
- for ( const arg of args ) {
313
- if ( typeof arg === 'string' ) {
314
- const lines = arg . split ( '\n' ) ;
315
- for ( const line of lines ) {
316
- if ( line ) {
317
- console . error ( `# > ${ line } ` ) ;
318
- }
147
+ for ( const arg of args ) {
148
+ if ( typeof arg === 'string' ) {
149
+ const lines = arg . split ( '\n' ) ;
150
+ for ( const line of lines ) {
151
+ if ( line ) {
152
+ console . error ( `# > ${ line } ` ) ;
319
153
}
320
- } else {
321
- console . error ( `# > ` , arg ) ;
322
154
}
155
+ } else {
156
+ console . error ( `# > ` , arg ) ;
323
157
}
324
158
}
325
159
}
326
160
}
327
161
328
- const handler = headless ? headlessHandler : new TapHandler ( ) ;
329
-
330
162
try {
331
163
stderr ( '[ci] navigating to new page' ) ;
332
164
const page = await browser . newPage ( ) ;
@@ -365,7 +197,7 @@ try {
365
197
return ;
366
198
}
367
199
368
- handler . other ( msg . type ( ) , first , ...rest ) ;
200
+ other ( msg . type ( ) , first , ...rest ) ;
369
201
} ) ;
370
202
371
203
const { promise } = Promise . withResolvers ( ) ;
@@ -388,16 +220,10 @@ process.exit(0);
388
220
389
221
/**
390
222
* @param {string } msg
223
+ * @param {...unknown[] } args
391
224
*/
392
- function stdout ( msg ) {
393
- console . log ( msg ) ;
394
- }
395
-
396
- /**
397
- * @param {string } msg
398
- */
399
- function stderr ( msg ) {
225
+ function stderr ( msg , ...args ) {
400
226
if ( ! failingOnly ) {
401
- console . error ( msg ) ;
227
+ console . error ( msg , ... args ) ;
402
228
}
403
229
}
0 commit comments