1.2.9 • Published 2 years ago

stdstream-snapshot v1.2.9

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

@qiwi/stdstream-snapshot

CI Maintainability Test Coverage npm (scoped)

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.

OptionDescriptionDefault
trimRemoves redundant spaces from both ends of stringstrue
normalizePathsReplaces process.cwd() prefix from any found paths in the output stringstrue
normalizeSpacesConverts tabs to double spacestrue
normalizeEncodingReplaces output rubbish like [8m [10mtrue

License

MIT

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago