Skip to content

Commit 902b5ee

Browse files
committed
docs(README): add tokenizedOutput example
1 parent 18e1e12 commit 902b5ee

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ yarn add --dev cli-testing-library
3232

3333
Check out [Interactive Examples on Stackblitz](https://stackblitz.com/edit/node-kfod5b?file=examples%2Fprompts%2Fprompts.test.js)
3434

35-
### Hello World Example
35+
### Eg 1: Hello World Example
3636

3737
```js
3838
// hello-world.test.js
@@ -63,7 +63,28 @@ readline.question(`What's your name?`, (name) => {
6363

6464
```
6565

66-
Check out [More Examples on Stackblitz](https://stackblitz.com/edit/node-kfod5b?file=examples%2Fprompts%2Fprompts.test.js)
66+
### Eg 2: Tokenized Output
67+
68+
Check out [this example of StackBlitz](https://stackblitz.com/edit/node-kfod5b?file=examples%2Fcolored-output%2Fcolored-output.test.js)
69+
70+
Sometimes you may want to test if the output has correct color and graphics. You can use the `.tokenizedOutput` method to get tokens in the output.
71+
72+
Check out [list of tokens](https://github.com/saurabhdaware/cli-testing-library/blob/18e1e12d86cec7b429f949cdd571b13b64fd4747/lib/cli-ansi-parser.js#L28) that library outputs.
73+
74+
```js
75+
// colored-output.test.js
76+
const { createCommandInterface } = require('cli-testing-library');
77+
78+
test('should have bold red text', async () => {
79+
const commandInterface = createCommandInterface('node ./colored-output.js', {
80+
cwd: __dirname,
81+
});
82+
const terminal = await commandInterface.getOutput();
83+
expect(terminal.tokenizedOutput).toBe("This has a [BOLD_START][RED_START]red and bold[COLOR_END][BOLD_END] text.");
84+
});
85+
```
86+
87+
[More Examples on Stackblitz](https://stackblitz.com/edit/node-kfod5b?file=examples%2Fprompts%2Fprompts.test.js)
6788

6889

6990
Big Shoutout to

0 commit comments

Comments
 (0)