Skip to content

Commit 6b555d0

Browse files
committed
feat: use snapshot testing
1 parent 58c076e commit 6b555d0

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
},
4848
"devDependencies": {
4949
"chai": "^4.1.2",
50+
"chai-jest-snapshot": "^2.0.0",
5051
"coveralls": "^3.0.2",
5152
"mocha": "^5.2.0",
5253
"standard": "^12.0.1",

test/integration.js

+8-25
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
const { spawnSync } = require('child_process')
44
const c8Path = require.resolve('../bin/c8')
55
const nodePath = process.execPath
6+
const chaiJestSnapshot = require('chai-jest-snapshot')
67

7-
require('chai').should()
8+
require('chai')
9+
.use(chaiJestSnapshot)
10+
.should()
11+
12+
beforeEach(function() { chaiJestSnapshot.configureUsingMochaContext(this) })
813

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

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

5437
it('omit-relative can be set to false', () => {

test/integration.js.snap

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`c8 merges reports from subprocesses together 1`] = `
4+
",first
5+
6+
second
7+
8+
--------------------|----------|----------|----------|----------|-------------------|
9+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
10+
--------------------|----------|----------|----------|----------|-------------------|
11+
All files | 94.12 | 70.59 | 0 | 94.12 | |
12+
bin | 83.72 | 57.14 | 100 | 83.72 | |
13+
c8.js | 83.72 | 57.14 | 100 | 83.72 |... 22,40,41,42,43 |
14+
lib | 96.41 | 65.38 | 100 | 96.41 | |
15+
parse-args.js | 97.47 | 44.44 | 100 | 97.47 | 55,56 |
16+
report.js | 95.45 | 76.47 | 100 | 95.45 | 51,52,53,54 |
17+
test/fixtures | 95.16 | 83.33 | 0 | 95.16 | |
18+
async.js | 100 | 100 | 100 | 100 | |
19+
multiple-spawn.js | 100 | 100 | 100 | 100 | |
20+
normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 |
21+
subprocess.js | 100 | 71.43 | 100 | 100 | 9,13 |
22+
--------------------|----------|----------|----------|----------|-------------------|
23+
,"
24+
`;
25+
26+
exports[`c8 reports coverage for script that exits normally 1`] = `
27+
",hey
28+
i am a line of code
29+
what
30+
hey
31+
what
32+
hey
33+
what
34+
hey
35+
-----------|----------|----------|----------|----------|-------------------|
36+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
37+
-----------|----------|----------|----------|----------|-------------------|
38+
All files | 91.18 | 88.89 | 0 | 91.18 | |
39+
async.js | 100 | 100 | 100 | 100 | |
40+
normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 |
41+
-----------|----------|----------|----------|----------|-------------------|
42+
,"
43+
`;

0 commit comments

Comments
 (0)