https://github.com/qiwi/stdstream-snapshot
Tiny util for CLI testing: fetch stdout, stderr streams and match data to snapshot
https://github.com/qiwi/stdstream-snapshot
Last synced: 6 days ago
JSON representation
Tiny util for CLI testing: fetch stdout, stderr streams and match data to snapshot
- Host: GitHub
- URL: https://github.com/qiwi/stdstream-snapshot
- Owner: qiwi
- License: mit
- Created: 2019-09-23T07:55:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-15T14:20:13.000Z (about 2 months ago)
- Last Synced: 2025-04-24T06:07:26.336Z (9 days ago)
- Language: TypeScript
- Size: 693 KB
- Stars: 1
- Watchers: 9
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @qiwi/stdstream-snapshot
[](https://github.com/qiwi/stdstream-snapshot/actions/workflows/ci.yaml)
[](https://codeclimate.com/github/qiwi/stdstream-snapshot/maintainability)
[](https://codeclimate.com/github/qiwi/stdstream-snapshot/test_coverage)
[](https://www.npmjs.com/package/@qiwi/stdstream-snapshot)Util for CLI testing: fetch stdout, stderr streams and match its data to snapshot
## Install
```bash
yarn add @qiwi/stdstream-snapshot -D
npm add @qiwi/stdstream-snapshot -D
```## Snapshot
```json
{
"stderr": "",
"stdout": "/rules/some-rules.ts\n 2:7 error 'name'...",
"err": {
"signal": null,
"code": 1,
"killed": false
}
}
```## Usage
With [Jest](https://jestjs.io/):
```javascript
import {generateSnapshot} from 'stdstream-snapshot'it('cmd output matches to snapshot', async () => {
const cmd = 'somecmd --flag=foo -b'
const result = await generateSnapshot({
cmd,
})expect(result).toMatchSnapshot()
})
```With [Jasmine](https://jasmine.github.io/) or another test framework with no built-it snapshot API:
```javascript
import {matchSnapshot} from 'stdstream-snapshot'it('cmd output matches to snapshot', async () => {
const cmd = 'somecmd --flag=foo -b'
const target = './test/snapshots/some-cmd-output.json'
const result = await matchSnapshot({
cmd,
target,
update: !!process.env.UPDATE_SNAPSHOT
})expect(result).toBe(true)
})
```## Options
There are several normalization steps supported out of box.| Option | Description | Default |
|----------------------|----------------------------------------------------------------------------|---------|
| `trim` | Removes redundant spaces from both ends of strings | true |
| `normalizePaths` | Replaces `process.cwd()` prefix from any found paths in the output strings | true |
| `normalizeSpaces` | Converts tabs to double spaces | true |
| `normalizeEncoding` | Replaces output rubbish like `[8m [10m` | true |## License
[MIT](/LICENSE)