@@ -136,6 +136,10 @@ class FileTest extends Test {
136136 #rawBufferSize = 0 ;
137137 #reportedChildren = 0 ;
138138 failedSubtests = false ;
139+
140+ #bailAmount = this . root . harness . bailAmount ;
141+ #failedTestsCount = 0 ;
142+
139143 #skipReporting( ) {
140144 return this . #reportedChildren > 0 && ( ! this . error || this . error . failureType === kSubtestsFailed ) ;
141145 }
@@ -179,6 +183,11 @@ class FileTest extends Test {
179183 if ( item . type !== 'test:pass' && item . type !== 'test:fail' ) {
180184 return ;
181185 }
186+
187+ if ( item . type === 'test:fail' ) {
188+ this . #failedTestsCount++ ;
189+ }
190+
182191 this . #reportedChildren++ ;
183192 if ( item . data . nesting === 0 && item . type === 'test:fail' ) {
184193 this . failedSubtests = true ;
@@ -191,6 +200,9 @@ class FileTest extends Test {
191200 }
192201 }
193202 addToReport ( item ) {
203+ if ( this . #bailAmount && this . #failedTestsCount > this . #bailAmount) {
204+ return ;
205+ }
194206 this . #accumulateReportItem( item ) ;
195207 if ( ! this . isClearToSend ( ) ) {
196208 ArrayPrototypePush ( this . #reportBuffer, item ) ;
@@ -425,7 +437,7 @@ function run(options) {
425437 options = kEmptyObject ;
426438 }
427439 let { testNamePatterns, shard } = options ;
428- const { concurrency, timeout, signal, files, inspectPort, watch, setup } = options ;
440+ const { concurrency, timeout, signal, files, inspectPort, watch, setup, bail } = options ;
429441
430442 if ( files != null ) {
431443 validateArray ( files , 'options.files' ) ;
@@ -469,6 +481,10 @@ function run(options) {
469481 } ) ;
470482 }
471483
484+ if ( bail != null ) {
485+ validateInteger ( bail , 'options.bail' , 0 ) ;
486+ }
487+
472488 const root = createTestTree ( { concurrency, timeout, signal } ) ;
473489 let testFiles = files ?? createTestFileList ( ) ;
474490
0 commit comments