@@ -118,29 +118,104 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
118
118
assert . strictEqual ( result [ 5 ] , 'ok 2 - this should be executed\n' ) ;
119
119
} ) ;
120
120
121
- it ( 'should stop watch mode when abortSignal aborts ' , async ( ) => {
121
+ it ( 'should emit "test: watch:drained" event on watch mode ' , async ( ) => {
122
122
const controller = new AbortController ( ) ;
123
- const result = await run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] , watch : true , signal : controller . signal } )
124
- . compose ( async function * ( source ) {
125
- for await ( const chunk of source ) {
126
- if ( chunk . type === 'test:pass' ) {
127
- controller . abort ( ) ;
128
- yield chunk . data . name ;
129
- }
130
- }
131
- } )
132
- . toArray ( ) ;
133
- assert . deepStrictEqual ( result , [ 'this should pass' ] ) ;
123
+ await run ( {
124
+ files : [ join ( testFixtures , 'test/random.cjs' ) ] ,
125
+ watch : true ,
126
+ signal : controller . signal ,
127
+ } ) . on ( 'data' , function ( { type } ) {
128
+ if ( type === 'test:watch:drained' ) {
129
+ controller . abort ( ) ;
130
+ }
131
+ } ) ;
134
132
} ) ;
135
133
136
- it ( 'should emit "test:watch:drained" event on watch mode' , async ( ) => {
137
- const controller = new AbortController ( ) ;
138
- await run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] , watch : true , signal : controller . signal } )
139
- . on ( 'data' , function ( { type } ) {
140
- if ( type === 'test:watch:drained' ) {
141
- controller . abort ( ) ;
134
+ describe ( 'AbortSignal' , ( ) => {
135
+ it ( 'should stop watch mode when abortSignal aborts' , async ( ) => {
136
+ const controller = new AbortController ( ) ;
137
+ const result = await run ( {
138
+ files : [ join ( testFixtures , 'test/random.cjs' ) ] ,
139
+ watch : true ,
140
+ signal : controller . signal ,
141
+ } )
142
+ . compose ( async function * ( source ) {
143
+ for await ( const chunk of source ) {
144
+ if ( chunk . type === 'test:pass' ) {
145
+ controller . abort ( ) ;
146
+ yield chunk . data . name ;
147
+ }
148
+ }
149
+ } )
150
+ . toArray ( ) ;
151
+ assert . deepStrictEqual ( result , [ 'this should pass' ] ) ;
152
+ } ) ;
153
+
154
+ it ( 'should abort when test succeeded' , async ( ) => {
155
+ const stream = run ( {
156
+ files : [
157
+ fixtures . path (
158
+ 'test-runner' ,
159
+ 'aborts' ,
160
+ 'successful-test-still-call-abort.js'
161
+ ) ,
162
+ ] ,
163
+ } ) ;
164
+
165
+ let passedTestCount = 0 ;
166
+ let failedTestCount = 0 ;
167
+
168
+ let output = '' ;
169
+ for await ( const data of stream ) {
170
+ if ( data . type === 'test:stdout' ) {
171
+ output += data . data . message . toString ( ) ;
172
+ }
173
+ if ( data . type === 'test:fail' ) {
174
+ failedTestCount ++ ;
142
175
}
176
+ if ( data . type === 'test:pass' ) {
177
+ passedTestCount ++ ;
178
+ }
179
+ }
180
+
181
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 1 / ) ;
182
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 2 / ) ;
183
+ assert . strictEqual ( failedTestCount , 0 , new Error ( 'no tests should fail' ) ) ;
184
+ assert . strictEqual ( passedTestCount , 2 ) ;
185
+ } ) ;
186
+
187
+ it ( 'should abort when test failed' , async ( ) => {
188
+ const stream = run ( {
189
+ files : [
190
+ fixtures . path (
191
+ 'test-runner' ,
192
+ 'aborts' ,
193
+ 'failed-test-still-call-abort.js'
194
+ ) ,
195
+ ] ,
143
196
} ) ;
197
+
198
+ let passedTestCount = 0 ;
199
+ let failedTestCount = 0 ;
200
+
201
+ let output = '' ;
202
+ for await ( const data of stream ) {
203
+ if ( data . type === 'test:stdout' ) {
204
+ output += data . data . message . toString ( ) ;
205
+ }
206
+ if ( data . type === 'test:fail' ) {
207
+ failedTestCount ++ ;
208
+ }
209
+ if ( data . type === 'test:pass' ) {
210
+ passedTestCount ++ ;
211
+ }
212
+ }
213
+
214
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 1 / ) ;
215
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 2 / ) ;
216
+ assert . strictEqual ( passedTestCount , 0 , new Error ( 'no tests should pass' ) ) ;
217
+ assert . strictEqual ( failedTestCount , 2 ) ;
218
+ } ) ;
144
219
} ) ;
145
220
146
221
describe ( 'sharding' , ( ) => {
0 commit comments