Skip to content

Commit

Permalink
feat: use snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
laggingreflex committed Sep 13, 2018
1 parent 58c076e commit 6b555d0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"devDependencies": {
"chai": "^4.1.2",
"chai-jest-snapshot": "^2.0.0",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
"standard": "^12.0.1",
Expand Down
33 changes: 8 additions & 25 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
const { spawnSync } = require('child_process')
const c8Path = require.resolve('../bin/c8')
const nodePath = process.execPath
const chaiJestSnapshot = require('chai-jest-snapshot')

require('chai').should()
require('chai')
.use(chaiJestSnapshot)
.should()

beforeEach(function() { chaiJestSnapshot.configureUsingMochaContext(this) })

describe('c8', () => {
it('reports coverage for script that exits normally', () => {
Expand All @@ -15,14 +20,7 @@ describe('c8', () => {
nodePath,
require.resolve('./fixtures/normal')
])
output.toString('utf8').should.include(`
-----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files | 91.18 | 88.89 | 0 | 91.18 | |
async.js | 100 | 100 | 100 | 100 | |
normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 |
-----------|----------|----------|----------|----------|-------------------|`)
output.toString('utf8').should.matchSnapshot()
})

it('merges reports from subprocesses together', () => {
Expand All @@ -33,22 +31,7 @@ All files | 91.18 | 88.89 | 0 | 91.18 | |
nodePath,
require.resolve('./fixtures/multiple-spawn')
])
output.toString('utf8').should.include(`
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 94.12 | 70.59 | 0 | 94.12 | |
bin | 83.72 | 57.14 | 100 | 83.72 | |
c8.js | 83.72 | 57.14 | 100 | 83.72 |... 22,40,41,42,43 |
lib | 96.41 | 65.38 | 100 | 96.41 | |
parse-args.js | 97.47 | 44.44 | 100 | 97.47 | 55,56 |
report.js | 95.45 | 76.47 | 100 | 95.45 | 51,52,53,54 |
test/fixtures | 95.16 | 83.33 | 0 | 95.16 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 |
subprocess.js | 100 | 71.43 | 100 | 100 | 9,13 |
--------------------|----------|----------|----------|----------|-------------------|`)
output.toString('utf8').should.matchSnapshot()
})

it('omit-relative can be set to false', () => {
Expand Down
43 changes: 43 additions & 0 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`c8 merges reports from subprocesses together 1`] = `
",first
second
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 94.12 | 70.59 | 0 | 94.12 | |
bin | 83.72 | 57.14 | 100 | 83.72 | |
c8.js | 83.72 | 57.14 | 100 | 83.72 |... 22,40,41,42,43 |
lib | 96.41 | 65.38 | 100 | 96.41 | |
parse-args.js | 97.47 | 44.44 | 100 | 97.47 | 55,56 |
report.js | 95.45 | 76.47 | 100 | 95.45 | 51,52,53,54 |
test/fixtures | 95.16 | 83.33 | 0 | 95.16 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 |
subprocess.js | 100 | 71.43 | 100 | 100 | 9,13 |
--------------------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 reports coverage for script that exits normally 1`] = `
",hey
i am a line of code
what
hey
what
hey
what
hey
-----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files | 91.18 | 88.89 | 0 | 91.18 | |
async.js | 100 | 100 | 100 | 100 | |
normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 |
-----------|----------|----------|----------|----------|-------------------|
,"
`;

0 comments on commit 6b555d0

Please sign in to comment.