11// Flags: --expose-gc
22'use strict' ;
33
4- require ( '../common' ) ;
4+ const common = require ( '../common' ) ;
55const { inspect } = require ( 'util' ) ;
66
7- const {
8- ok,
9- notStrictEqual,
10- strictEqual,
11- throws,
12- } = require ( 'assert' ) ;
7+ const assert = require ( 'assert' ) ;
138
149const {
1510 test,
@@ -25,34 +20,34 @@ const{setTimeout: sleep } = require('timers/promises');
2520test ( 'Abort is fired with the correct event type on AbortControllers' , ( ) => {
2621// Tests that abort is fired with the correct event type on AbortControllers
2722const ac = new AbortController ( ) ;
28- ok ( ac . signal ) ;
23+ assert . ok ( ac . signal ) ;
2924
30- const fn = mock . fn ( ( event ) => {
31- ok ( event ) ;
32- strictEqual ( event . type , 'abort' ) ;
33- } ) ;
25+ const fn = mock . fn ( common . mustCall ( ( event ) => {
26+ assert . ok ( event ) ;
27+ assert . strictEqual ( event . type , 'abort' ) ;
28+ } , 2 ) ) ;
3429
3530ac . signal . onabort = fn ;
3631ac . signal . addEventListener ( 'abort' , fn ) ;
3732
3833ac . abort ( ) ;
3934ac . abort ( ) ;
40- ok ( ac . signal . aborted ) ;
35+ assert . ok ( ac . signal . aborted ) ;
4136
42- strictEqual ( fn . mock . calls . length , 2 ) ;
37+ assert . strictEqual ( fn . mock . calls . length , 2 ) ;
4338} ) ;
4439
4540test ( 'Abort events are trusted' , ( ) => {
4641// Tests that abort events are trusted
4742const ac = new AbortController ( ) ;
4843
49- const fn = mock . fn ( ( event ) => {
50- ok ( event . isTrusted ) ;
51- } ) ;
44+ const fn = mock . fn ( common . mustCall ( ( event ) => {
45+ assert . ok ( event . isTrusted ) ;
46+ } ) ) ;
5247
5348ac . signal . onabort = fn ;
5449ac . abort ( ) ;
55- strictEqual ( fn . mock . calls . length , 1 ) ;
50+ assert . strictEqual ( fn . mock . calls . length , 1 ) ;
5651} ) ;
5752
5853test ( 'Abort events have the same isTrusted reference' , ( ) => {
@@ -73,14 +68,14 @@ test('Abort events have the same isTrusted reference', () =>{
7368const firstTrusted = Reflect . getOwnPropertyDescriptor ( Object . getPrototypeOf ( ev1 ) , 'isTrusted' ) . get ;
7469const secondTrusted = Reflect . getOwnPropertyDescriptor ( Object . getPrototypeOf ( ev2 ) , 'isTrusted' ) . get ;
7570const untrusted = Reflect . getOwnPropertyDescriptor ( Object . getPrototypeOf ( ev3 ) , 'isTrusted' ) . get ;
76- strictEqual ( firstTrusted , secondTrusted ) ;
77- strictEqual ( untrusted , firstTrusted ) ;
71+ assert . strictEqual ( firstTrusted , secondTrusted ) ;
72+ assert . strictEqual ( untrusted , firstTrusted ) ;
7873} ) ;
7974
8075test ( 'AbortSignal is impossible to construct manually' , ( ) => {
8176// Tests that AbortSignal is impossible to construct manually
8277const ac = new AbortController ( ) ;
83- throws ( ( ) => new ac . signal . constructor ( ) , {
78+ assert . throws ( ( ) => new ac . signal . constructor ( ) , {
8479code : 'ERR_ILLEGAL_CONSTRUCTOR' ,
8580} ) ;
8681} ) ;
@@ -89,13 +84,13 @@ test('Symbol.toStringTag is correct', () =>{
8984// Symbol.toStringTag
9085const toString = ( o ) => Object . prototype . toString . call ( o ) ;
9186const ac = new AbortController ( ) ;
92- strictEqual ( toString ( ac ) , '[object AbortController]' ) ;
93- strictEqual ( toString ( ac . signal ) , '[object AbortSignal]' ) ;
87+ assert . strictEqual ( toString ( ac ) , '[object AbortController]' ) ;
88+ assert . strictEqual ( toString ( ac . signal ) , '[object AbortSignal]' ) ;
9489} ) ;
9590
9691test ( 'AbortSignal.abort() creates an already aborted signal' , ( ) => {
9792const signal = AbortSignal . abort ( ) ;
98- ok ( signal . aborted ) ;
93+ assert . ok ( signal . aborted ) ;
9994} ) ;
10095
10196test ( 'AbortController properties and methods valiate the receiver' , ( ) => {
@@ -106,7 +101,7 @@ test('AbortController properties and methods valiate the receiver', () =>{
106101const acAbort = AbortController . prototype . abort ;
107102
108103const goodController = new AbortController ( ) ;
109- ok ( acSignalGet . call ( goodController ) ) ;
104+ assert . ok ( acSignalGet . call ( goodController ) ) ;
110105acAbort . call ( goodController ) ;
111106
112107const badAbortControllers = [
@@ -119,11 +114,11 @@ test('AbortController properties and methods valiate the receiver', () =>{
119114{ __proto__ : AbortController . prototype } ,
120115] ;
121116for ( const badController of badAbortControllers ) {
122- throws (
117+ assert . throws (
123118( ) => acSignalGet . call ( badController ) ,
124119{ name : 'TypeError' }
125120) ;
126- throws (
121+ assert . throws (
127122( ) => acAbort . call ( badController ) ,
128123{ name : 'TypeError' }
129124) ;
@@ -137,7 +132,7 @@ test('AbortSignal properties validate the receiver', () =>{
137132) . get ;
138133
139134const goodSignal = new AbortController ( ) . signal ;
140- strictEqual ( signalAbortedGet . call ( goodSignal ) , false ) ;
135+ assert . strictEqual ( signalAbortedGet . call ( goodSignal ) , false ) ;
141136
142137const badAbortSignals = [
143138null ,
@@ -149,7 +144,7 @@ test('AbortSignal properties validate the receiver', () =>{
149144{ __proto__ : AbortSignal . prototype } ,
150145] ;
151146for ( const badSignal of badAbortSignals ) {
152- throws (
147+ assert . throws (
153148( ) => signalAbortedGet . call ( badSignal ) ,
154149{ name : 'TypeError' }
155150) ;
@@ -158,38 +153,38 @@ test('AbortSignal properties validate the receiver', () =>{
158153
159154test ( 'AbortController inspection depth 1 or null works' , ( ) => {
160155const ac = new AbortController ( ) ;
161- strictEqual ( inspect ( ac , { depth : 1 } ) ,
162- 'AbortController{signal: [AbortSignal] }' ) ;
163- strictEqual ( inspect ( ac , { depth : null } ) ,
164- 'AbortController{signal: AbortSignal{aborted: false } }' ) ;
156+ assert . strictEqual ( inspect ( ac , { depth : 1 } ) ,
157+ 'AbortController{signal: [AbortSignal] }' ) ;
158+ assert . strictEqual ( inspect ( ac , { depth : null } ) ,
159+ 'AbortController{signal: AbortSignal{aborted: false } }' ) ;
165160} ) ;
166161
167162test ( 'AbortSignal reason is set correctly' , ( ) => {
168163// Test AbortSignal.reason
169164const ac = new AbortController ( ) ;
170165ac . abort ( 'reason' ) ;
171- strictEqual ( ac . signal . reason , 'reason' ) ;
166+ assert . strictEqual ( ac . signal . reason , 'reason' ) ;
172167} ) ;
173168
174169test ( 'AbortSignal reasonable is set correctly with AbortSignal.abort()' , ( ) => {
175170// Test AbortSignal.reason
176171const signal = AbortSignal . abort ( 'reason' ) ;
177- strictEqual ( signal . reason , 'reason' ) ;
172+ assert . strictEqual ( signal . reason , 'reason' ) ;
178173} ) ;
179174
180175test ( 'AbortSignal.timeout() works as expected' , async ( ) => {
181176// Test AbortSignal timeout
182177const signal = AbortSignal . timeout ( 10 ) ;
183- ok ( ! signal . aborted ) ;
178+ assert . ok ( ! signal . aborted ) ;
184179
185180const { promise, resolve } = Promise . withResolvers ( ) ;
186181
187- const fn = mock . fn ( ( ) => {
188- ok ( signal . aborted ) ;
189- strictEqual ( signal . reason . name , 'TimeoutError' ) ;
190- strictEqual ( signal . reason . code , 23 ) ;
182+ const fn = mock . fn ( common . mustCall ( ( ) => {
183+ assert . ok ( signal . aborted ) ;
184+ assert . strictEqual ( signal . reason . name , 'TimeoutError' ) ;
185+ assert . strictEqual ( signal . reason . code , 23 ) ;
191186resolve ( ) ;
192- } ) ;
187+ } ) ) ;
193188
194189setTimeout ( fn , 20 ) ;
195190await promise ;
@@ -205,7 +200,7 @@ test('AbortSignal.timeout() does not prevent the signal from being collected', a
205200
206201await sleep ( 10 ) ;
207202globalThis . gc ( ) ;
208- strictEqual ( ref . deref ( ) , undefined ) ;
203+ assert . strictEqual ( ref . deref ( ) , undefined ) ;
209204} ) ;
210205
211206test ( 'AbortSignal with a timeout is not collected while there is an active listener' , async ( ) => {
@@ -220,14 +215,14 @@ test('AbortSignal with a timeout is not collected while there is an active liste
220215
221216await sleep ( 10 ) ;
222217globalThis . gc ( ) ;
223- notStrictEqual ( ref . deref ( ) , undefined ) ;
224- ok ( ref . deref ( ) instanceof AbortSignal ) ;
218+ assert . notStrictEqual ( ref . deref ( ) , undefined ) ;
219+ assert . ok ( ref . deref ( ) instanceof AbortSignal ) ;
225220
226221ref . deref ( ) . removeEventListener ( 'abort' , handler ) ;
227222
228223await sleep ( 10 ) ;
229224globalThis . gc ( ) ;
230- strictEqual ( ref . deref ( ) , undefined ) ;
225+ assert . strictEqual ( ref . deref ( ) , undefined ) ;
231226} ) ;
232227
233228test ( 'Setting a long timeout should not keep the process open' , ( ) => {
@@ -237,18 +232,18 @@ test('Setting a long timeout should not keep the process open', () =>{
237232test ( 'AbortSignal.reason should default' , ( ) => {
238233// Test AbortSignal.reason default
239234const signal = AbortSignal . abort ( ) ;
240- ok ( signal . reason instanceof DOMException ) ;
241- strictEqual ( signal . reason . code , 20 ) ;
235+ assert . ok ( signal . reason instanceof DOMException ) ;
236+ assert . strictEqual ( signal . reason . code , 20 ) ;
242237
243238const ac = new AbortController ( ) ;
244239ac . abort ( ) ;
245- ok ( ac . signal . reason instanceof DOMException ) ;
246- strictEqual ( ac . signal . reason . code , 20 ) ;
240+ assert . ok ( ac . signal . reason instanceof DOMException ) ;
241+ assert . strictEqual ( ac . signal . reason . code , 20 ) ;
247242} ) ;
248243
249244test ( 'abortSignal.throwIfAborted() works as expected' , ( ) => {
250245// Test abortSignal.throwIfAborted()
251- throws ( ( ) => AbortSignal . abort ( ) . throwIfAborted ( ) , {
246+ assert . throws ( ( ) => AbortSignal . abort ( ) . throwIfAborted ( ) , {
252247code : 20 ,
253248name : 'AbortError' ,
254249} ) ;
@@ -262,7 +257,7 @@ test('abortSignal.throwIfAobrted() works as expected (2)', () =>{
262257const originalDesc = Reflect . getOwnPropertyDescriptor ( AbortSignal . prototype , 'aborted' ) ;
263258const actualReason = new Error ( ) ;
264259Reflect . defineProperty ( AbortSignal . prototype , 'aborted' , { value : false } ) ;
265- throws ( ( ) => AbortSignal . abort ( actualReason ) . throwIfAborted ( ) , actualReason ) ;
260+ assert . throws ( ( ) => AbortSignal . abort ( actualReason ) . throwIfAborted ( ) , actualReason ) ;
266261Reflect . defineProperty ( AbortSignal . prototype , 'aborted' , originalDesc ) ;
267262} ) ;
268263
@@ -271,6 +266,6 @@ test('abortSignal.throwIfAobrted() works as expected (3)', () =>{
271266const actualReason = new Error ( ) ;
272267const fakeExcuse = new Error ( ) ;
273268Reflect . defineProperty ( AbortSignal . prototype , 'reason' , { value : fakeExcuse } ) ;
274- throws ( ( ) => AbortSignal . abort ( actualReason ) . throwIfAborted ( ) , actualReason ) ;
269+ assert . throws ( ( ) => AbortSignal . abort ( actualReason ) . throwIfAborted ( ) , actualReason ) ;
275270Reflect . defineProperty ( AbortSignal . prototype , 'reason' , originalDesc ) ;
276271} ) ;
0 commit comments