@inquirer/testing 2.1.52 → 3.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.
@@ -0,0 +1,19 @@
1
+ import MuteStream from 'mute-stream';
2
+ import type { Prompt, Context } from '@inquirer/type';
3
+ export declare function render<const Props, const Value>(prompt: Prompt<Value, Props>, props: Props, options?: Context): Promise<{
4
+ answer: Promise<Value>;
5
+ input: MuteStream;
6
+ events: {
7
+ keypress: (key: string | {
8
+ name?: string;
9
+ ctrl?: boolean;
10
+ meta?: boolean;
11
+ shift?: boolean;
12
+ }) => void;
13
+ type: (text: string) => void;
14
+ };
15
+ getScreen: ({ raw }?: {
16
+ raw?: boolean;
17
+ }) => string;
18
+ getFullOutput: () => string;
19
+ }>;
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ import { Stream } from 'node:stream';
2
+ import { stripVTControlCharacters } from 'node:util';
3
+ import MuteStream from 'mute-stream';
4
+ class BufferedStream extends Stream.Writable {
5
+ #_fullOutput = '';
6
+ #_chunks = [];
7
+ #_rawChunks = [];
8
+ _write(chunk, _encoding, callback) {
9
+ const str = chunk.toString();
10
+ this.#_fullOutput += str;
11
+ // Keep track of every chunk send through.
12
+ this.#_rawChunks.push(str);
13
+ // Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
14
+ // This is probably fine since we don't care about those for testing; but this could become
15
+ // an issue if we ever want to test for those.
16
+ if (stripVTControlCharacters(str).trim().length > 0) {
17
+ this.#_chunks.push(str);
18
+ }
19
+ callback();
20
+ }
21
+ getLastChunk({ raw }) {
22
+ const chunks = raw ? this.#_rawChunks : this.#_chunks;
23
+ const lastChunk = chunks.at(-1);
24
+ return lastChunk ?? '';
25
+ }
26
+ getFullOutput() {
27
+ return this.#_fullOutput;
28
+ }
29
+ }
30
+ export async function render(prompt, props, options) {
31
+ const input = new MuteStream();
32
+ input.unmute();
33
+ const output = new BufferedStream();
34
+ const answer = prompt(props, { input, output, ...options });
35
+ // Wait for event listeners to be ready
36
+ await Promise.resolve();
37
+ await Promise.resolve();
38
+ const events = {
39
+ keypress(key) {
40
+ if (typeof key === 'string') {
41
+ input.emit('keypress', null, { name: key });
42
+ }
43
+ else {
44
+ input.emit('keypress', null, key);
45
+ }
46
+ },
47
+ type(text) {
48
+ input.write(text);
49
+ for (const char of text) {
50
+ input.emit('keypress', null, { name: char });
51
+ }
52
+ },
53
+ };
54
+ return {
55
+ answer,
56
+ input,
57
+ events,
58
+ getScreen: ({ raw } = {}) => {
59
+ const lastScreen = output.getLastChunk({ raw: Boolean(raw) });
60
+ return raw ? lastScreen : stripVTControlCharacters(lastScreen).trim();
61
+ },
62
+ getFullOutput: () => {
63
+ return output.getFullOutput();
64
+ },
65
+ };
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/testing",
3
- "version": "2.1.52",
3
+ "version": "3.0.0",
4
4
  "description": "Inquirer testing utilities",
5
5
  "keywords": [
6
6
  "answer",
@@ -55,49 +55,26 @@
55
55
  "type": "module",
56
56
  "exports": {
57
57
  "./package.json": "./package.json",
58
- ".": {
59
- "import": {
60
- "types": "./dist/esm/index.d.ts",
61
- "default": "./dist/esm/index.js"
62
- },
63
- "require": {
64
- "types": "./dist/commonjs/index.d.ts",
65
- "default": "./dist/commonjs/index.js"
66
- }
67
- }
58
+ ".": "./src/index.ts"
68
59
  },
69
- "main": "./dist/commonjs/index.js",
70
- "module": "./dist/esm/index.js",
71
- "types": "./dist/commonjs/index.d.ts",
72
60
  "files": [
73
61
  "dist"
74
62
  ],
75
63
  "scripts": {
76
- "attw": "attw --pack",
77
- "tsc": "tshy"
64
+ "tsc": "tsc"
78
65
  },
79
66
  "dependencies": {
80
- "@inquirer/type": "^3.0.10",
67
+ "@inquirer/type": "^4.0.0",
81
68
  "mute-stream": "^3.0.0"
82
69
  },
83
70
  "devDependencies": {
84
- "@arethetypeswrong/cli": "^0.18.2",
85
71
  "@repo/tsconfig": "0.0.0",
86
72
  "@types/mute-stream": "^0.0.4",
87
- "@types/node": "^24.10.0",
88
- "tshy": "^3.0.3"
73
+ "@types/node": "^24.10.1",
74
+ "typescript": "^5.9.3"
89
75
  },
90
76
  "engines": {
91
- "node": ">=18"
92
- },
93
- "tshy": {
94
- "exclude": [
95
- "src/**/*.test.ts"
96
- ],
97
- "exports": {
98
- "./package.json": "./package.json",
99
- ".": "./src/index.ts"
100
- }
77
+ "node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
101
78
  },
102
79
  "peerDependencies": {
103
80
  "@types/node": ">=18"
@@ -108,7 +85,14 @@
108
85
  }
109
86
  },
110
87
  "publishConfig": {
111
- "access": "public"
88
+ "access": "public",
89
+ "exports": {
90
+ "./package.json": "./package.json",
91
+ ".": {
92
+ "types": "./dist/index.d.ts",
93
+ "default": "./dist/index.js"
94
+ }
95
+ }
112
96
  },
113
- "gitHead": "6881993e517e76fa891b72e1f5086fd11f7676ac"
97
+ "gitHead": "676685d33374a30340c1b9f0831c7eae2b2357dd"
114
98
  }