import { expect as expect_ } from "bun:test"; // @ts-ignore import { gcTick } from "gc"; import assertNode from "node:assert"; type DoneCb = (err?: Error) => any; function noop() {} const expect = (actual) => { gcTick(); const ret = expect_(actual); gcTick(); return ret; }; // Assert export const strictEqual = ( ...args: Parameters ) => { assertNode.strictEqual.apply(this, args); expect(true).toBe(true); }; export const notStrictEqual = ( ...args: Parameters ) => { assertNode.notStrictEqual.apply(this, args); expect(true).toBe(true); }; export const deepStrictEqual = ( ...args: Parameters ) => { assertNode.deepStrictEqual.apply(this, args); expect(true).toBe(true); }; export const throws = (...args: Parameters) => { assertNode.throws.apply(this, args); expect(true).toBe(true); }; export const ok = (...args: Parameters) => { assertNode.ok.apply(this, args); expect(true).toBe(true); }; export const ifError = (...args: Parameters) => { assertNode.ifError.apply(this, args); expect(true).toBe(true); }; export const match = (...args: Parameters) => { assertNode.match.apply(this, args); expect(true).toBe(true); }; export const assert = function (...args: any[]) { // @ts-ignore assertNode(...args); }; Object.assign(assert, { strictEqual, deepStrictEqual, notStrictEqual, throws, ok, ifError, match, }); // End assert export const createCallCheckCtx = (done: DoneCb) => { const createDone = createDoneDotAll(done); // const mustCallChecks = []; // failed.forEach(function (context) { // console.log( // "Mismatched %s function calls. Expected %s, actual %d.", // context.name, // context.messageSegment, // context.actual // ); // console.log(context.stack.split("\n").slice(2).join("\n")); // }); // TODO: Implement this to be exact only function mustCall(fn?: (...args) => any, exact?: number) { return mustCallAtLeast(fn, exact); } function mustNotCall( reason: string = "function should not have been called", ) { const localDone = createDone(); setTimeout(() => localDone(), 200); return () => { done(new Error(reason)); }; } function mustSucceed(fn: () => any, exact?: number) { return mustCall(function (err, ...args) { ifError(err); // @ts-ignore if (typeof fn === "function") return fn.apply(this, args as []); }, exact); } function mustCallAtLeast(fn, minimum) { return _mustCallInner(fn, minimum, "minimum"); } function _mustCallInner(fn, criteria = 1, field) { if (process._exiting) throw new Error("Cannot use common.mustCall*() in process exit handler"); if (typeof fn === "number") { criteria = fn; fn = noop; } else if (fn === undefined) { fn = noop; } if (typeof criteria !== "number") throw new TypeError(`Invalid ${field} value: ${criteria}`); let actual = 0; let expected = criteria; // mustCallChecks.push(context); const done = createDone(); const _return = (...args) => { // @ts-ignore const result = fn.apply(this, args); actual++; if (actual >= expected) { done(); } return result; }; // Function instances have own properties that may be relevant. // Let's replicate those properties to the returned function. // Refs: https://tc39.es/ecma262/#sec-function-instances Object.defineProperties(_return, { name: { value: fn.name, writable: false, enumerable: false, configurable: true, }, length: { value: fn.length, writable: false, enumerable: false, configurable: true, }, }); return _return; } return { mustSucceed, mustCall, mustCallAtLeast, mustNotCall, }; }; export function createDoneDotAll(done: DoneCb, globalTimeout?: number) { let toComplete = 0; let completed = 0; const globalTimer = globalTimeout ? setTimeout(() => { console.log("Global Timeout"); done(new Error("Timed out!")); }, globalTimeout) : undefined; function createDoneCb(timeout?: number) { toComplete += 1; const timer = timeout !== undefined ? setTimeout(() => { console.log("Timeout"); done(new Error("Timed out!")); }, timeout) : timeout; return (result?: Error) => { if (timer) clearTimeout(timer); if (globalTimer) clearTimeout(globalTimer); if (result instanceof Error) { done(result); return; } completed += 1; if (completed === toComplete) { done(); } }; } return createDoneCb; } stream'>eventstream Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-01-05Fix crash that sometimes happens after 30 secondsGravatar Jarred Sumner 5-106/+185
2022-01-05[bun bun][bun dev] Fix crash affecting large projectsGravatar Jarred Sumner 1-26/+119
2022-01-05move some code aroundGravatar Jarred Sumner 2-281/+284
2022-01-05we want the opposite of thisGravatar Jarred Sumner 1-1/+0
2022-01-05[JS Parser] Reduce memory usage by ~8%Gravatar Jarred Sumner 6-7/+42
2022-01-05minimal integration tests for macrosGravatar Jarred Sumner 4-0/+47
2022-01-05Update resolver.zigGravatar Jarred Sumner 1-3/+0
2022-01-05Update options.zigGravatar Jarred Sumner 1-2/+25
2022-01-05Update http.zigGravatar Jarred Sumner 1-1/+1
2022-01-05Add module condition to the node platform (#104)Gravatar Mateusz Burzyński 1-1/+4
2022-01-05Drop redundant comments (#103)Gravatar Mateusz Burzyński 1-23/+0
2022-01-05Tweak default main fields for the bun platform to match other popular bundler...Gravatar Mateusz Burzyński 1-10/+7
2022-01-04:skull: dead codeGravatar Jarred Sumner 1-13/+0
2022-01-04[bun dev] Print error in status line textGravatar Jarred Sumner 1-3/+13
2022-01-04noramlize some errorsGravatar Jarred Sumner 3-3/+4
2022-01-04[Bun.js][bun dev] Support macros inside of Bun.jsGravatar Jarred Sumner 5-51/+103
2022-01-04[bun bun] Fix error when regenerating node_modules.bun after moving itGravatar Jarred Sumner 1-1/+17
2022-01-04Improve how we detect if terminal colors are supportedGravatar Jarred Sumner 3-11/+66
2022-01-04Improve error handling when out of file handlesGravatar Jarred Sumner 5-58/+248
2022-01-04Update build-idGravatar Jarred Sumner 1-1/+1
2022-01-04Downgrade mimalloc due to crashesGravatar Jarred Sumner 1-0/+0
2022-01-04Upload compressed `.dSYM` for every releaseGravatar Jarred Sumner 2-4/+34
2022-01-04Update .gitignoreGravatar Jarred Sumner 1-0/+3
2022-01-04[bun install] Fix more cases where bytes are printed instead of stringsGravatar Jarred Sumner 1-10/+38
2022-01-04minor perf optimization: remove this loop on macOSGravatar Jarred Sumner 2-4/+8
2022-01-03Update crash_reporter_linux.zigbun-v0.0.66Gravatar Jarred Sumner 1-1/+1
2022-01-03:confused:Gravatar Jarred Sumner 5-0/+1
2022-01-03:nail_care:Gravatar Jarred Sumner 3-1652/+1826
2022-01-03Update crash_reporter_linux.zigGravatar Jarred Sumner 1-1/+1
2022-01-03Update PLCrashReport.mGravatar Jarred Sumner 1-1/+1
2022-01-03Update PLCrashReport.mGravatar Jarred Sumner 1-2/+1
2022-01-03:lock:Gravatar Jarred Sumner 4-1/+1
2022-01-03dead codeGravatar Jarred Sumner 13-1881/+1660