|
1 | | -/* global describe, it */ |
| 1 | +/* global describe, beforeEach, it */ |
2 | 2 |
|
3 | 3 | const { spawnSync } = require('child_process') |
4 | 4 | const c8Path = require.resolve('../bin/c8') |
5 | 5 | const nodePath = process.execPath |
| 6 | +const chaiJestSnapshot = require('chai-jest-snapshot') |
6 | 7 |
|
7 | | -require('chai').should() |
| 8 | +require('chai') |
| 9 | + .use(chaiJestSnapshot) |
| 10 | + .should() |
| 11 | + |
| 12 | +beforeEach(function () { chaiJestSnapshot.configureUsingMochaContext(this) }) |
8 | 13 |
|
9 | 14 | describe('c8', () => { |
10 | 15 | it('reports coverage for script that exits normally', () => { |
11 | 16 | const { output } = spawnSync(nodePath, [ |
12 | 17 | c8Path, |
13 | 18 | '--exclude="test/*.js"', |
| 19 | + '--clean=false', |
14 | 20 | nodePath, |
15 | 21 | require.resolve('./fixtures/normal') |
16 | 22 | ]) |
17 | | - output.toString('utf8').should.include(` |
18 | | ------------|----------|----------|----------|----------|-------------------| |
19 | | -File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | |
20 | | ------------|----------|----------|----------|----------|-------------------| |
21 | | -All files | 91.18 | 88.89 | 0 | 91.18 | | |
22 | | - async.js | 100 | 100 | 100 | 100 | | |
23 | | - normal.js | 85.71 | 75 | 0 | 85.71 | 14,15,16 | |
24 | | ------------|----------|----------|----------|----------|-------------------|`) |
| 23 | + output.toString('utf8').should.matchSnapshot() |
25 | 24 | }) |
26 | 25 |
|
27 | 26 | it('merges reports from subprocesses together', () => { |
28 | 27 | const { output } = spawnSync(nodePath, [ |
29 | 28 | c8Path, |
30 | 29 | '--exclude="test/*.js"', |
| 30 | + '--clean=false', |
31 | 31 | nodePath, |
32 | 32 | require.resolve('./fixtures/multiple-spawn') |
33 | 33 | ]) |
34 | | - output.toString('utf8').should.include(` |
35 | | --------------------|----------|----------|----------|----------|-------------------| |
36 | | -File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | |
37 | | --------------------|----------|----------|----------|----------|-------------------| |
38 | | -All files | 100 | 77.78 | 100 | 100 | | |
39 | | - multiple-spawn.js | 100 | 100 | 100 | 100 | | |
40 | | - subprocess.js | 100 | 71.43 | 100 | 100 | 9,13 | |
41 | | --------------------|----------|----------|----------|----------|-------------------|`) |
| 34 | + output.toString('utf8').should.matchSnapshot() |
42 | 35 | }) |
43 | 36 |
|
44 | 37 | it('omit-relative can be set to false', () => { |
45 | 38 | const { output } = spawnSync(nodePath, [ |
46 | 39 | c8Path, |
47 | 40 | '--exclude="test/*.js"', |
48 | 41 | '--omit-relative=false', |
| 42 | + '--clean=false', |
49 | 43 | nodePath, |
50 | 44 | require.resolve('./fixtures/multiple-spawn') |
51 | 45 | ]) |
|
0 commit comments