diff options
author | 2023-01-08 03:49:49 -0600 | |
---|---|---|
committer | 2023-01-08 01:49:49 -0800 | |
commit | 94409770dece8bb9dfc23f4bdc2f240836035d87 (patch) | |
tree | 4cc627eb67c476871e84141a6c7a583e29e98309 /test/bun.js/node-test-helpers.js | |
parent | c505f172b84f5359aa186513f3ef7d6394bfc7b2 (diff) | |
download | bun-94409770dece8bb9dfc23f4bdc2f240836035d87.tar.gz bun-94409770dece8bb9dfc23f4bdc2f240836035d87.tar.zst bun-94409770dece8bb9dfc23f4bdc2f240836035d87.zip |
feat(node:readline): add node:readline and node:readline/promises (#1738)
* feat(readline): WIP: add readline
* test(helpers): add deepStrictEqual helper
* feat(readline): add readline & readline/promises to loader
* fix(node:events): emit newListener on new listener added
* feat(readline): finish readline cb interface, add tests
* fix(stream): fix Transform.end()
* fix(node-test-helpers): correct throws behavior, improve how all asserts work
* feat(readline/promises): add readline/promises
* feat(assert): add assert.match
* test(readline): uncomment more tests
* fix(readline): MaxCeil -> MathCeil 🤦
* fix(readline): export promises from node:readline
* fix(readline): temp fix for circular dependency
* cleanup(readline): remove console.log
* fix(readline): change true -> 0 for CommonJS export
* perf(readline): micro-optimizations with some getters
* perf(readline): lazy load isWritable
* cleanup(readline): rename debug flag env var to BUN_JS_DEBUG
Diffstat (limited to 'test/bun.js/node-test-helpers.js')
-rw-r--r-- | test/bun.js/node-test-helpers.js | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/test/bun.js/node-test-helpers.js b/test/bun.js/node-test-helpers.js deleted file mode 100644 index f62f1ab3b..000000000 --- a/test/bun.js/node-test-helpers.js +++ /dev/null @@ -1,156 +0,0 @@ -import { expect as expect_ } from "bun:test"; -import { gcTick } from "gc"; -import assertNode from "node:assert"; - -const expect = (actual) => { - gcTick(); - const ret = expect_(actual); - gcTick(); - return ret; -}; - -export const strictEqual = (...args) => { - let error = null; - try { - assertNode.strictEqual(...args); - } catch (err) { - error = err; - } - expect(error).toBe(null); -}; - -export const throws = (...args) => { - let error = null; - try { - assertNode.throws(...args); - } catch (err) { - error = err; - } - expect(error).toBe(null); -}; - -export const assert = (...args) => { - let error = null; - try { - assertNode(...args); - } catch (err) { - error = err; - } - expect(error).toBe(null); -}; - -export const assertOk = (...args) => { - let error = null; - try { - assertNode.ok(...args); - } catch (err) { - error = err; - } - expect(error).toBe(null); -}; - -export const createCallCheckCtx = (done, timeout = 1500) => { - 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, exact) { - return mustCallAtLeast(fn, exact); - } - - function mustSucceed(fn, exact) { - return mustCall(function (err, ...args) { - assert.ifError(err); - if (typeof fn === "function") return fn.apply(this, args); - }, 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(timeout); - const _return = (...args) => { - 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, - }; -}; - -export function createDoneDotAll(done) { - let toComplete = 0; - let completed = 0; - function createDoneCb(timeout) { - toComplete += 1; - const timer = setTimeout(() => { - console.log("Timeout"); - done(new Error("Timed out!")); - }, timeout); - return (result) => { - clearTimeout(timer); - if (result instanceof Error) { - done(result); - return; - } - completed += 1; - if (completed === toComplete) { - done(); - } - }; - } - return createDoneCb; -} |