1// Block scoped definitions work poorly for global variables, temporarily enable var 2/* eslint-disable no-var */ 3 4// this will work in the browser via browserify 5declare var assert: typeof _chai.assert; 6declare var expect: typeof _chai.expect; 7var _chai: typeof import("chai") = require("chai"); 8globalThis.assert = _chai.assert; 9{ 10 // chai's builtin `assert.isFalse` is featureful but slow - we don't use those features, 11 // so we'll just overwrite it as an alterative to migrating a bunch of code off of chai 12 assert.isFalse = (expr: any, msg: string) => { 13 if (expr !== false) throw new Error(msg); 14 }; 15 16 const assertDeepImpl = assert.deepEqual; 17 assert.deepEqual = (a, b, msg) => { 18 if (ts.isArray(a) && ts.isArray(b)) { 19 assertDeepImpl(arrayExtraKeysObject(a), arrayExtraKeysObject(b), "Array extra keys differ"); 20 } 21 assertDeepImpl(a, b, msg); 22 23 function arrayExtraKeysObject(a: readonly unknown[]): object { 24 const obj: { [key: string]: unknown } = {}; 25 for (const key in a) { 26 if (Number.isNaN(Number(key))) { 27 obj[key] = a[key]; 28 } 29 } 30 return obj; 31 } 32 }; 33} 34globalThis.expect = _chai.expect; 35/* eslint-enable no-var */ 36// empty ts namespace so this file is included in the `ts.ts` namespace file generated by the module swapover 37// This way, everything that ends up importing `ts` downstream also imports this file and picks up its augmentation 38namespace ts {}