Package detail

@qiwi/stdstream-snapshot

qiwi6MIT1.2.9

Util for CLI testing: fetch stdout, stderr streams and match data to snapshot

snapshot, stdout, stderr, stdstream

readme

@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.

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

changelog

1.2.9 (2022-10-13)

Fixes & improvements

  • fix: add pkg exports field (dde9f25)

1.2.8 (2022-09-28)

Fixes & improvements

1.2.7 (2022-09-28)

Fixes & improvements

  • perf: up deps, fix some vuls (bd08f24)

1.2.6 (2022-03-07)

Bug Fixes

  • deps: update dependency lodash to v4.17.21 [security] (d27868a)

1.2.5 (2020-10-29)

Performance Improvements

  • package: up deps, fix vuls (ee62988)

1.2.4 (2019-10-30)

Performance Improvements

1.2.3 (2019-10-30)

Performance Improvements

1.2.2 (2019-09-29)

Bug Fixes

  • index: export lib ifaces (711d9ee)

1.2.1 (2019-09-28)

Performance Improvements

  • package: minor improvements, up dev deps & repack (44003e0)

1.2.0 (2019-09-27)

Bug Fixes

  • exclude opts field from snapshot data (9fc7563)
  • fix default opts processing (5a11aee)

Features

  • expose generateSnapshot to use Jest snapshot API (576b08d)

1.1.1 (2019-09-26)

Bug Fixes

  • rename process to matchSnapshot (6a5260b)

1.1.0 (2019-09-26)

Features

  • add err details to snapshot (10966ff)

1.0.0 (2019-09-26)

Features

  • add configurable output normalization (497cb64)