@inquirer/testing 0.0.5-alpha.0 → 0.1.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/LICENSE +22 -0
- package/dist/cjs/index.js +70 -0
- package/dist/esm/types/index.d.mts +11 -0
- package/package.json +37 -16
- /package/dist/{index.d.ts → cjs/types/index.d.mts} +0 -0
- /package/dist/{index.js → esm/index.mjs} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2022 Simon Boudrias
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,70 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.render = exports.log = void 0;
|
|
16
|
+
const mute_stream_1 = __importDefault(require("mute-stream"));
|
|
17
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
18
|
+
const node_stream_1 = require("node:stream");
|
|
19
|
+
const logStore = [];
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
logStore.length = 0;
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
logStore.forEach((...line) => console.log(...line));
|
|
25
|
+
});
|
|
26
|
+
function log(...line) {
|
|
27
|
+
logStore.push(line);
|
|
28
|
+
}
|
|
29
|
+
exports.log = log;
|
|
30
|
+
function render(prompt, props, options) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const input = new mute_stream_1.default();
|
|
33
|
+
const buffer = [];
|
|
34
|
+
const data = [];
|
|
35
|
+
const output = new node_stream_1.Stream.Writable({
|
|
36
|
+
write(chunk, _encoding, next) {
|
|
37
|
+
buffer.push(chunk.toString());
|
|
38
|
+
next();
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const processScreen = () => {
|
|
42
|
+
if (buffer.length > 0) {
|
|
43
|
+
const prevScreen = buffer.join('');
|
|
44
|
+
data.push((0, strip_ansi_1.default)(prevScreen));
|
|
45
|
+
buffer.length = 0;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const answer = prompt(props, Object.assign({ input, output }, options));
|
|
49
|
+
// Wait for event listeners to be ready
|
|
50
|
+
yield Promise.resolve();
|
|
51
|
+
yield Promise.resolve();
|
|
52
|
+
const events = {
|
|
53
|
+
keypress(name) {
|
|
54
|
+
processScreen();
|
|
55
|
+
input.emit('keypress', null, { name });
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
answer,
|
|
60
|
+
input,
|
|
61
|
+
events,
|
|
62
|
+
getScreen() {
|
|
63
|
+
var _a;
|
|
64
|
+
processScreen();
|
|
65
|
+
return (_a = data[data.length - 1]) !== null && _a !== void 0 ? _a : '';
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.render = render;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import MuteStream from 'mute-stream';
|
|
2
|
+
import type { Prompt } from '@inquirer/type';
|
|
3
|
+
export declare function log(...line: Parameters<typeof console.log>): void;
|
|
4
|
+
export declare function render<TestedPrompt extends Prompt<any, any>>(prompt: TestedPrompt, props: Parameters<TestedPrompt>[0], options?: Parameters<TestedPrompt>[1]): Promise<{
|
|
5
|
+
answer: Promise<any>;
|
|
6
|
+
input: MuteStream;
|
|
7
|
+
events: {
|
|
8
|
+
keypress(name: string): void;
|
|
9
|
+
};
|
|
10
|
+
getScreen(): string;
|
|
11
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/testing",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=14.18.0"
|
|
6
|
+
},
|
|
5
7
|
"description": "Inquirer testing utilities",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"typings": "dist/index.d.
|
|
8
|
+
"main": "./dist/cjs/index.js",
|
|
9
|
+
"typings": "./dist/cjs/types/index.d.mts",
|
|
8
10
|
"files": [
|
|
9
|
-
"dist
|
|
11
|
+
"dist/**/*"
|
|
10
12
|
],
|
|
11
|
-
"repository":
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
16
|
+
},
|
|
12
17
|
"keywords": [
|
|
13
18
|
"answer",
|
|
14
19
|
"answers",
|
|
15
20
|
"ask",
|
|
16
21
|
"base",
|
|
17
22
|
"cli",
|
|
18
|
-
"cli",
|
|
19
23
|
"command",
|
|
20
24
|
"command-line",
|
|
21
25
|
"confirm",
|
|
@@ -43,24 +47,41 @@
|
|
|
43
47
|
"stdin",
|
|
44
48
|
"stdout",
|
|
45
49
|
"terminal",
|
|
46
|
-
"test",
|
|
47
|
-
"testing",
|
|
48
50
|
"tty",
|
|
49
51
|
"ui",
|
|
50
|
-
"unit-test",
|
|
51
52
|
"yeoman",
|
|
52
53
|
"yo",
|
|
53
|
-
"zsh"
|
|
54
|
+
"zsh",
|
|
55
|
+
"test",
|
|
56
|
+
"testing",
|
|
57
|
+
"unit-test"
|
|
54
58
|
],
|
|
55
|
-
"author": "Simon Boudrias",
|
|
59
|
+
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
|
56
60
|
"license": "MIT",
|
|
57
61
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/testing/README.md",
|
|
58
62
|
"dependencies": {
|
|
59
|
-
"@inquirer/type": "^0.
|
|
60
|
-
"mute-stream": "^0.0
|
|
63
|
+
"@inquirer/type": "^0.1.0",
|
|
64
|
+
"mute-stream": "^1.0.0",
|
|
61
65
|
"strip-ansi": "^7.0.1"
|
|
62
66
|
},
|
|
63
67
|
"scripts": {
|
|
64
|
-
"tsc": "tsc"
|
|
65
|
-
|
|
68
|
+
"tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
|
|
69
|
+
"clean": "rm -rf dist",
|
|
70
|
+
"tsc:esm": "tsc -p ./tsconfig.esm.json",
|
|
71
|
+
"tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
|
|
72
|
+
"fix-ext": "ts-node ../../tools/rename-ext.ts"
|
|
73
|
+
},
|
|
74
|
+
"exports": {
|
|
75
|
+
".": {
|
|
76
|
+
"import": {
|
|
77
|
+
"types": "./dist/esm/types/index.d.mts",
|
|
78
|
+
"default": "./dist/esm/index.mjs"
|
|
79
|
+
},
|
|
80
|
+
"require": {
|
|
81
|
+
"types": "./dist/cjs/types/index.d.mts",
|
|
82
|
+
"default": "./dist/cjs/index.js"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"gitHead": "bd58130dd8204945a31b062070b829003b8385fc"
|
|
66
87
|
}
|
|
File without changes
|
|
File without changes
|