Package Exports
- stdstream-snapshot
- stdstream-snapshot/target/bundle/stdstream-snapshot.js
- stdstream-snapshot/target/bundle/stdstream-snapshot.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stdstream-snapshot) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@qiwi/stdstream-snapshot
Util for CLI testing: fetch stdout, stderr streams and match its data to snapshot
Install
yarn add @qiwi/stdstream-snapshot -D
npm add @qiwi/stdstream-snapshot -D
Snapshot
{
"stderr": "",
"stdout": "/rules/some-rules.ts\n 2:7 error 'name'...",
"err": {
"signal": null,
"code": 1,
"killed": false
}
}
Usage
With Jest:
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 or another test framework with no built-it snapshot API:
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 |