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 ;
210
3- const expect = chai . expect ;
411
512describe ( "AbortController" , function ( ) {
613 it ( "should not throw while aborting with no callbacks" , function ( ) {
@@ -60,7 +67,7 @@ describe("AbortController", function () {
6067} ) ;
6168
6269describe ( "XMLHTTPRequest" , function ( ) {
63- function createRequest ( method , url , body , responseType ) {
70+ function createRequest ( method : string , url : string , body : any = undefined , responseType : any = undefined ) : Promise < XMLHttpRequest > {
6471 return new Promise ( ( resolve ) => {
6572 const xhr = new XMLHttpRequest ( ) ;
6673 xhr . open ( method , url ) ;
@@ -72,11 +79,11 @@ describe("XMLHTTPRequest", function () {
7279 } ) ;
7380 }
7481
75- function createRequestWithHeaders ( method , url , headers , body ) {
82+ function createRequestWithHeaders ( method : string , url : string , headers : any , body ?: string ) : Promise < XMLHttpRequest > {
7683 return new Promise ( ( resolve ) => {
7784 const xhr = new XMLHttpRequest ( ) ;
7885 xhr . open ( method , url ) ;
79- headers . forEach ( ( value , key ) => xhr . setRequestHeader ( key , value ) ) ;
86+ headers . forEach ( ( value : string , key : string ) => xhr . setRequestHeader ( key , value ) ) ;
8087 xhr . addEventListener ( "loadend" , ( ) => resolve ( xhr ) ) ;
8188 xhr . send ( body ) ;
8289 } ) ;
@@ -199,7 +206,7 @@ describe("setTimeout", function () {
199206 } ) ;
200207
201208 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 ) ;
203210 expect ( id ) . to . be . greaterThan ( 0 ) ;
204211 } ) ;
205212
@@ -241,13 +248,13 @@ describe("setTimeout", function () {
241248 catch ( e ) {
242249 done ( e ) ;
243250 }
244- } , "10" ) ;
251+ } , "10" as any ) ;
245252 } ) ;
246253
247254 it ( "should call the given function after zero milliseconds when the delay is a string representing an invalid number" , function ( done ) {
248255 setTimeout ( ( ) => {
249256 done ( ) ;
250- } , "a" ) ;
257+ } , "a" as any ) ;
251258 } ) ;
252259
253260 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") {
416423 } ;
417424
418425 ws . onerror = ( ev ) => {
419- done ( new Error ( ev . message ) ) ;
426+ done ( new Error ( "WebSocket failed" ) ) ;
420427 } ;
421428 } ) ;
422429
@@ -459,7 +466,7 @@ if (hostPlatform !== "Unix") {
459466 } ;
460467
461468 ws2 . onerror = ( ev ) => {
462- done ( new Error ( ev . message ) ) ;
469+ done ( new Error ( String ( ev ) ) ) ;
463470 } ;
464471 }
465472
@@ -484,7 +491,7 @@ if (hostPlatform !== "Unix") {
484491 }
485492
486493 ws1 . onerror = ( ev ) => {
487- done ( new Error ( ev . message ) ) ;
494+ done ( new Error ( String ( ev ) ) ) ;
488495 } ;
489496 } ) ;
490497
@@ -509,7 +516,15 @@ if (hostPlatform !== "Unix") {
509516describe ( "URL" , function ( ) {
510517
511518 // 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 {
513528 expect ( url ) . to . have . property ( "hostname" , hostname ) ;
514529 expect ( url ) . to . have . property ( "href" , href ) ;
515530 expect ( url ) . to . have . property ( "origin" , origin ) ;
@@ -567,7 +582,7 @@ describe("URL", function () {
567582 it ( "should update href after URLSearchParams are changed" , function ( ) {
568583 // Augment URL with pathname and search
569584 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 ) ;
571586 // href should change to reflect searchParams change
572587 checkURL ( url , {
573588 href : "https://httpbin.org/en-US/docs?foo=999&bar=2" ,
@@ -581,7 +596,7 @@ describe("URL", function () {
581596 it ( "should update href after URLSearchParams are changed (Starting with 0 params)" , function ( ) {
582597 // Augment URL with pathname and search
583598 const url = new URL ( "https://httpbin.org/en-US/docs" ) ;
584- url . searchParams . set ( "foo" , 999 ) ;
599+ url . searchParams . set ( "foo" , " 999" ) ;
585600 // href should change to reflect searchParams change
586601 checkURL ( url , {
587602 href : "https://httpbin.org/en-US/docs?foo=999" ,
@@ -617,12 +632,14 @@ describe("URLSearchParams", function () {
617632 const paramsSet = new URLSearchParams ( "" ) ;
618633
619634 it ( "should throw exception when trying to set with less than 2 parameters" , function ( ) {
635+ // `set` expects parameters, none given.
636+ // @ts -expect-error
620637 expect ( ( ) => paramsSet . set ( ) ) . to . throw ( ) ;
621638 } ) ;
622639
623640 it ( "should add a number and retrieve it as a string from searchParams" , function ( ) {
624641 // Set Number
625- paramsSet . set ( "foo" , 400 ) ;
642+ paramsSet . set ( "foo" , 400 as any ) ;
626643 expect ( paramsSet . get ( "foo" ) ) . to . equal ( "400" ) ;
627644 } ) ;
628645
@@ -634,13 +651,13 @@ describe("URLSearchParams", function () {
634651
635652 it ( "should add a boolean and retrieve it as a string from searchParams" , function ( ) {
636653 // Set Boolean
637- paramsSet . set ( "baz" , true ) ;
654+ paramsSet . set ( "baz" , true as any ) ;
638655 expect ( paramsSet . get ( "baz" ) ) . to . equal ( "true" ) ;
639656 } ) ;
640657
641658 it ( "should set an existing number and retrieve it as a string from searchParams" , function ( ) {
642659 // Set Existing Value
643- paramsSet . set ( "foo" , 9999 ) ;
660+ paramsSet . set ( "foo" , 9999 as any ) ;
644661 expect ( paramsSet . get ( "foo" ) ) . to . equal ( "9999" ) ;
645662 } ) ;
646663
@@ -728,10 +745,10 @@ describe("Console", function () {
728745} ) ;
729746
730747describe ( "Blob" , function ( ) {
731- let emptyBlobs , helloBlobs , stringBlob , typedArrayBlob , arrayBufferBlob , blobBlob ;
748+ let emptyBlobs : Blob [ ] , helloBlobs : Blob [ ] , stringBlob : Blob , typedArrayBlob : Blob , arrayBufferBlob : Blob , blobBlob : Blob ;
732749
733750 before ( function ( ) {
734- emptyBlobs = [ new Blob ( ) , new Blob ( [ ] ) ] ;
751+ emptyBlobs = [ new Blob ( [ ] ) , new Blob ( [ ] ) ] ;
735752 stringBlob = new Blob ( [ "Hello" ] ) ;
736753 typedArrayBlob = new Blob ( [ new Uint8Array ( [ 72 , 101 , 108 , 108 , 111 ] ) ] ) ,
737754 arrayBufferBlob = new Blob ( [ new Uint8Array ( [ 72 , 101 , 108 , 108 , 111 ] ) . buffer ] ) ,
@@ -842,7 +859,7 @@ describe("Blob", function () {
842859} ) ;
843860
844861function runTests ( ) {
845- mocha . run ( failures => {
862+ mocha . run ( ( failures : number ) => {
846863 // Test program will wait for code to be set before exiting
847864 if ( failures > 0 ) {
848865 // Failure
0 commit comments