@@ -22,27 +22,25 @@ Instead, the following API is what `CLI Testing Library` provides the following.
2222function render(
2323 command : string ,
2424 args : string [],
25- options ? : {
26- /* You won't often use this, expand below for docs on options */
27- },
28- ): RenderResult
25+ options ? : {/* You won't often use this, expand below for docs on options */ },
26+ ): RenderResult ;
2927```
3028
3129Run the CLI application in a newly spawned process.
3230
3331``` javascript
34- import {render} from ' cli-testing-library'
32+ import { render } from " cli-testing-library" ;
3533
36- render(' node' , [' ./path/to/script.js'])
34+ render (" node" , [" ./path/to/script.js" ]);
3735```
3836
3937``` javascript
40- import {render} from ' cli-testing-library'
38+ import { render } from " cli-testing-library" ;
4139
42- test(' renders a message' , () => {
43- const {getByText} = render(' node' , [' ./console-out.js'])
44- expect(getByText(' Hello, world!' )).toBeTruthy()
45- })
40+ test (" renders a message" , () => {
41+ const { getByText } = render (" node" , [" ./console-out.js" ]);
42+ expect (getByText (" Hello, world!" )).toBeTruthy ();
43+ });
4644```
4745
4846# ` render ` Options
@@ -62,11 +60,11 @@ to have to specify the absolute path every time. In this case, you can specify a
6260directory as the render ` cwd ` .
6361
6462``` javascript
65- const containingPath = path.resolve(__dirname, ' ./movables')
63+ const containingPath = path .resolve (__dirname , " ./movables" );
6664
67- const {getByText} = render(' node' , [' mover.js' ], {
65+ const { getByText } = render (" node" , [" mover.js" ], {
6866 cwd: containingPath,
69- })
67+ });
7068```
7169
7270## ` spawnOpts `
@@ -79,11 +77,11 @@ underlying
7977[ ` child_process.spawn ` NodeJS API] ( https://nodejs.org/api/child_process.html#child_processspawncommand-args-options ) .
8078
8179``` javascript
82- const {getByText} = render(' script.ps1' , {
80+ const { getByText } = render (" script.ps1" , {
8381 spawnOpts: {
84- shell: ' powershell.exe' ,
82+ shell: " powershell.exe" ,
8583 },
86- })
84+ });
8785```
8886
8987# ` render ` Result
@@ -127,7 +125,7 @@ These options are all standard for text matching. To learn more, see our
127125## ` userEvent[eventName] `
128126
129127``` javascript
130- userEvent[eventName](...eventProps)
128+ userEvent[eventName](... eventProps);
131129```
132130
133131> While ` userEvent ` isn't usually returned on ` render ` in, say,
@@ -144,10 +142,10 @@ This object is the same as described with
144142This method is a shortcut for ` console.log(prettyCLI(instance)). `
145143
146144``` javascript
147- import {render} from ' cli-testing-library'
145+ import { render } from " cli-testing-library" ;
148146
149- const {debug} = render(' command')
150- debug()
147+ const { debug } = render (" command" );
148+ debug ();
151149// Hello, world! How are you?
152150//
153151// you can also pass an instance: debug(getByText('message'))
@@ -166,9 +164,9 @@ This method allows you to check if the spawned process has exit, and if so, what
166164exit code it closed with.
167165
168166``` javascript
169- const instance = render(' command')
167+ const instance = render (" command" );
170168
171- await waitFor(() => expect(instance.hasExit()).toMatchObject({exitCode: 1}))
169+ await waitFor (() => expect (instance .hasExit ()).toMatchObject ({ exitCode: 1 }));
172170```
173171
174172This method returns ` null ` if still running, but ` {exitCode: number} ` if it has
@@ -189,8 +187,8 @@ They're defined as:
189187
190188``` typescript
191189interface TestInstance {
192- stdoutArr: Array<{contents: Buffer | string; timestamp: number}>
193- stderrArr: Array<{contents: Buffer | string; timestamp: number}>
190+ stdoutArr: Array <{ contents: Buffer | string ; timestamp: number }>;
191+ stderrArr: Array <{ contents: Buffer | string ; timestamp: number }>;
194192}
195193```
196194
@@ -214,15 +212,15 @@ For example, if you're using the [ava](https://github.com/avajs/ava) testing
214212framework, then you would need to use the ` test.afterEach ` hook like so:
215213
216214``` javascript
217- import {cleanup, render} from ' cli-testing-library'
218- import test from ' ava'
215+ import { cleanup , render } from " cli-testing-library" ;
216+ import test from " ava" ;
219217
220- test.afterEach(cleanup)
218+ test .afterEach (cleanup);
221219
222- test(' renders into document' , () => {
223- render(' long-running-command')
220+ test (" renders into document" , () => {
221+ render (" long-running-command" );
224222 // ...
225- })
223+ });
226224
227225// ... more tests ...
228226```
0 commit comments