1
- mocha . setup ( { ui : "bdd" , reporter : "spec" , retries : 5 } ) ;
1
+ import * as Mocha from "mocha" ;
2
+ import { expect } from "chai" ;
3
+
4
+ Mocha . setup ( 'bdd' ) ;
5
+ // @ts -ignore
6
+ Mocha . reporter ( 'spec' ) ;
7
+
8
+ declare const hostPlatform : string ;
9
+ declare const setExitCode : ( code : number ) => void ;
2
10
3
- const expect = chai . expect ;
4
11
5
12
describe ( "AbortController" , function ( ) {
6
13
it ( "should not throw while aborting with no callbacks" , function ( ) {
@@ -60,7 +67,7 @@ describe("AbortController", function () {
60
67
} ) ;
61
68
62
69
describe ( "XMLHTTPRequest" , function ( ) {
63
- function createRequest ( method , url , body , responseType ) {
70
+ function createRequest ( method : string , url : string , body : any = undefined , responseType : any = undefined ) : Promise < XMLHttpRequest > {
64
71
return new Promise ( ( resolve ) => {
65
72
const xhr = new XMLHttpRequest ( ) ;
66
73
xhr . open ( method , url ) ;
@@ -72,11 +79,11 @@ describe("XMLHTTPRequest", function () {
72
79
} ) ;
73
80
}
74
81
75
- function createRequestWithHeaders ( method , url , headers , body ) {
82
+ function createRequestWithHeaders ( method : string , url : string , headers : any , body ?: string ) : Promise < XMLHttpRequest > {
76
83
return new Promise ( ( resolve ) => {
77
84
const xhr = new XMLHttpRequest ( ) ;
78
85
xhr . open ( method , url ) ;
79
- headers . forEach ( ( value , key ) => xhr . setRequestHeader ( key , value ) ) ;
86
+ headers . forEach ( ( value : string , key : string ) => xhr . setRequestHeader ( key , value ) ) ;
80
87
xhr . addEventListener ( "loadend" , ( ) => resolve ( xhr ) ) ;
81
88
xhr . send ( body ) ;
82
89
} ) ;
@@ -199,7 +206,7 @@ describe("setTimeout", function () {
199
206
} ) ;
200
207
201
208
it ( "should return an id greater than zero when given an undefined function" , function ( ) {
202
- const id = setTimeout ( undefined , 0 ) ;
209
+ const id = setTimeout ( undefined as any , 0 ) ;
203
210
expect ( id ) . to . be . greaterThan ( 0 ) ;
204
211
} ) ;
205
212
@@ -241,13 +248,13 @@ describe("setTimeout", function () {
241
248
catch ( e ) {
242
249
done ( e ) ;
243
250
}
244
- } , "10" ) ;
251
+ } , "10" as any ) ;
245
252
} ) ;
246
253
247
254
it ( "should call the given function after zero milliseconds when the delay is a string representing an invalid number" , function ( done ) {
248
255
setTimeout ( ( ) => {
249
256
done ( ) ;
250
- } , "a" ) ;
257
+ } , "a" as any ) ;
251
258
} ) ;
252
259
253
260
it ( "should call the given function after other tasks execute when the given delay is zero" , function ( done ) {
@@ -416,7 +423,7 @@ if (hostPlatform !== "Unix") {
416
423
} ;
417
424
418
425
ws . onerror = ( ev ) => {
419
- done ( new Error ( ev . message ) ) ;
426
+ done ( new Error ( "WebSocket failed" ) ) ;
420
427
} ;
421
428
} ) ;
422
429
@@ -459,7 +466,7 @@ if (hostPlatform !== "Unix") {
459
466
} ;
460
467
461
468
ws2 . onerror = ( ev ) => {
462
- done ( new Error ( ev . message ) ) ;
469
+ done ( new Error ( String ( ev ) ) ) ;
463
470
} ;
464
471
}
465
472
@@ -484,7 +491,7 @@ if (hostPlatform !== "Unix") {
484
491
}
485
492
486
493
ws1 . onerror = ( ev ) => {
487
- done ( new Error ( ev . message ) ) ;
494
+ done ( new Error ( String ( ev ) ) ) ;
488
495
} ;
489
496
} ) ;
490
497
@@ -509,7 +516,15 @@ if (hostPlatform !== "Unix") {
509
516
describe ( "URL" , function ( ) {
510
517
511
518
// Currently all of the properties that the polyfill has implemented
512
- function checkURL ( url , { href, hostname, origin, pathname, search } ) {
519
+ interface URLCheckOptions {
520
+ href : string ;
521
+ hostname : string ;
522
+ origin : string ;
523
+ pathname : string ;
524
+ search : string ;
525
+ }
526
+
527
+ function checkURL ( url : URL , { href, hostname, origin, pathname, search } : URLCheckOptions ) : void {
513
528
expect ( url ) . to . have . property ( "hostname" , hostname ) ;
514
529
expect ( url ) . to . have . property ( "href" , href ) ;
515
530
expect ( url ) . to . have . property ( "origin" , origin ) ;
@@ -567,7 +582,7 @@ describe("URL", function () {
567
582
it ( "should update href after URLSearchParams are changed" , function ( ) {
568
583
// Augment URL with pathname and search
569
584
const url = new URL ( "https://httpbin.org/en-US/docs?foo=1&bar=2" ) ;
570
- url . searchParams . set ( "foo" , 999 ) ;
585
+ url . searchParams . set ( "foo" , 999 as any ) ;
571
586
// href should change to reflect searchParams change
572
587
checkURL ( url , {
573
588
href : "https://httpbin.org/en-US/docs?foo=999&bar=2" ,
@@ -581,7 +596,7 @@ describe("URL", function () {
581
596
it ( "should update href after URLSearchParams are changed (Starting with 0 params)" , function ( ) {
582
597
// Augment URL with pathname and search
583
598
const url = new URL ( "https://httpbin.org/en-US/docs" ) ;
584
- url . searchParams . set ( "foo" , 999 ) ;
599
+ url . searchParams . set ( "foo" , " 999" ) ;
585
600
// href should change to reflect searchParams change
586
601
checkURL ( url , {
587
602
href : "https://httpbin.org/en-US/docs?foo=999" ,
@@ -617,12 +632,14 @@ describe("URLSearchParams", function () {
617
632
const paramsSet = new URLSearchParams ( "" ) ;
618
633
619
634
it ( "should throw exception when trying to set with less than 2 parameters" , function ( ) {
635
+ // `set` expects parameters, none given.
636
+ // @ts -expect-error
620
637
expect ( ( ) => paramsSet . set ( ) ) . to . throw ( ) ;
621
638
} ) ;
622
639
623
640
it ( "should add a number and retrieve it as a string from searchParams" , function ( ) {
624
641
// Set Number
625
- paramsSet . set ( "foo" , 400 ) ;
642
+ paramsSet . set ( "foo" , 400 as any ) ;
626
643
expect ( paramsSet . get ( "foo" ) ) . to . equal ( "400" ) ;
627
644
} ) ;
628
645
@@ -634,13 +651,13 @@ describe("URLSearchParams", function () {
634
651
635
652
it ( "should add a boolean and retrieve it as a string from searchParams" , function ( ) {
636
653
// Set Boolean
637
- paramsSet . set ( "baz" , true ) ;
654
+ paramsSet . set ( "baz" , true as any ) ;
638
655
expect ( paramsSet . get ( "baz" ) ) . to . equal ( "true" ) ;
639
656
} ) ;
640
657
641
658
it ( "should set an existing number and retrieve it as a string from searchParams" , function ( ) {
642
659
// Set Existing Value
643
- paramsSet . set ( "foo" , 9999 ) ;
660
+ paramsSet . set ( "foo" , 9999 as any ) ;
644
661
expect ( paramsSet . get ( "foo" ) ) . to . equal ( "9999" ) ;
645
662
} ) ;
646
663
@@ -728,10 +745,10 @@ describe("Console", function () {
728
745
} ) ;
729
746
730
747
describe ( "Blob" , function ( ) {
731
- let emptyBlobs , helloBlobs , stringBlob , typedArrayBlob , arrayBufferBlob , blobBlob ;
748
+ let emptyBlobs : Blob [ ] , helloBlobs : Blob [ ] , stringBlob : Blob , typedArrayBlob : Blob , arrayBufferBlob : Blob , blobBlob : Blob ;
732
749
733
750
before ( function ( ) {
734
- emptyBlobs = [ new Blob ( ) , new Blob ( [ ] ) ] ;
751
+ emptyBlobs = [ new Blob ( [ ] ) , new Blob ( [ ] ) ] ;
735
752
stringBlob = new Blob ( [ "Hello" ] ) ;
736
753
typedArrayBlob = new Blob ( [ new Uint8Array ( [ 72 , 101 , 108 , 108 , 111 ] ) ] ) ,
737
754
arrayBufferBlob = new Blob ( [ new Uint8Array ( [ 72 , 101 , 108 , 108 , 111 ] ) . buffer ] ) ,
@@ -842,7 +859,7 @@ describe("Blob", function () {
842
859
} ) ;
843
860
844
861
function runTests ( ) {
845
- mocha . run ( failures => {
862
+ mocha . run ( ( failures : number ) => {
846
863
// Test program will wait for code to be set before exiting
847
864
if ( failures > 0 ) {
848
865
// Failure
0 commit comments