@inquirer/testing 2.1.34 → 2.1.36
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/commonjs/index.js +77 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/package.json +3 -0
- package/package.json +52 -34
- package/dist/cjs/index.js +0 -104
- package/dist/types/index.d.ts +0 -19
- /package/dist/{cjs/types → commonjs}/index.d.ts +0 -0
- /package/dist/esm/{types/index.d.mts → index.d.ts} +0 -0
- /package/dist/esm/{index.mjs → index.js} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.render = render;
|
|
7
|
+
const node_stream_1 = require("node:stream");
|
|
8
|
+
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
9
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
10
|
+
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
11
|
+
const ignoredAnsi = new Set([ansi_escapes_1.default.cursorHide, ansi_escapes_1.default.cursorShow]);
|
|
12
|
+
class BufferedStream extends node_stream_1.Stream.Writable {
|
|
13
|
+
#_fullOutput = '';
|
|
14
|
+
#_chunks = [];
|
|
15
|
+
#_rawChunks = [];
|
|
16
|
+
_write(chunk, _encoding, callback) {
|
|
17
|
+
const str = chunk.toString();
|
|
18
|
+
this.#_fullOutput += str;
|
|
19
|
+
// There's some ANSI Inquirer just send to keep state of the terminal clear; we'll ignore those since they're
|
|
20
|
+
// unlikely to be used by end users or part of prompt code.
|
|
21
|
+
if (!ignoredAnsi.has(str)) {
|
|
22
|
+
this.#_rawChunks.push(str);
|
|
23
|
+
}
|
|
24
|
+
// Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
|
|
25
|
+
// This is probably fine since we don't care about those for testing; but this could become
|
|
26
|
+
// an issue if we ever want to test for those.
|
|
27
|
+
if ((0, strip_ansi_1.default)(str).trim().length > 0) {
|
|
28
|
+
this.#_chunks.push(str);
|
|
29
|
+
}
|
|
30
|
+
callback();
|
|
31
|
+
}
|
|
32
|
+
getLastChunk({ raw }) {
|
|
33
|
+
const chunks = raw ? this.#_rawChunks : this.#_chunks;
|
|
34
|
+
const lastChunk = chunks.at(-1);
|
|
35
|
+
return lastChunk ?? '';
|
|
36
|
+
}
|
|
37
|
+
getFullOutput() {
|
|
38
|
+
return this.#_fullOutput;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function render(prompt, props, options) {
|
|
42
|
+
const input = new mute_stream_1.default();
|
|
43
|
+
input.unmute();
|
|
44
|
+
const output = new BufferedStream();
|
|
45
|
+
const answer = prompt(props, { input, output, ...options });
|
|
46
|
+
// Wait for event listeners to be ready
|
|
47
|
+
await Promise.resolve();
|
|
48
|
+
await Promise.resolve();
|
|
49
|
+
const events = {
|
|
50
|
+
keypress(key) {
|
|
51
|
+
if (typeof key === 'string') {
|
|
52
|
+
input.emit('keypress', null, { name: key });
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
input.emit('keypress', null, key);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
type(text) {
|
|
59
|
+
input.write(text);
|
|
60
|
+
for (const char of text) {
|
|
61
|
+
input.emit('keypress', null, { name: char });
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
answer,
|
|
67
|
+
input,
|
|
68
|
+
events,
|
|
69
|
+
getScreen: ({ raw } = {}) => {
|
|
70
|
+
const lastScreen = output.getLastChunk({ raw });
|
|
71
|
+
return raw ? lastScreen : (0, strip_ansi_1.default)(lastScreen).trim();
|
|
72
|
+
},
|
|
73
|
+
getFullOutput: () => {
|
|
74
|
+
return output.getFullOutput();
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/testing",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">=18"
|
|
6
|
-
},
|
|
3
|
+
"version": "2.1.36",
|
|
7
4
|
"description": "Inquirer testing utilities",
|
|
8
|
-
"main": "./dist/cjs/index.js",
|
|
9
|
-
"typings": "./dist/cjs/types/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"dist/**/*"
|
|
12
|
-
],
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
16
|
-
},
|
|
17
5
|
"keywords": [
|
|
18
6
|
"answer",
|
|
19
7
|
"answers",
|
|
@@ -56,35 +44,65 @@
|
|
|
56
44
|
"testing",
|
|
57
45
|
"unit-test"
|
|
58
46
|
],
|
|
59
|
-
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
60
|
-
"license": "MIT",
|
|
61
47
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/testing/README.md",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"@types/node": "^22.5.5",
|
|
66
|
-
"ansi-escapes": "^4.3.2",
|
|
67
|
-
"mute-stream": "^1.0.0",
|
|
68
|
-
"strip-ansi": "^6.0.1"
|
|
69
|
-
},
|
|
70
|
-
"scripts": {
|
|
71
|
-
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
72
|
-
"tsc:esm": "rm -rf dist/esm && tsc -p ./tsconfig.json",
|
|
73
|
-
"tsc:cjs": "rm -rf dist/cjs && tsc -p ./tsconfig.cjs.json && node ../../tools/fix-ext.mjs",
|
|
74
|
-
"attw": "attw --pack"
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
75
51
|
},
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
54
|
+
"sideEffects": false,
|
|
55
|
+
"type": "module",
|
|
76
56
|
"exports": {
|
|
57
|
+
"./package.json": "./package.json",
|
|
77
58
|
".": {
|
|
78
59
|
"import": {
|
|
79
|
-
"types": "./dist/esm/
|
|
80
|
-
"default": "./dist/esm/index.
|
|
60
|
+
"types": "./dist/esm/index.d.ts",
|
|
61
|
+
"default": "./dist/esm/index.js"
|
|
81
62
|
},
|
|
82
63
|
"require": {
|
|
83
|
-
"types": "./dist/
|
|
84
|
-
"default": "./dist/
|
|
64
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
65
|
+
"default": "./dist/commonjs/index.js"
|
|
85
66
|
}
|
|
86
67
|
}
|
|
87
68
|
},
|
|
88
|
-
"
|
|
89
|
-
"
|
|
69
|
+
"main": "./dist/commonjs/index.js",
|
|
70
|
+
"module": "./dist/esm/index.js",
|
|
71
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
72
|
+
"files": [
|
|
73
|
+
"dist"
|
|
74
|
+
],
|
|
75
|
+
"scripts": {
|
|
76
|
+
"attw": "attw --pack",
|
|
77
|
+
"tsc": "tshy"
|
|
78
|
+
},
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"@inquirer/type": "^3.0.0",
|
|
81
|
+
"ansi-escapes": "^4.3.2",
|
|
82
|
+
"mute-stream": "^2.0.0",
|
|
83
|
+
"strip-ansi": "^6.0.1"
|
|
84
|
+
},
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@arethetypeswrong/cli": "^0.16.4",
|
|
87
|
+
"@repo/tsconfig": "workspace:*",
|
|
88
|
+
"@types/mute-stream": "^0.0.4",
|
|
89
|
+
"@types/node": "^22.8.0",
|
|
90
|
+
"tshy": "^3.0.2"
|
|
91
|
+
},
|
|
92
|
+
"engines": {
|
|
93
|
+
"node": ">=18"
|
|
94
|
+
},
|
|
95
|
+
"tshy": {
|
|
96
|
+
"exclude": [
|
|
97
|
+
"src/**/*.test.ts"
|
|
98
|
+
],
|
|
99
|
+
"exports": {
|
|
100
|
+
"./package.json": "./package.json",
|
|
101
|
+
".": "./src/index.ts"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"peerDependencies": {
|
|
105
|
+
"@types/node": ">=18"
|
|
106
|
+
},
|
|
107
|
+
"gitHead": "da3dd749325495266025f2dbdb339a812da468f8"
|
|
90
108
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
-
};
|
|
16
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
20
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
var _BufferedStream__fullOutput, _BufferedStream__chunks, _BufferedStream__rawChunks;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.render = render;
|
|
28
|
-
const node_stream_1 = require("node:stream");
|
|
29
|
-
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
30
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
31
|
-
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
32
|
-
const ignoredAnsi = new Set([ansi_escapes_1.default.cursorHide, ansi_escapes_1.default.cursorShow]);
|
|
33
|
-
class BufferedStream extends node_stream_1.Stream.Writable {
|
|
34
|
-
constructor() {
|
|
35
|
-
super(...arguments);
|
|
36
|
-
_BufferedStream__fullOutput.set(this, '');
|
|
37
|
-
_BufferedStream__chunks.set(this, []);
|
|
38
|
-
_BufferedStream__rawChunks.set(this, []);
|
|
39
|
-
}
|
|
40
|
-
_write(chunk, _encoding, callback) {
|
|
41
|
-
const str = chunk.toString();
|
|
42
|
-
__classPrivateFieldSet(this, _BufferedStream__fullOutput, __classPrivateFieldGet(this, _BufferedStream__fullOutput, "f") + str, "f");
|
|
43
|
-
// There's some ANSI Inquirer just send to keep state of the terminal clear; we'll ignore those since they're
|
|
44
|
-
// unlikely to be used by end users or part of prompt code.
|
|
45
|
-
if (!ignoredAnsi.has(str)) {
|
|
46
|
-
__classPrivateFieldGet(this, _BufferedStream__rawChunks, "f").push(str);
|
|
47
|
-
}
|
|
48
|
-
// Stripping the ANSI codes here because Inquirer will push commands ANSI (like cursor move.)
|
|
49
|
-
// This is probably fine since we don't care about those for testing; but this could become
|
|
50
|
-
// an issue if we ever want to test for those.
|
|
51
|
-
if ((0, strip_ansi_1.default)(str).trim().length > 0) {
|
|
52
|
-
__classPrivateFieldGet(this, _BufferedStream__chunks, "f").push(str);
|
|
53
|
-
}
|
|
54
|
-
callback();
|
|
55
|
-
}
|
|
56
|
-
getLastChunk({ raw }) {
|
|
57
|
-
const chunks = raw ? __classPrivateFieldGet(this, _BufferedStream__rawChunks, "f") : __classPrivateFieldGet(this, _BufferedStream__chunks, "f");
|
|
58
|
-
const lastChunk = chunks.at(-1);
|
|
59
|
-
return lastChunk !== null && lastChunk !== void 0 ? lastChunk : '';
|
|
60
|
-
}
|
|
61
|
-
getFullOutput() {
|
|
62
|
-
return __classPrivateFieldGet(this, _BufferedStream__fullOutput, "f");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
_BufferedStream__fullOutput = new WeakMap(), _BufferedStream__chunks = new WeakMap(), _BufferedStream__rawChunks = new WeakMap();
|
|
66
|
-
function render(prompt, props, options) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const input = new mute_stream_1.default();
|
|
69
|
-
input.unmute();
|
|
70
|
-
const output = new BufferedStream();
|
|
71
|
-
const answer = prompt(props, Object.assign({ input, output }, options));
|
|
72
|
-
// Wait for event listeners to be ready
|
|
73
|
-
yield Promise.resolve();
|
|
74
|
-
yield Promise.resolve();
|
|
75
|
-
const events = {
|
|
76
|
-
keypress(key) {
|
|
77
|
-
if (typeof key === 'string') {
|
|
78
|
-
input.emit('keypress', null, { name: key });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
input.emit('keypress', null, key);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
type(text) {
|
|
85
|
-
input.write(text);
|
|
86
|
-
for (const char of text) {
|
|
87
|
-
input.emit('keypress', null, { name: char });
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
answer,
|
|
93
|
-
input,
|
|
94
|
-
events,
|
|
95
|
-
getScreen: ({ raw } = {}) => {
|
|
96
|
-
const lastScreen = output.getLastChunk({ raw });
|
|
97
|
-
return raw ? lastScreen : (0, strip_ansi_1.default)(lastScreen).trim();
|
|
98
|
-
},
|
|
99
|
-
getFullOutput: () => {
|
|
100
|
-
return output.getFullOutput();
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import MuteStream from 'mute-stream';
|
|
2
|
-
import type { Prompt } from '@inquirer/type';
|
|
3
|
-
export declare function render<TestedPrompt extends Prompt<unknown, unknown>>(prompt: TestedPrompt, props: Parameters<TestedPrompt>[0], options?: Parameters<TestedPrompt>[1]): Promise<{
|
|
4
|
-
answer: import("@inquirer/type").CancelablePromise<unknown>;
|
|
5
|
-
input: MuteStream;
|
|
6
|
-
events: {
|
|
7
|
-
keypress(key: string | {
|
|
8
|
-
name?: string | undefined;
|
|
9
|
-
ctrl?: boolean | undefined;
|
|
10
|
-
meta?: boolean | undefined;
|
|
11
|
-
shift?: boolean | undefined;
|
|
12
|
-
}): void;
|
|
13
|
-
type(text: string): void;
|
|
14
|
-
};
|
|
15
|
-
getScreen({ raw }?: {
|
|
16
|
-
raw?: boolean;
|
|
17
|
-
}): string;
|
|
18
|
-
getFullOutput(): string;
|
|
19
|
-
}>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|