aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/readline_promises.node.test.ts
diff options
context:
space:
mode:
authorGravatar Derrick Farris <mr.dcfarris@gmail.com> 2023-01-08 03:49:49 -0600
committerGravatar GitHub <noreply@github.com> 2023-01-08 01:49:49 -0800
commit94409770dece8bb9dfc23f4bdc2f240836035d87 (patch)
tree4cc627eb67c476871e84141a6c7a583e29e98309 /test/bun.js/readline_promises.node.test.ts
parentc505f172b84f5359aa186513f3ef7d6394bfc7b2 (diff)
downloadbun-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 '')
-rw-r--r--test/bun.js/readline_promises.node.test.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/bun.js/readline_promises.node.test.ts b/test/bun.js/readline_promises.node.test.ts
new file mode 100644
index 000000000..eadd289e3
--- /dev/null
+++ b/test/bun.js/readline_promises.node.test.ts
@@ -0,0 +1,55 @@
+import { describe, it } from "bun:test";
+import readlinePromises from "node:readline/promises";
+import { EventEmitter } from "node:events";
+import {
+ createDoneDotAll,
+ createCallCheckCtx,
+ assert,
+} from "./node-test-helpers";
+
+// ----------------------------------------------------------------------------
+// Helpers
+// ----------------------------------------------------------------------------
+
+class FakeInput extends EventEmitter {
+ output = "";
+ resume() {}
+ pause() {}
+ write(data) {
+ this.output += data;
+ }
+ end() {}
+ reset() {
+ this.output = "";
+ }
+}
+
+// ----------------------------------------------------------------------------
+// Tests
+// ----------------------------------------------------------------------------
+
+describe("readline/promises.createInterface()", () => {
+ it("should throw an error when failed completion", (done) => {
+ const createDone = createDoneDotAll(done);
+ const { mustCall, mustNotCall } = createCallCheckCtx(createDone());
+
+ const fi = new FakeInput();
+ const rli = new readlinePromises.Interface({
+ input: fi,
+ output: fi,
+ terminal: true,
+ completer: mustCall(() => Promise.reject(new Error("message"))),
+ });
+
+ rli.on("line", mustNotCall());
+ fi.emit("data", "\t");
+ const outCheckDone = createDone();
+ process.nextTick(() => {
+ console.log("output", fi.output);
+ assert.match(fi.output, /^Tab completion error/);
+ fi.reset();
+ outCheckDone();
+ });
+ rli.close();
+ });
+});