aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/readline_promises.node.test.ts
blob: 93093aecd0125e53f63e1742f789c6ec1e9f613b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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();
  });
});