cliprobe 1.9.0 → 1.10.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/README.md +50 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +21 -3050
- package/dist/index.d.ts +323 -0
- package/dist/index.js +108 -0
- package/dist/report-DuFcZAqG.js +3137 -0
- package/package.json +10 -2
- package/schema.json +1 -1
package/README.md
CHANGED
|
@@ -96,6 +96,7 @@ The other checks cover the rest of what goes wrong between a program and the thi
|
|
|
96
96
|
- [Exit codes](#exit-codes)
|
|
97
97
|
- [In CI](#in-ci)
|
|
98
98
|
- [JSON output](#json-output)
|
|
99
|
+
- [In your test suite](#in-your-test-suite)
|
|
99
100
|
- [Stability](#stability)
|
|
100
101
|
- [Checks](#checks): [closed-pipe](#closed-pipe), [write-error](#write-error), [color](#color), [pipe-escapes](#pipe-escapes), [stdin](#stdin), [ctrl-c](#ctrl-c), [sigterm](#sigterm), [restore](#restore), [control-chars](#control-chars), [info checks](#info-checks)
|
|
101
102
|
- [Fixing a failure in a Node.js CLI](#fixing-a-failure-in-a-nodejs-cli)
|
|
@@ -115,7 +116,7 @@ Run it without installing:
|
|
|
115
116
|
npx cliprobe -- <command>
|
|
116
117
|
```
|
|
117
118
|
|
|
118
|
-
Or add it to a project, to run in CI against your own CLI:
|
|
119
|
+
Or add it to a project, to run in CI against your own CLI or [from its test suite](#in-your-test-suite):
|
|
119
120
|
|
|
120
121
|
```sh
|
|
121
122
|
npm install --save-dev cliprobe # or: pnpm add -D cliprobe
|
|
@@ -185,6 +186,7 @@ npx cliprobe # with no command, reads cliprobe.config.json from the current d
|
|
|
185
186
|
| `command` | The program, required. Unlike on the command line, everything in it belongs to the program, so with `node ./dist/cli.js` the probes are `--version`, `--help` and each of `probes`, all after the script |
|
|
186
187
|
| `probes` | More invocations, each the arguments after the program, as `--probe` |
|
|
187
188
|
| `bare` | `true` probes the program alone instead of `--version` and `--help`, as `--bare` |
|
|
189
|
+
| `defaultProbes` | `false` leaves out `--version` and `--help`, so only `probes` run |
|
|
188
190
|
| `checks`, `skip` | Arrays of check names, as `--check` and `--skip` |
|
|
189
191
|
| `strict`, `timeout` | As `--strict` and `--timeout` |
|
|
190
192
|
| `accept` | Failures and warnings the project knows about; see below |
|
|
@@ -260,7 +262,7 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
260
262
|
|
|
261
263
|
## JSON output
|
|
262
264
|
|
|
263
|
-
`--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json
|
|
265
|
+
`--format json` (or `--json`) writes one report, described by a JSON Schema that ships in the package as `cliprobe/schema.json`. [`probe()`](#in-your-test-suite) returns the same report as an object:
|
|
264
266
|
|
|
265
267
|
```json
|
|
266
268
|
{
|
|
@@ -292,6 +294,49 @@ In JUnit, each check is a test suite and each probe a test case: `FAIL` is a fai
|
|
|
292
294
|
|
|
293
295
|
`strict` says whether `--strict` was given (added in 1.1). Every result has the same five fields: `check`, `invocation` (the command and arguments that ran), `verdict` (`pass`, `fail`, `warn`, `skip`, `error` for could-not-run, or `info`), `reason` (a sentence for a person) and `details`, plus `evidence` when there is a line to quote and, since 1.8, `accepted` (an object with the `reason`) when the [config file accepts](#accepted-findings) the result; `summary` counts verdicts as before. `details` holds the check's own measurements, such as exit codes, timings, the terminal modes left on or the processes left running; the schema describes each check's. Text from the program under test is escaped: control characters, line separators and bidi overrides appear as `\u` escapes, so the report can't drive a terminal when printed. The human report shows them as `\x1b`-style escapes and doubles a backslash the program printed, so `\\x1b` is text and `\x1b` a real escape character; it cuts evidence longer than 200 characters, which the JSON has in full.
|
|
294
296
|
|
|
297
|
+
## In your test suite
|
|
298
|
+
|
|
299
|
+
cliprobe is also a library: `probe()` runs the checks and returns the report as an object, so your own tests can hold your CLI to them. It works with any test runner; with Vitest:
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
import { expect, test } from 'vitest';
|
|
303
|
+
import { failing, formatReport, probe } from 'cliprobe';
|
|
304
|
+
|
|
305
|
+
test('the CLI behaves in pipes, on Ctrl-C and on a full disk', async () => {
|
|
306
|
+
const report = await probe('node ./dist/cli.js', {
|
|
307
|
+
probes: ['serve --port 0', 'scan {fixture}'],
|
|
308
|
+
});
|
|
309
|
+
// On a failure, the message is the report a person would read.
|
|
310
|
+
expect(failing(report), formatReport(report)).toEqual([]);
|
|
311
|
+
}, 120_000);
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
`probe(command, options)` takes the program as the [config file](#config-file) does: `command` is all of it, script included, as a string or an array, and the options are the file's other keys (`probes`, `bare`, `defaultProbes`, `checks`, `skip`, `strict`, `timeout`, `accept`). It resolves to the same report as [`--format json`](#json-output), with TypeScript types: `result.check` narrows `result.details` to that check's fields.
|
|
315
|
+
|
|
316
|
+
| Export | What it does |
|
|
317
|
+
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
318
|
+
| `probe(command, options?)` | Runs the checks and resolves to the report. A check that fails is a result, never an exception |
|
|
319
|
+
| `failing(report)` | The results that fail the run: every `fail`, plus every `warn` with `strict`, except those `accept` covers |
|
|
320
|
+
| `exitCode(report)` | `0`, `1` or `2`, as the CLI would exit |
|
|
321
|
+
| `formatReport(report, format?)` | The report as text: `human` (default), `json`, `markdown`, `junit` or `github`, escaped as in the CLI. `{ color: true }` paints the verdicts |
|
|
322
|
+
| `readConfig(path?)` | Reads `cliprobe.config.json`, so a test probes exactly what `npx cliprobe` does: `const { command, ...options } = readConfig()` |
|
|
323
|
+
| `ProbeError` | What `probe()` rejects with when the run can't start; its `code` is `USAGE`, `COMMAND` or `PLATFORM` |
|
|
324
|
+
| `CHECK_NAMES`, `FORMAT_NAMES`, `version` | The check names in run order, the format names, and the cliprobe version |
|
|
325
|
+
|
|
326
|
+
To assert on one check, read the results; the verdict and the check name are stable, the wording of `reason` is not:
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
const report = await probe('node ./dist/cli.js', { checks: ['closed-pipe'] });
|
|
330
|
+
expect(report.results.map((r) => r.verdict)).toEqual(['pass', 'pass']);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
A few things to know:
|
|
334
|
+
|
|
335
|
+
- **Give the test time.** A probe that keeps running costs a few seconds in each check, so a full run takes from a few seconds to a minute or more. `checks` and `defaultProbes: false` keep a test to exactly what it asserts.
|
|
336
|
+
- **Run probes one after another.** The checks measure time, so several `probe()` calls at once on a busy machine can turn a slow answer into a wrong verdict.
|
|
337
|
+
- **It is the same run as the CLI.** The program starts in the current directory, without a shell, with a temporary `HOME` and [a minimal environment](#the-probes-environment), and anything it leaves running is killed. If the test process exits early, cliprobe kills the probe in progress and removes its temporary files on the way out.
|
|
338
|
+
- **Importing it does nothing.** No output, no signal handlers, no work until `probe()` is called. The package is ESM with types included and no dependencies; `require('cliprobe')` works too.
|
|
339
|
+
|
|
295
340
|
## Stability
|
|
296
341
|
|
|
297
342
|
From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x release:
|
|
@@ -300,6 +345,7 @@ From 1.0, cliprobe follows semantic versioning, and these hold for every 1.x rel
|
|
|
300
345
|
- **Names and exit codes.** Check names, verdicts, options, config file keys and exit codes stay as they are.
|
|
301
346
|
- **`--strict` opts out of the first promise.** It fails on warnings, so a new warning in a minor release can fail your build. Pin an exact version (`cliprobe@1.7.0`) if that matters, or `--skip` the check.
|
|
302
347
|
- **JSON.** `schemaVersion` stays `1`. Fields are only added, never removed, renamed or given a new type.
|
|
348
|
+
- **The API.** The functions `cliprobe` exports, their options and the report they return follow the same rules: they are only added to.
|
|
303
349
|
- **Not covered.** The wording of `reason` and `evidence`, and the human, Markdown and `github` output, are for people and may change. Match on `check` and `verdict`, not on text.
|
|
304
350
|
|
|
305
351
|
## Checks
|
|
@@ -580,6 +626,8 @@ The runs under a terminal are color's second and third, restore's, and control-c
|
|
|
580
626
|
|
|
581
627
|
**How do I stop repeating the probes in every command?** Put them in a [config file](#config-file): `cliprobe.config.json` holds the command, the probes and any findings you accept, and `npx cliprobe` runs it.
|
|
582
628
|
|
|
629
|
+
**Can I run it from my own tests?** Yes: [`probe()`](#in-your-test-suite) returns the report as an object, with helpers to list what fails and to print it.
|
|
630
|
+
|
|
583
631
|
**Does a pass mean my CLI has no terminal bugs?** No. Each check tests one behavior, on the probes that ran; a subcommand that wasn't probed wasn't checked. cliprobe reports evidence, not a score, so add a `--probe` for each command your users pipe or interrupt.
|
|
584
632
|
|
|
585
633
|
**Does it only work for Node.js programs?** No. It tests any command as a black box, whatever it is written in. Only the [fixes](#fixing-a-failure-in-a-nodejs-cli) are specific to Node.js.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|