Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 4 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 (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-09T21:01:46.000Z (4 months ago)
- Last Synced: 2024-07-16T14:21:19.510Z (4 months ago)
- Language: TypeScript
- Size: 1.02 MB
- Stars: 1
- Watchers: 11
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @qiwi/stdstream-snapshot
[![CI](https://github.com/qiwi/stdstream-snapshot/actions/workflows/ci.yaml/badge.svg)](https://github.com/qiwi/stdstream-snapshot/actions/workflows/ci.yaml)
[![Maintainability](https://api.codeclimate.com/v1/badges/5770053f57f0656df4ea/maintainability)](https://codeclimate.com/github/qiwi/stdstream-snapshot/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/5770053f57f0656df4ea/test_coverage)](https://codeclimate.com/github/qiwi/stdstream-snapshot/test_coverage)
[![npm (scoped)](https://img.shields.io/npm/v/@qiwi/stdstream-snapshot)](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)