1
- import { TestRunner , TestEndPayload , isUnderTest } from '@cloudflare/playwright/internal' ;
1
+ import { TestRunner , TestEndPayload , isUnderTest , TestInfoError , TestResult } from '@cloudflare/playwright/internal' ;
2
2
import { DurableObject } from 'cloudflare:workers' ;
3
3
import '@workerTests/index' ;
4
4
5
- import { skipTests } from '../skipTests' ;
5
+ import { skipTests , skipErrorMessages } from '../skipTests' ;
6
6
import { BrowserBindingName } from '../utils' ;
7
7
8
8
export type TestRequestPayload = {
@@ -17,6 +17,17 @@ const log = console.log.bind(console);
17
17
18
18
const skipTestsFullTitles = new Set ( skipTests . map ( t => t . join ( ' > ' ) ) ) ;
19
19
20
+ function formatError ( error : TestInfoError | Error | string ) {
21
+ if ( typeof error === 'string' )
22
+ return error ;
23
+ return `${ error . message } ${ error . stack ? `\n${ error . stack } ` : '' } ` ;
24
+ }
25
+
26
+ function shouldSkipTestResult ( testResult : TestResult ) {
27
+ const errorText = testResult . errors . map ( e => formatError ( e ) ) . join ( '\n' ) ;
28
+ return skipErrorMessages . some ( msg => typeof msg === 'string' ? errorText . includes ( msg ) : msg . test ( errorText ) ) ;
29
+ }
30
+
20
31
export class TestsServer extends DurableObject < Env > {
21
32
constructor ( state : DurableObjectState , env : Env ) {
22
33
super ( state , env ) ;
@@ -61,9 +72,28 @@ export class TestsServer extends DurableObject<Env> {
61
72
log ( `🧪 Running ${ fullTitle } ${ retry ? ` (retry #${ retry } )` : '' } ` ) ;
62
73
63
74
const result = await testRunner . runTest ( file , testId ) ;
75
+
64
76
if ( ! [ 'passed' , 'skipped' ] . includes ( result . status ) ) {
65
- const error = result . errors [ 0 ] ;
66
- log ( `❌ ${ fullTitle } failed with status ${ result . status } ${ error ? `: ${ error . message } ` : '' } ${ error . stack ? `\n${ error . stack } ` : '' } ` ) ;
77
+ if ( shouldSkipTestResult ( result ) ) {
78
+ log ( `🚫 Skipping ${ fullTitle } because it failed with a known error message` ) ;
79
+ return Response . json ( {
80
+ testId,
81
+ status : 'skipped' ,
82
+ errors : result . errors ,
83
+ annotations : [
84
+ {
85
+ type : 'skip' ,
86
+ description : `Test skipped because it failed with a known error message` ,
87
+ }
88
+ ] ,
89
+ duration : 0 ,
90
+ hasNonRetriableError : false ,
91
+ timeout,
92
+ expectedStatus : 'skipped'
93
+ } satisfies TestEndPayload ) ;
94
+ }
95
+ const [ error ] = result . errors ;
96
+ log ( `❌ ${ fullTitle } failed with status ${ result . status } ${ error ? `: ${ formatError ( error ) } ` : '' } ` ) ;
67
97
}
68
98
return Response . json ( result ) ;
69
99
}
0 commit comments