diff --git a/README.md b/README.md index 7228e0e4..772748a0 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ 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 @@ -72,7 +72,7 @@ const myVariable = 99 if (process.platform === 'win32') console.info('hello world') ``` -### Ignoring the next N elements +### Ignoring the next N lines ```js const myVariable = 99 @@ -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 diff --git a/package-lock.json b/package-lock.json index d48bb37d..403ea9ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2951,9 +2951,9 @@ "dev": true }, "v8-to-istanbul": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-7.0.0.tgz", - "integrity": "sha512-fLL2rFuQpMtm9r8hrAV2apXX/WqHJ6+IC4/eQVdMDGBUgH/YMV4Gv3duk3kjmyg6uiQWBAA9nJwue4iJUOkHeA==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-7.1.0.tgz", + "integrity": "sha512-uXUVqNUCLa0AH1vuVxzi+MI4RfxEOKt9pBgKwHbgH7st8Kv2P1m+jvWNnektzBh5QShF3ODgKmUFCf38LnVz1g==", "requires": { "@types/istanbul-lib-coverage": "^2.0.1", "convert-source-map": "^1.6.0", diff --git a/package.json b/package.json index b89e6cad..2f360a16 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/fixtures/c8-ignore-start-stop.js b/test/fixtures/c8-ignore-start-stop.js new file mode 100644 index 00000000..0db97a8f --- /dev/null +++ b/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') +} diff --git a/test/integration.js b/test/integration.js index def53a94..2da500c0 100644 --- a/test/integration.js +++ b/test/integration.js @@ -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') ]) @@ -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)) diff --git a/test/integration.js.snap b/test/integration.js.snap index 93e4fbb8..81c2e1b3 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -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 diff --git a/test/integration.js_10.snap b/test/integration.js_10.snap index be0e8aab..f4e22e8d 100644 --- a/test/integration.js_10.snap +++ b/test/integration.js_10.snap @@ -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 +-------------------------|---------|----------|---------|---------|------------------- ," `;