@@ -26,15 +26,20 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
26
26
} ) ;
27
27
28
28
it ( 'should succeed with a file' , async ( ) => {
29
- const stream = run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] } ) ;
29
+ const stream = run ( { files : [ join ( testFixtures , 'default-behavior/ test/random.cjs' ) ] } ) ;
30
30
stream . on ( 'test:fail' , common . mustNotCall ( ) ) ;
31
31
stream . on ( 'test:pass' , common . mustCall ( 1 ) ) ;
32
32
// eslint-disable-next-line no-unused-vars
33
33
for await ( const _ of stream ) ;
34
34
} ) ;
35
35
36
36
it ( 'should run same file twice' , async ( ) => {
37
- const stream = run ( { files : [ join ( testFixtures , 'test/random.cjs' ) , join ( testFixtures , 'test/random.cjs' ) ] } ) ;
37
+ const stream = run ( {
38
+ files : [
39
+ join ( testFixtures , 'default-behavior/test/random.cjs' ) ,
40
+ join ( testFixtures , 'default-behavior/test/random.cjs' ) ,
41
+ ]
42
+ } ) ;
38
43
stream . on ( 'test:fail' , common . mustNotCall ( ) ) ;
39
44
stream . on ( 'test:pass' , common . mustCall ( 2 ) ) ;
40
45
// eslint-disable-next-line no-unused-vars
@@ -68,7 +73,9 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
68
73
} ) ;
69
74
70
75
it ( 'should be piped with dot' , async ( ) => {
71
- const result = await run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] } ) . compose ( dot ) . toArray ( ) ;
76
+ const result = await run ( {
77
+ files : [ join ( testFixtures , 'default-behavior/test/random.cjs' ) ]
78
+ } ) . compose ( dot ) . toArray ( ) ;
72
79
assert . deepStrictEqual ( result , [
73
80
'.' ,
74
81
'\n' ,
@@ -77,15 +84,19 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
77
84
78
85
it ( 'should be piped with spec' , async ( ) => {
79
86
const specReporter = new spec ( ) ;
80
- const result = await run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] } ) . compose ( specReporter ) . toArray ( ) ;
87
+ const result = await run ( {
88
+ files : [ join ( testFixtures , 'default-behavior/test/random.cjs' ) ]
89
+ } ) . compose ( specReporter ) . toArray ( ) ;
81
90
const stringResults = result . map ( ( bfr ) => bfr . toString ( ) ) ;
82
91
assert . match ( stringResults [ 0 ] , / t h i s s h o u l d p a s s / ) ;
83
92
assert . match ( stringResults [ 1 ] , / t e s t s 1 / ) ;
84
93
assert . match ( stringResults [ 1 ] , / p a s s 1 / ) ;
85
94
} ) ;
86
95
87
96
it ( 'should be piped with tap' , async ( ) => {
88
- const result = await run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] } ) . compose ( tap ) . toArray ( ) ;
97
+ const result = await run ( {
98
+ files : [ join ( testFixtures , 'default-behavior/test/random.cjs' ) ]
99
+ } ) . compose ( tap ) . toArray ( ) ;
89
100
assert . strictEqual ( result . length , 13 ) ;
90
101
assert . strictEqual ( result [ 0 ] , 'TAP version 13\n' ) ;
91
102
assert . strictEqual ( result [ 1 ] , '# Subtest: this should pass\n' ) ;
@@ -103,24 +114,44 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
103
114
} ) ;
104
115
105
116
it ( 'should skip tests not matching testNamePatterns - RegExp' , async ( ) => {
106
- const result = await run ( { files : [ join ( testFixtures , 'test/skip_by_name.cjs' ) ] , testNamePatterns : [ / e x e c u t e d / ] } )
117
+ const result = await run ( {
118
+ files : [ join ( testFixtures , 'default-behavior/test/skip_by_name.cjs' ) ] ,
119
+ testNamePatterns : [ / e x e c u t e d / ]
120
+ } )
107
121
. compose ( tap )
108
122
. toArray ( ) ;
109
123
assert . strictEqual ( result [ 2 ] , 'ok 1 - this should be skipped # SKIP test name does not match pattern\n' ) ;
110
124
assert . strictEqual ( result [ 5 ] , 'ok 2 - this should be executed\n' ) ;
111
125
} ) ;
112
126
113
127
it ( 'should skip tests not matching testNamePatterns - string' , async ( ) => {
114
- const result = await run ( { files : [ join ( testFixtures , 'test/skip_by_name.cjs' ) ] , testNamePatterns : [ 'executed' ] } )
128
+ const result = await run ( {
129
+ files : [ join ( testFixtures , 'default-behavior/test/skip_by_name.cjs' ) ] ,
130
+ testNamePatterns : [ 'executed' ]
131
+ } )
115
132
. compose ( tap )
116
133
. toArray ( ) ;
117
134
assert . strictEqual ( result [ 2 ] , 'ok 1 - this should be skipped # SKIP test name does not match pattern\n' ) ;
118
135
assert . strictEqual ( result [ 5 ] , 'ok 2 - this should be executed\n' ) ;
119
136
} ) ;
120
137
138
+ it ( 'should emit "test:watch:drained" event on watch mode' , async ( ) => {
139
+ const controller = new AbortController ( ) ;
140
+ await run ( {
141
+ files : [ join ( testFixtures , 'default-behavior/test/random.cjs' ) ] ,
142
+ watch : true ,
143
+ signal : controller . signal ,
144
+ } ) . on ( 'data' , function ( { type } ) {
145
+ if ( type === 'test:watch:drained' ) {
146
+ controller . abort ( ) ;
147
+ }
148
+ } ) ;
149
+ } ) ;
150
+
151
+ describe ( 'AbortSignal' , ( ) => {
121
152
it ( 'should stop watch mode when abortSignal aborts' , async ( ) => {
122
153
const controller = new AbortController ( ) ;
123
- const result = await run ( { files : [ join ( testFixtures , 'test/random.cjs' ) ] , watch : true , signal : controller . signal } )
154
+ const result = await run ( { files : [ join ( testFixtures , 'default-behavior/ test/random.cjs' ) ] , watch : true , signal : controller . signal } )
124
155
. compose ( async function * ( source ) {
125
156
for await ( const chunk of source ) {
126
157
if ( chunk . type === 'test:pass' ) {
@@ -133,14 +164,71 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
133
164
assert . deepStrictEqual ( result , [ 'this should pass' ] ) ;
134
165
} ) ;
135
166
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 ( ) ;
167
+ it ( 'should abort when test succeeded' , async ( ) => {
168
+ const stream = run ( {
169
+ files : [
170
+ fixtures . path (
171
+ 'test-runner' ,
172
+ 'aborts' ,
173
+ 'successful-test-still-call-abort.js'
174
+ ) ,
175
+ ] ,
176
+ } ) ;
177
+
178
+ let passedTestCount = 0 ;
179
+ let failedTestCount = 0 ;
180
+
181
+ let output = '' ;
182
+ for await ( const data of stream ) {
183
+ if ( data . type === 'test:stdout' ) {
184
+ output += data . data . message . toString ( ) ;
185
+ }
186
+ if ( data . type === 'test:fail' ) {
187
+ failedTestCount ++ ;
142
188
}
189
+ if ( data . type === 'test:pass' ) {
190
+ passedTestCount ++ ;
191
+ }
192
+ }
193
+
194
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 1 / ) ;
195
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 2 / ) ;
196
+ assert . strictEqual ( failedTestCount , 0 , new Error ( 'no tests should fail' ) ) ;
197
+ assert . strictEqual ( passedTestCount , 2 ) ;
198
+ } ) ;
199
+
200
+ it ( 'should abort when test failed' , async ( ) => {
201
+ const stream = run ( {
202
+ files : [
203
+ fixtures . path (
204
+ 'test-runner' ,
205
+ 'aborts' ,
206
+ 'failed-test-still-call-abort.js'
207
+ ) ,
208
+ ] ,
143
209
} ) ;
210
+
211
+ let passedTestCount = 0 ;
212
+ let failedTestCount = 0 ;
213
+
214
+ let output = '' ;
215
+ for await ( const data of stream ) {
216
+ if ( data . type === 'test:stdout' ) {
217
+ output += data . data . message . toString ( ) ;
218
+ }
219
+ if ( data . type === 'test:fail' ) {
220
+ failedTestCount ++ ;
221
+ }
222
+ if ( data . type === 'test:pass' ) {
223
+ passedTestCount ++ ;
224
+ }
225
+ }
226
+
227
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 1 / ) ;
228
+ assert . match ( output , / a b o r t c a l l e d f o r t e s t 2 / ) ;
229
+ assert . strictEqual ( passedTestCount , 0 , new Error ( 'no tests should pass' ) ) ;
230
+ assert . strictEqual ( failedTestCount , 2 ) ;
231
+ } ) ;
144
232
} ) ;
145
233
146
234
describe ( 'sharding' , ( ) => {
0 commit comments