Skip to content

Commit

Permalink
Merge 96979b9 into 5ea4313
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Apr 20, 2019
2 parents 5ea4313 + 96979b9 commit dda5c4e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
.DS_Store
node_modules
.nyc_output
coverage
coverage
tmp
46 changes: 40 additions & 6 deletions test/integration.js
@@ -1,21 +1,24 @@
/* global describe, beforeEach, it */
/* global describe, before, beforeEach, it */

const { spawnSync } = require('child_process')
const c8Path = require.resolve('../bin/c8')
const nodePath = process.execPath
const chaiJestSnapshot = require('chai-jest-snapshot')
const rimraf = require('rimraf')

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

before(cb => rimraf('tmp', cb))
beforeEach(function () { chaiJestSnapshot.configureUsingMochaContext(this) })

describe('c8', () => {
it('reports coverage for script that exits normally', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/normal',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
Expand All @@ -27,6 +30,7 @@ describe('c8', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/multiple-spawn',
'--clean=false',
nodePath,
require.resolve('./fixtures/multiple-spawn')
Expand All @@ -38,6 +42,7 @@ describe('c8', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/multiple-spawn-2',
'--omit-relative=false',
'--clean=false',
nodePath,
Expand All @@ -49,35 +54,49 @@ describe('c8', () => {
})

describe('check-coverage', () => {
before(() => {
spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
])
})

it('exits with 0 if coverage within threshold', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--temp-directory=tmp/check-coverage',
'--lines=80'
])
status.should.equal(0)
output.toString('utf8').should.matchSnapshot()
})

it('allows threshold to be applied on per-file basis', () => {
it('exits with 1 if coverage is below threshold', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--lines=80',
'--per-file'
'--temp-directory=tmp/check-coverage',
'--lines=101'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
})

it('exits with 1 if coverage is below threshold', () => {
it('allows threshold to be applied on per-file basis', () => {
const { output, status } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--exclude="test/*.js"',
'--lines=101'
'--temp-directory=tmp/check-coverage',
'--lines=101',
'--per-file'
])
status.should.equal(1)
output.toString('utf8').should.matchSnapshot()
Expand All @@ -88,6 +107,7 @@ describe('c8', () => {
c8Path,
'--exclude="test/*.js"',
'--clean=false',
'--temp-directory=tmp/check-coverage',
'--lines=101',
'--check-coverage',
nodePath,
Expand All @@ -99,11 +119,23 @@ describe('c8', () => {
})

describe('report', () => {
before(() => {
spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/report',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
])
})

it('generates report from existing temporary files', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'report',
'--exclude="test/*.js"',
'--temp-directory=tmp/report',
'--clean=false'
])
output.toString('utf8').should.matchSnapshot()
Expand All @@ -116,6 +148,7 @@ describe('c8', () => {
'--check-coverage',
'--lines=101',
'--exclude="test/*.js"',
'--temp-directory=tmp/report',
'--clean=false'
])
status.should.equal(1)
Expand All @@ -129,6 +162,7 @@ describe('c8', () => {
c8Path,
'--exclude="test/*.js"',
'--clean=false',
'--temp-directory=tmp/esm',
nodePath,
'--experimental-modules',
'--no-warnings',
Expand Down
137 changes: 40 additions & 97 deletions test/integration.js.snap
Expand Up @@ -2,26 +2,13 @@

exports[`c8 ESM Modules collects coverage for ESM modules 1`] = `
",bar
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.2 | 86.49 | 90.32 | 96.2 | |
bin | 91.18 | 83.33 | 100 | 91.18 | |
c8.js | 91.18 | 83.33 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 82.35 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 91.67 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 100 | 88.89 | 100 | 100 | |
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
report.js | 100 | 80 | 100 | 100 | 16 |
test/fixtures | 89.04 | 93.75 | 70 | 89.04 | |
async.js | 100 | 100 | 100 | 100 | |
export.mjs | 71.43 | 100 | 50 | 71.43 | 2,3 |
import.mjs | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 80 | 100 | 50 | 80 | |
export.mjs | 71.43 | 100 | 50 | 71.43 | 2,3 |
import.mjs | 100 | 100 | 100 | 100 | |
------------|----------|----------|----------|----------|-------------------|
,"
`;

Expand All @@ -34,38 +21,27 @@ what
hey
what
hey
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.12 | 82.09 | 89.66 | 96.12 | |
bin | 91.18 | 80 | 100 | 91.18 | |
c8.js | 91.18 | 80 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 78.13 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 86.36 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 97.67 | 82.35 | 87.5 | 97.67 | |
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (96.12%) does not meet global threshold (101%)
-----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files | 83.33 | 85.71 | 66.67 | 83.33 | |
async.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
-----------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (83.33%) does not meet global threshold (101%)
"
`;

exports[`c8 check-coverage allows threshold to be applied on per-file basis 1`] = `
",,ERROR: Coverage for lines (78.33%) does not meet threshold (80%) for lib/commands/check-coverage.js
ERROR: Coverage for lines (75%) does not meet threshold (80%) for test/fixtures/normal.js
",,ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js
ERROR: Coverage for lines (75%) does not meet threshold (101%) for test/fixtures/normal.js
"
`;

exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`;

exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = `
",,ERROR: Coverage for lines (95.69%) does not meet global threshold (101%)
",,ERROR: Coverage for lines (83.33%) does not meet global threshold (101%)
"
`;

Expand All @@ -74,69 +50,36 @@ exports[`c8 merges reports from subprocesses together 1`] = `
second
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 84.91 | 72 | 74.07 | 84.91 | |
bin | 88.24 | 60 | 100 | 88.24 | |
c8.js | 88.24 | 60 | 100 | 88.24 | 22,25,26,27 |
lib | 96.09 | 66.67 | 100 | 96.09 | |
parse-args.js | 96.92 | 44.44 | 100 | 96.92 | 93,94,107,108 |
report.js | 95.36 | 77.78 | 100 | 95.36 |... 10,136,137,138 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
-------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
subprocess.js | 100 | 100 | 100 | 100 | |
-------------------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 report generates report from existing temporary files 1`] = `
",--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.12 | 85.51 | 89.66 | 96.12 | |
bin | 91.18 | 83.33 | 100 | 91.18 | |
c8.js | 91.18 | 83.33 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 82.35 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 91.67 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 97.67 | 87.5 | 87.5 | 97.67 | |
check-coverage.js | 100 | 91.67 | 100 | 100 | 17 |
report.js | 92.31 | 75 | 50 | 92.31 | 9,10 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
",-----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files | 83.33 | 85.71 | 66.67 | 83.33 | |
async.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
-----------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 report supports --check-coverage, when generating reports 1`] = `
",--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.55 | 85.51 | 93.1 | 96.55 | |
bin | 91.18 | 80 | 100 | 91.18 | |
c8.js | 91.18 | 80 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 82.35 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 91.67 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 100 | 88.24 | 100 | 100 | |
check-coverage.js | 100 | 91.67 | 100 | 100 | 17 |
report.js | 100 | 80 | 100 | 100 | 16 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (96.55%) does not meet global threshold (101%)
",-----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------|----------|----------|----------|----------|-------------------|
All files | 83.33 | 85.71 | 66.67 | 83.33 | |
async.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
-----------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (83.33%) does not meet global threshold (101%)
"
`;

Expand Down

0 comments on commit dda5c4e

Please sign in to comment.