@inquirer/testing 0.0.5-alpha.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/index.d.ts +11 -0
- package/dist/index.js +50 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -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/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import MuteStream from 'mute-stream';
|
|
2
|
+
import stripAnsi from 'strip-ansi';
|
|
3
|
+
import { Stream } from 'node:stream';
|
|
4
|
+
const logStore = [];
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
logStore.length = 0;
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
logStore.forEach((...line) => console.log(...line));
|
|
10
|
+
});
|
|
11
|
+
export function log(...line) {
|
|
12
|
+
logStore.push(line);
|
|
13
|
+
}
|
|
14
|
+
export async function render(prompt, props, options) {
|
|
15
|
+
const input = new MuteStream();
|
|
16
|
+
const buffer = [];
|
|
17
|
+
const data = [];
|
|
18
|
+
const output = new Stream.Writable({
|
|
19
|
+
write(chunk, _encoding, next) {
|
|
20
|
+
buffer.push(chunk.toString());
|
|
21
|
+
next();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const processScreen = () => {
|
|
25
|
+
if (buffer.length > 0) {
|
|
26
|
+
const prevScreen = buffer.join('');
|
|
27
|
+
data.push(stripAnsi(prevScreen));
|
|
28
|
+
buffer.length = 0;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const answer = prompt(props, { input, output, ...options });
|
|
32
|
+
// Wait for event listeners to be ready
|
|
33
|
+
await Promise.resolve();
|
|
34
|
+
await Promise.resolve();
|
|
35
|
+
const events = {
|
|
36
|
+
keypress(name) {
|
|
37
|
+
processScreen();
|
|
38
|
+
input.emit('keypress', null, { name });
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
answer,
|
|
43
|
+
input,
|
|
44
|
+
events,
|
|
45
|
+
getScreen() {
|
|
46
|
+
processScreen();
|
|
47
|
+
return data[data.length - 1] ?? '';
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inquirer/testing",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.5-alpha.0",
|
|
5
|
+
"description": "Inquirer testing utilities",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/"
|
|
10
|
+
],
|
|
11
|
+
"repository": "SBoudrias/Inquirer.js",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"answer",
|
|
14
|
+
"answers",
|
|
15
|
+
"ask",
|
|
16
|
+
"base",
|
|
17
|
+
"cli",
|
|
18
|
+
"cli",
|
|
19
|
+
"command",
|
|
20
|
+
"command-line",
|
|
21
|
+
"confirm",
|
|
22
|
+
"enquirer",
|
|
23
|
+
"generate",
|
|
24
|
+
"generator",
|
|
25
|
+
"hyper",
|
|
26
|
+
"input",
|
|
27
|
+
"inquire",
|
|
28
|
+
"inquirer",
|
|
29
|
+
"interface",
|
|
30
|
+
"iterm",
|
|
31
|
+
"javascript",
|
|
32
|
+
"menu",
|
|
33
|
+
"node",
|
|
34
|
+
"nodejs",
|
|
35
|
+
"prompt",
|
|
36
|
+
"promptly",
|
|
37
|
+
"prompts",
|
|
38
|
+
"question",
|
|
39
|
+
"readline",
|
|
40
|
+
"scaffold",
|
|
41
|
+
"scaffolder",
|
|
42
|
+
"scaffolding",
|
|
43
|
+
"stdin",
|
|
44
|
+
"stdout",
|
|
45
|
+
"terminal",
|
|
46
|
+
"test",
|
|
47
|
+
"testing",
|
|
48
|
+
"tty",
|
|
49
|
+
"ui",
|
|
50
|
+
"unit-test",
|
|
51
|
+
"yeoman",
|
|
52
|
+
"yo",
|
|
53
|
+
"zsh"
|
|
54
|
+
],
|
|
55
|
+
"author": "Simon Boudrias",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/testing/README.md",
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@inquirer/type": "^0.0.4-alpha.0",
|
|
60
|
+
"mute-stream": "^0.0.8",
|
|
61
|
+
"strip-ansi": "^7.0.1"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"tsc": "tsc"
|
|
65
|
+
}
|
|
66
|
+
}
|