Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ignore start/stop comment #273

Merged
merged 6 commits into from Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
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
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
@@ -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')
}
14 changes: 14 additions & 0 deletions test/integration.js
Expand Up @@ -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/normal',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@connorjclark part of the problem was here, we should use a different tmp directory for each test (it was an oversight that we were already reusing tmp/normal).

I believe this was contributing to nondeterministic behavior.

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
15 changes: 15 additions & 0 deletions test/integration.js.snap
Expand Up @@ -24,6 +24,21 @@ All files | 86.21 | 91.67 | 66.67 | 86.21 |
,"
`;

exports[`c8 /* c8 ignore start/stop */ ignores lines with special comment 1`] = `
",covered
covered
-------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files | 89.87 | 87.5 | 71.43 | 89.87 |
async.js | 100 | 100 | 100 | 100 |
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22
c8-ignore-start-stop.js | 100 | 75 | 100 | 100 | 2
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
-------------------------|---------|----------|---------|---------|-------------------
,"
`;

exports[`c8 --all reports coverage for unloaded js files as 0 for line, branch and function 1`] = `
",zero
positive
Expand Down
26 changes: 26 additions & 0 deletions test/integration.js_10.snap
Expand Up @@ -35,6 +35,32 @@ All files | 76.18 | 61.18 | 68.57 | 76.18 |
,"
`;

exports[`c8 /* c8 ignore start/stop */ ignores lines with special comment 1`] = `
",covered
covered
--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 76.9 | 65.93 | 69.44 | 76.9 |
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 | 59.65 | 84.21 | 80.67 |
is-cjs-esm-bridge.js | 90 | 62.5 | 100 | 90 | 9
parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133
report.js | 75.17 | 62.16 | 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 | 89.87 | 87.5 | 75 | 89.87 |
async.js | 100 | 100 | 100 | 100 |
c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22
c8-ignore-start-stop.js | 100 | 75 | 100 | 100 | 2
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
--------------------------|---------|----------|---------|---------|--------------------------------
,"
`;

exports[`c8 --all reports coverage for unloaded js files as 0 for line, branch and function 1`] = `
",zero
positive
Expand Down