-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
500 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Minimal assert version to avoid dependecies on node internals | ||
// Allows to verify that none of brwoserify version of node internals is included in resulting build | ||
function deepStrictEqual(actual, expected, message) { | ||
const [actualType, expectedType] = [typeof actual, typeof expected]; | ||
const err = new Error(`Non-equal values: actual=${actual} (type=${actualType}) expected=${expected} (type=${expectedType})${message ? `. Message: ${message}` : ''}`); | ||
if (actualType !== expectedType) { | ||
throw err; | ||
} | ||
// Primitive types | ||
if (['string', 'number', 'bigint', 'undefined', 'boolean'].includes(actualType)) { | ||
if (actual !== expected) { | ||
throw err; | ||
} | ||
return; | ||
} | ||
if (actual instanceof Uint8Array && expected instanceof Uint8Array) { | ||
if (actual.length !== expected.length) { | ||
throw err; | ||
} | ||
for (let i = 0; i < actual.length; i++) { | ||
if (actual[i] !== expected[i]) { | ||
throw err; | ||
} | ||
} | ||
return; | ||
} | ||
if (Array.isArray(actual) && Array.isArray(expected)) { | ||
if (actual.length !== expected.length) { | ||
throw err; | ||
} | ||
for (let i = 0; i < actual.length; i++) { | ||
deepStrictEqual(actual[i], expected[i], message); | ||
} | ||
return; | ||
} | ||
if (actual === null && expected === null) { | ||
return; | ||
} | ||
if (actualType === 'object') { | ||
const [actualKeys, expectedKeys] = [ | ||
Object.keys(actual), | ||
Object.keys(expected), | ||
]; | ||
deepStrictEqual(actualKeys, expectedKeys, message); | ||
for (const key of actualKeys) { | ||
deepStrictEqual(actual[key], expected[key], message); | ||
} | ||
return; | ||
} | ||
throw err; | ||
} | ||
async function throws(cb) { | ||
try { | ||
cb(); | ||
} | ||
catch (e) { | ||
return; | ||
} | ||
throw new Error('Missing expected exception.'); | ||
} | ||
async function rejects(cb) { | ||
try { | ||
await cb(); | ||
} | ||
catch (e) { | ||
return; | ||
} | ||
throw new Error('Missing expected rejection.'); | ||
} | ||
// Run tests with node assert: | ||
// import { deepStrictEqual, throws } from "assert"; | ||
export { deepStrictEqual, throws, rejects }; |
Oops, something went wrong.