@@ -5,6 +5,14 @@ import { runTests } from '@web/test-runner-core/test-helpers';
55import { legacyPlugin } from '@web/dev-server-legacy' ;
66import { resolve , sep } from 'path' ;
77
8+ function expectIncludes ( actual : string , expected : string ) {
9+ if ( ! actual . includes ( expected ) ) {
10+ throw new Error (
11+ `Expected substring not found.\n\nExpected:\n${ expected } \n\nActual:\n${ actual } ` ,
12+ ) ;
13+ }
14+ }
15+
816const ERROR_NOT_IMPORTABLE = {
917 message :
1018 'Could not import your test module. Check the browser logs or open the browser in debug mode for more information.' ,
@@ -93,7 +101,7 @@ export function runTestFailureTest(
93101 [ 'true is true' , 'true is really true' ] ,
94102 ) ;
95103 assert . equal ( session . errors . length , 1 ) ;
96- assert . ok ( session . errors [ 0 ] . message . includes ( 'error thrown in afterEach hook' ) ) ;
104+ expectIncludes ( session . errors [ 0 ] . message , 'error thrown in afterEach hook' ) ;
97105 assert . ok (
98106 session . errors [ 0 ] . stack ! . includes (
99107 `test-failure${ sep } browser-tests${ sep } fail-after-each.test.js` ,
@@ -112,7 +120,7 @@ export function runTestFailureTest(
112120 [ 'true is true' , 'true is really true' ] ,
113121 ) ;
114122 assert . equal ( session . errors . length , 1 ) ;
115- assert . ok ( session . errors [ 0 ] . message . includes ( 'error thrown in after hook' ) ) ;
123+ expectIncludes ( session . errors [ 0 ] . message , 'error thrown in after hook' ) ;
116124 assert . ok (
117125 session . errors [ 0 ] . stack ! . includes (
118126 `test-failure${ sep } browser-tests${ sep } fail-after.test.js` ,
@@ -131,7 +139,7 @@ export function runTestFailureTest(
131139 [ 'true is true' , 'true is really true' ] ,
132140 ) ;
133141 assert . equal ( session . errors . length , 1 ) ;
134- assert . ok ( session . errors [ 0 ] . message . includes ( 'error thrown in beforeEach hook' ) ) ;
142+ expectIncludes ( session . errors [ 0 ] . message , 'error thrown in beforeEach hook' ) ;
135143 assert . ok (
136144 session . errors [ 0 ] . stack ! . includes (
137145 `test-failure${ sep } browser-tests${ sep } fail-before-each.test.js` ,
@@ -150,7 +158,7 @@ export function runTestFailureTest(
150158 [ 'true is true' , 'true is really true' ] ,
151159 ) ;
152160 assert . equal ( session . errors . length , 1 ) ;
153- assert . ok ( session . errors [ 0 ] . message . includes ( 'error thrown in before hook' ) ) ;
161+ expectIncludes ( session . errors [ 0 ] . message , 'error thrown in before hook' ) ;
154162 assert . ok (
155163 session . errors [ 0 ] . stack ! . includes (
156164 `test-failure${ sep } browser-tests${ sep } fail-before.test.js` ,
@@ -168,7 +176,7 @@ export function runTestFailureTest(
168176 session . testResults ! . tests . map ( t => t . name ) ,
169177 [ 'custom error' ] ,
170178 ) ;
171- assert . ok ( session . testResults ! . tests [ 0 ] . error ! . message . includes ( 'a custom error thrown' ) ) ;
179+ expectIncludes ( session . testResults ! . tests [ 0 ] . error ! . message , 'a custom error thrown' ) ;
172180 assert . ok (
173181 session . testResults ! . tests [ 0 ] . error ! . stack ! . includes (
174182 `browser-tests${ sep } fail-custom-error.test.js` ,
@@ -188,7 +196,7 @@ export function runTestFailureTest(
188196 assert . equal ( session . testResults ! . suites . length , 0 ) ;
189197 assert . equal ( session . testResults ! . tests . length , 0 ) ;
190198 assert . deepEqual ( session . errors , [ ERROR_NOT_IMPORTABLE ] ) ;
191- assert . ok ( ( session . logs [ 0 ] [ 0 ] as any ) . includes ( 'This is thrown before running tests' ) ) ;
199+ expectIncludes ( session . logs [ 0 ] [ 0 ] as string , 'This is thrown before running tests' ) ;
192200 }
193201 } ) ;
194202
@@ -197,9 +205,9 @@ export function runTestFailureTest(
197205 assert . equal ( sessions . length === browserCount , true ) ;
198206 for ( const session of sessions ) {
199207 assert . equal ( session . testResults ! . tests . length , 1 ) ;
200- assert . ok ( session . testResults ! . tests [ 0 ] ! . error ! . message . includes ( 'My error' ) ) ;
201- assert . ok ( session . testResults ! . tests [ 0 ] ! . error ! . stack ! . includes ( 'throwErrorC' ) ) ;
202- assert . ok ( session . testResults ! . tests [ 0 ] ! . error ! . stack ! . includes ( 'fail-stack-trace-c.js' ) ) ;
208+ expectIncludes ( session . testResults ! . tests [ 0 ] ! . error ! . message , 'My error' ) ;
209+ expectIncludes ( session . testResults ! . tests [ 0 ] ! . error ! . stack ! , 'throwErrorC' ) ;
210+ expectIncludes ( session . testResults ! . tests [ 0 ] ! . error ! . stack ! , 'fail-stack-trace-c.js' ) ;
203211 assert . deepEqual ( session . errors , [ ] ) ;
204212 assert . deepEqual ( session . logs , [ ] ) ;
205213 }
0 commit comments