@inquirer/testing 1.0.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -16,7 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
- var _BufferedStream__chunks;
19
+ var _BufferedStream__chunks, _BufferedStream__rawChunks;
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.render = void 0;
22
22
  const mute_stream_1 = __importDefault(require("mute-stream"));
@@ -26,9 +26,11 @@ class BufferedStream extends node_stream_1.Stream.Writable {
26
26
  constructor() {
27
27
  super(...arguments);
28
28
  _BufferedStream__chunks.set(this, []);
29
+ _BufferedStream__rawChunks.set(this, []);
29
30
  }
30
31
  _write(chunk, _encoding, callback) {
31
32
  const str = chunk.toString();
33
+ __classPrivateFieldGet(this, _BufferedStream__rawChunks, "f").push(chunk.toString());
32
34
  // Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
33
35
  // This is probably fine since we don't care about those for testing; but this could become
34
36
  // an issue if we ever want to test for those.
@@ -37,12 +39,13 @@ class BufferedStream extends node_stream_1.Stream.Writable {
37
39
  }
38
40
  callback();
39
41
  }
40
- getLastChunk() {
41
- const lastChunk = __classPrivateFieldGet(this, _BufferedStream__chunks, "f")[__classPrivateFieldGet(this, _BufferedStream__chunks, "f").length - 1];
42
+ getLastChunk({ raw }) {
43
+ const chunks = raw ? __classPrivateFieldGet(this, _BufferedStream__rawChunks, "f") : __classPrivateFieldGet(this, _BufferedStream__chunks, "f");
44
+ const lastChunk = chunks[chunks.length - 1];
42
45
  return lastChunk !== null && lastChunk !== void 0 ? lastChunk : '';
43
46
  }
44
47
  }
45
- _BufferedStream__chunks = new WeakMap();
48
+ _BufferedStream__chunks = new WeakMap(), _BufferedStream__rawChunks = new WeakMap();
46
49
  function render(prompt, props, options) {
47
50
  return __awaiter(this, void 0, void 0, function* () {
48
51
  const input = new mute_stream_1.default();
@@ -68,7 +71,7 @@ function render(prompt, props, options) {
68
71
  input,
69
72
  events,
70
73
  getScreen({ raw } = {}) {
71
- const lastScreen = output.getLastChunk();
74
+ const lastScreen = output.getLastChunk({ raw });
72
75
  return raw ? lastScreen : (0, strip_ansi_1.default)(lastScreen).trim();
73
76
  },
74
77
  };
@@ -1,7 +1,7 @@
1
1
  import MuteStream from 'mute-stream';
2
2
  import type { Prompt } from '@inquirer/type';
3
3
  export declare function render<TestedPrompt extends Prompt<any, any>>(prompt: TestedPrompt, props: Parameters<TestedPrompt>[0], options?: Parameters<TestedPrompt>[1]): Promise<{
4
- answer: Promise<any>;
4
+ answer: import("@inquirer/type").CancelablePromise<any>;
5
5
  input: MuteStream;
6
6
  events: {
7
7
  keypress(name: string): void;
@@ -3,8 +3,10 @@ import stripAnsi from 'strip-ansi';
3
3
  import { Stream } from 'node:stream';
4
4
  class BufferedStream extends Stream.Writable {
5
5
  #_chunks = [];
6
+ #_rawChunks = [];
6
7
  _write(chunk, _encoding, callback) {
7
8
  const str = chunk.toString();
9
+ this.#_rawChunks.push(chunk.toString());
8
10
  // Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
9
11
  // This is probably fine since we don't care about those for testing; but this could become
10
12
  // an issue if we ever want to test for those.
@@ -13,8 +15,9 @@ class BufferedStream extends Stream.Writable {
13
15
  }
14
16
  callback();
15
17
  }
16
- getLastChunk() {
17
- const lastChunk = this.#_chunks[this.#_chunks.length - 1];
18
+ getLastChunk({ raw }) {
19
+ const chunks = raw ? this.#_rawChunks : this.#_chunks;
20
+ const lastChunk = chunks[chunks.length - 1];
18
21
  return lastChunk ?? '';
19
22
  }
20
23
  }
@@ -42,7 +45,7 @@ export async function render(prompt, props, options) {
42
45
  input,
43
46
  events,
44
47
  getScreen({ raw } = {}) {
45
- const lastScreen = output.getLastChunk();
48
+ const lastScreen = output.getLastChunk({ raw });
46
49
  return raw ? lastScreen : stripAnsi(lastScreen).trim();
47
50
  },
48
51
  };
@@ -1,7 +1,7 @@
1
1
  import MuteStream from 'mute-stream';
2
2
  import type { Prompt } from '@inquirer/type';
3
3
  export declare function render<TestedPrompt extends Prompt<any, any>>(prompt: TestedPrompt, props: Parameters<TestedPrompt>[0], options?: Parameters<TestedPrompt>[1]): Promise<{
4
- answer: Promise<any>;
4
+ answer: import("@inquirer/type").CancelablePromise<any>;
5
5
  input: MuteStream;
6
6
  events: {
7
7
  keypress(name: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/testing",
3
- "version": "1.0.5",
3
+ "version": "2.0.0",
4
4
  "engines": {
5
5
  "node": ">=14.18.0"
6
6
  },
@@ -60,16 +60,16 @@
60
60
  "license": "MIT",
61
61
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/testing/README.md",
62
62
  "dependencies": {
63
- "@inquirer/type": "^1.0.4",
63
+ "@inquirer/type": "^1.1.0",
64
64
  "mute-stream": "^1.0.0",
65
65
  "strip-ansi": "^6.0.1"
66
66
  },
67
67
  "scripts": {
68
68
  "tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
69
69
  "clean": "rm -rf dist",
70
- "tsc:esm": "tsc -p ./tsconfig.esm.json",
70
+ "tsc:esm": "tsc -p ./tsconfig.json",
71
71
  "tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
72
- "fix-ext": "node --no-warnings=ExperimentalWarning --loader=ts-node/esm ../../tools/rename-ext.mts"
72
+ "fix-ext": "node --no-warnings=ExperimentalWarning --loader=ts-node/esm ../../tools/fix-ext.mts"
73
73
  },
74
74
  "exports": {
75
75
  ".": {
@@ -83,5 +83,5 @@
83
83
  }
84
84
  }
85
85
  },
86
- "gitHead": "4ade5f25d271c6f814efc7a21bdeb1a4d1ee6cf8"
86
+ "gitHead": "86531864067faf1d6e76f1581c9aa72cb1b03753"
87
87
  }