inquirerer 4.7.0 → 4.8.1
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/README.md +46 -0
- package/commander.js +12 -2
- package/esm/commander.js +12 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ npm install inquirerer
|
|
|
73
73
|
- [Progress Bar](#progress-bar)
|
|
74
74
|
- [Streaming Text](#streaming-text)
|
|
75
75
|
- [Custom UI with UIEngine](#custom-ui-with-uiengine)
|
|
76
|
+
- [Testing](#testing)
|
|
76
77
|
- [Developing](#developing)
|
|
77
78
|
|
|
78
79
|
## Quick Start
|
|
@@ -1642,6 +1643,51 @@ await engine.run({
|
|
|
1642
1643
|
});
|
|
1643
1644
|
```
|
|
1644
1645
|
|
|
1646
|
+
## Testing
|
|
1647
|
+
|
|
1648
|
+
For testing CLI applications built with `inquirerer`, use the companion
|
|
1649
|
+
package [`@inquirerer/test`](https://www.npmjs.com/package/@inquirerer/test)
|
|
1650
|
+
(also in this repo). It provides everything you need to mock stdin/stdout,
|
|
1651
|
+
queue keypresses and readline responses, capture and snapshot output, and
|
|
1652
|
+
even drive the built executable as a subprocess for end-to-end tests —
|
|
1653
|
+
without you having to hand-roll any of that scaffolding.
|
|
1654
|
+
|
|
1655
|
+
```bash
|
|
1656
|
+
npm install --save-dev @inquirerer/test
|
|
1657
|
+
```
|
|
1658
|
+
|
|
1659
|
+
**In-process testing** (mock streams):
|
|
1660
|
+
|
|
1661
|
+
```typescript
|
|
1662
|
+
import { createTestEnvironment, KEY_SEQUENCES } from '@inquirerer/test';
|
|
1663
|
+
import { Inquirerer } from 'inquirerer';
|
|
1664
|
+
|
|
1665
|
+
const env = createTestEnvironment();
|
|
1666
|
+
env.sendKey(KEY_SEQUENCES.ENTER);
|
|
1667
|
+
|
|
1668
|
+
const prompter = new Inquirerer(env.options);
|
|
1669
|
+
const result = await prompter.prompt({}, [
|
|
1670
|
+
{ name: 'confirm', type: 'confirm', message: 'Continue?' }
|
|
1671
|
+
]);
|
|
1672
|
+
|
|
1673
|
+
expect(result.confirm).toBe(true);
|
|
1674
|
+
expect(env.getOutput()).toContain('Continue?');
|
|
1675
|
+
```
|
|
1676
|
+
|
|
1677
|
+
**Subprocess (E2E) testing** — drive the actual built CLI:
|
|
1678
|
+
|
|
1679
|
+
```typescript
|
|
1680
|
+
import { runCli } from '@inquirerer/test';
|
|
1681
|
+
|
|
1682
|
+
const { stdout, exitCode } = await runCli('node', [CLI_ENTRY, 'search', 'hello']);
|
|
1683
|
+
expect(exitCode).toBe(0);
|
|
1684
|
+
expect(stdout).toContain('1 result');
|
|
1685
|
+
```
|
|
1686
|
+
|
|
1687
|
+
See the [@inquirerer/test README](https://github.com/constructive-io/dev-utils/tree/main/packages/inquirerer-test#readme) for the full API, including `createTestFixture` (temp-dir + commands runner), key-sequence constants, and snapshot normalisers.
|
|
1688
|
+
|
|
1689
|
+
## Developing
|
|
1690
|
+
|
|
1645
1691
|
**Run the demos:**
|
|
1646
1692
|
|
|
1647
1693
|
```bash
|
package/commander.js
CHANGED
|
@@ -8,11 +8,21 @@ const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
|
8
8
|
const minimist_1 = __importDefault(require("minimist"));
|
|
9
9
|
const prompt_1 = require("./prompt");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
+
// NOTE: `input` and `output` are lazy getters rather than plain properties.
|
|
12
|
+
// `process.stdin` / `process.stdout` are Node getters that lazy-construct
|
|
13
|
+
// streams on first access. When fd 0 is a pipe (e.g. a Jest worker or any
|
|
14
|
+
// spawned child), constructing stdin registers a libuv PIPEWRAP handle
|
|
15
|
+
// that the runtime must close before the process can exit. Evaluating
|
|
16
|
+
// these defaults eagerly as object properties meant that merely
|
|
17
|
+
// `require('inquirerer')` — even via a transitive dep that never
|
|
18
|
+
// constructs `CLI` — would open stdin and produce a spurious open-handle
|
|
19
|
+
// warning under `jest --detectOpenHandles`. Deferring the access to
|
|
20
|
+
// read-time keeps the module side-effect free.
|
|
11
21
|
exports.defaultCLIOptions = {
|
|
12
22
|
version: `inquirerer@${(0, utils_1.getVersion)()}`,
|
|
13
23
|
noTty: false,
|
|
14
|
-
input
|
|
15
|
-
output
|
|
24
|
+
get input() { return process.stdin; },
|
|
25
|
+
get output() { return process.stdout; },
|
|
16
26
|
minimistOpts: {
|
|
17
27
|
alias: {
|
|
18
28
|
v: 'version'
|
package/esm/commander.js
CHANGED
|
@@ -2,11 +2,21 @@ import deepmerge from 'deepmerge';
|
|
|
2
2
|
import minimist from 'minimist';
|
|
3
3
|
import { Inquirerer } from './prompt';
|
|
4
4
|
import { getVersion } from './utils';
|
|
5
|
+
// NOTE: `input` and `output` are lazy getters rather than plain properties.
|
|
6
|
+
// `process.stdin` / `process.stdout` are Node getters that lazy-construct
|
|
7
|
+
// streams on first access. When fd 0 is a pipe (e.g. a Jest worker or any
|
|
8
|
+
// spawned child), constructing stdin registers a libuv PIPEWRAP handle
|
|
9
|
+
// that the runtime must close before the process can exit. Evaluating
|
|
10
|
+
// these defaults eagerly as object properties meant that merely
|
|
11
|
+
// `require('inquirerer')` — even via a transitive dep that never
|
|
12
|
+
// constructs `CLI` — would open stdin and produce a spurious open-handle
|
|
13
|
+
// warning under `jest --detectOpenHandles`. Deferring the access to
|
|
14
|
+
// read-time keeps the module side-effect free.
|
|
5
15
|
export const defaultCLIOptions = {
|
|
6
16
|
version: `inquirerer@${getVersion()}`,
|
|
7
17
|
noTty: false,
|
|
8
|
-
input
|
|
9
|
-
output
|
|
18
|
+
get input() { return process.stdin; },
|
|
19
|
+
get output() { return process.stdout; },
|
|
10
20
|
minimistOpts: {
|
|
11
21
|
alias: {
|
|
12
22
|
v: 'version'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "TypeScript-first library for building beautiful CLI interfaces with interactive prompts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"makage": "0.1.10",
|
|
47
47
|
"string-width": "4.2.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "ea7144ba7becb4bcabfc5044214eafe25b24b876"
|
|
50
50
|
}
|