Skip to content

Commit

Permalink
feat: support ignore start/stop comment (bcoe#273)
Browse files Browse the repository at this point in the history
Fixes bcoe#271
  • Loading branch information
connorjclark authored Dec 30, 2020
1 parent ebe92de commit 90949fa
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 29 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ To ignore lines, blocks, and functions, use the special comment:

`/* c8 ignore next */`.

### Ignoring the next element
### Ignoring the next line

```js
const myVariable = 99
/* c8 ignore next */
if (process.platform === 'win32') console.info('hello world')
```

### Ignoring the next N elements
### Ignoring the next N lines

```js
const myVariable = 99
Expand All @@ -82,6 +82,16 @@ if (process.platform === 'win32') {
}
```

### Ignoring all lines until told

```js
/* c8 ignore start */
function dontMindMe() {
// ...
}
/* c8 ignore stop */
```

### Ignoring a block on the current line

```js
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"istanbul-reports": "^3.0.2",
"rimraf": "^3.0.0",
"test-exclude": "^6.0.0",
"v8-to-istanbul": "^7.0.0",
"v8-to-istanbul": "^7.1.0",
"yargs": "^16.0.0",
"yargs-parser": "^20.0.0"
},
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/c8-ignore-start-stop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const a = 99
const b = true ? 1 : 2
if (true) {
console.info('covered')
/* c8 ignore start */
} else {
console.info('uncovered')
}
/* c8 ignore stop */

/* c8 ignore start */ 'ignore me'
function notExecuted () {

}
/* c8 ignore stop */

if (true) {
console.info('covered')
} else { /* c8 ignore start */
console.info('uncovered')
}
16 changes: 15 additions & 1 deletion test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('c8', () => {
c8Path,
'--exclude="test/*.js"',
'--clean=false',
'--temp-directory=tmp/normal',
'--temp-directory=tmp/special-comment',
nodePath,
require.resolve('./fixtures/c8-ignore-next.js')
])
Expand All @@ -294,6 +294,20 @@ describe('c8', () => {
})
})

describe('/* c8 ignore start/stop */', () => {
it('ignores lines with special comment', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--clean=false',
'--temp-directory=tmp/start-stop',
nodePath,
require.resolve('./fixtures/c8-ignore-start-stop.js')
])
output.toString('utf8').should.matchSnapshot()
})
})

describe('source-maps', () => {
beforeEach(cb => rimraf('tmp/source-map', cb))

Expand Down
16 changes: 13 additions & 3 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ covered
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 86.21 | 91.67 | 66.67 | 86.21 |
async.js | 100 | 100 | 100 | 100 |
All files | 90.91 | 100 | 100 | 90.91 |
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
-------------------|---------|----------|---------|---------|-------------------
,"
`;

exports[`c8 /* c8 ignore start/stop */ ignores lines with special comment 1`] = `
",covered
covered
-------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files | 100 | 75 | 100 | 100 |
c8-ignore-start-stop.js | 100 | 75 | 100 | 100 | 2
-------------------------|---------|----------|---------|---------|-------------------
,"
`;

exports[`c8 --all reports coverage for unloaded js files as 0 for line, branch and function 1`] = `
",zero
positive
Expand Down
37 changes: 18 additions & 19 deletions test/integration.js_10.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@ All files | 100 | 100 | 100 | 100 |
exports[`c8 /* c8 ignore next */ ignores lines with special comment 1`] = `
",covered
covered
--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 76.18 | 61.18 | 68.57 | 76.18 |
bin | 78.85 | 60 | 66.67 | 78.85 |
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
lib | 80.67 | 52.73 | 84.21 | 80.67 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133
report.js | 75.17 | 60 | 84.62 | 75.17 | ...206,237-238,264-265,271-273
source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23
lib/commands | 44.44 | 75 | 16.67 | 44.44 |
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
report.js | 93.1 | 71.43 | 50 | 93.1 | 9-10
test/fixtures | 86.21 | 91.67 | 71.43 | 86.21 |
async.js | 100 | 100 | 100 | 100 |
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
--------------------------|---------|----------|---------|---------|--------------------------------
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 90.91 | 100 | 100 | 90.91 |
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22
-------------------|---------|----------|---------|---------|-------------------
,"
`;

exports[`c8 /* c8 ignore start/stop */ ignores lines with special comment 1`] = `
",covered
covered
-------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files | 100 | 75 | 100 | 100 |
c8-ignore-start-stop.js | 100 | 75 | 100 | 100 | 2
-------------------------|---------|----------|---------|---------|-------------------
,"
`;

Expand Down

0 comments on commit 90949fa

Please sign in to comment.