diff --git a/lib/commands/report.js b/lib/commands/report.js index cacf88b4..b42e5072 100644 --- a/lib/commands/report.js +++ b/lib/commands/report.js @@ -34,7 +34,8 @@ exports.outputReport = async function (argv) { allowExternal: argv.allowExternal, src: argv.src, skipFull: argv.skipFull, - excludeNodeModules: argv.excludeNodeModules + excludeNodeModules: argv.excludeNodeModules, + mergeAsync: argv.mergeAsync }) await report.run() if (argv.checkCoverage) await checkCoverages(argv, report) diff --git a/lib/parse-args.js b/lib/parse-args.js index 0266923a..21a9cd7a 100644 --- a/lib/parse-args.js +++ b/lib/parse-args.js @@ -152,6 +152,12 @@ function buildYargs (withCommands = false) { describe: 'supplying --allowExternal will cause c8 to allow files from outside of your cwd. This applies both to ' + 'files discovered in coverage temp files and also src files discovered if using the --all flag.' }) + .options('merge-async', { + default: false, + type: 'boolean', + describe: 'supplying --merge-async will merge all v8 coverage reports asynchronously and incrementally. ' + + 'This is to avoid OOM issues with Node.js runtime.' + }) .pkgConf('c8') .demandCommand(1) .check((argv) => { diff --git a/lib/report.js b/lib/report.js index cd09eef7..e1671ca0 100644 --- a/lib/report.js +++ b/lib/report.js @@ -2,6 +2,12 @@ const Exclude = require('test-exclude') const libCoverage = require('istanbul-lib-coverage') const libReport = require('istanbul-lib-report') const reports = require('istanbul-reports') +let readFile +try { + ;({ readFile } = require('fs/promises')) +} catch (err) { + ;({ readFile } = require('fs').promises) +} const { readdirSync, readFileSync, statSync } = require('fs') const { isAbsolute, resolve, extname } = require('path') const { pathToFileURL, fileURLToPath } = require('url') @@ -30,7 +36,8 @@ class Report { src, allowExternal = false, skipFull, - excludeNodeModules + excludeNodeModules, + mergeAsync }) { this.reporter = reporter this.reporterOptions = reporterOptions || {} @@ -53,6 +60,7 @@ class Report { this.all = all this.src = this._getSrc(src) this.skipFull = skipFull + this.mergeAsync = mergeAsync } _getSrc (src) { @@ -90,7 +98,13 @@ class Report { if (this._allCoverageFiles) return this._allCoverageFiles const map = libCoverage.createCoverageMap() - const v8ProcessCov = this._getMergedProcessCov() + let v8ProcessCov + + if (this.mergeAsync) { + v8ProcessCov = await this._getMergedProcessCovAsync() + } else { + v8ProcessCov = this._getMergedProcessCov() + } const resultCountPerPath = new Map() const possibleCjsEsmBridges = new Map() @@ -188,43 +202,106 @@ class Report { } if (this.all) { - const emptyReports = [] + const emptyReports = this._includeUncoveredFiles(fileIndex) v8ProcessCovs.unshift({ result: emptyReports }) - const workingDirs = this.src - const { extension } = this.exclude - for (const workingDir of workingDirs) { - this.exclude.globSync(workingDir).forEach((f) => { - const fullPath = resolve(workingDir, f) - if (!fileIndex.has(fullPath)) { - const ext = extname(fullPath) - if (extension.includes(ext)) { - const stat = statSync(fullPath) - const sourceMap = getSourceMapFromFile(fullPath) - if (sourceMap) { - this.sourceMapCache[pathToFileURL(fullPath)] = { data: sourceMap } - } - emptyReports.push({ - scriptId: 0, - url: resolve(fullPath), - functions: [{ - functionName: '(empty-report)', - ranges: [{ - startOffset: 0, - endOffset: stat.size, - count: 0 - }], - isBlockCoverage: true - }] - }) - } + } + + return mergeProcessCovs(v8ProcessCovs) + } + + /** + * Returns the merged V8 process coverage. + * + * It asynchronously and incrementally reads and merges individual process coverages + * generated by Node. This can be used via the `--merge-async` CLI arg. It's intended + * to be used across a large multi-process test run. + * + * @return {ProcessCov} Merged V8 process coverage. + * @private + */ + async _getMergedProcessCovAsync () { + const { mergeProcessCovs } = require('@bcoe/v8-coverage') + const fileIndex = new Set() // Set + let mergedCov = null + for (const file of readdirSync(this.tempDirectory)) { + try { + const rawFile = await readFile( + resolve(this.tempDirectory, file), + 'utf8' + ) + let report = JSON.parse(rawFile) + + if (this._isCoverageObject(report)) { + if (report['source-map-cache']) { + Object.assign(this.sourceMapCache, this._normalizeSourceMapCache(report['source-map-cache'])) } - }) + report = this._normalizeProcessCov(report, fileIndex) + if (mergedCov) { + mergedCov = mergeProcessCovs([mergedCov, report]) + } else { + mergedCov = mergeProcessCovs([report]) + } + } + } catch (err) { + debuglog(`${err.stack}`) } } - return mergeProcessCovs(v8ProcessCovs) + if (this.all) { + const emptyReports = this._includeUncoveredFiles(fileIndex) + const emptyReport = { + result: emptyReports + } + + mergedCov = mergeProcessCovs([emptyReport, mergedCov]) + } + + return mergedCov + } + + /** + * Adds empty coverage reports to account for uncovered/untested code. + * This is only done when the `--all` flag is present. + * + * @param {Set} fileIndex list of files that have coverage + * @returns {Array} list of empty coverage reports + */ + _includeUncoveredFiles (fileIndex) { + const emptyReports = [] + const workingDirs = this.src + const { extension } = this.exclude + for (const workingDir of workingDirs) { + this.exclude.globSync(workingDir).forEach((f) => { + const fullPath = resolve(workingDir, f) + if (!fileIndex.has(fullPath)) { + const ext = extname(fullPath) + if (extension.includes(ext)) { + const stat = statSync(fullPath) + const sourceMap = getSourceMapFromFile(fullPath) + if (sourceMap) { + this.sourceMapCache[pathToFileURL(fullPath)] = { data: sourceMap } + } + emptyReports.push({ + scriptId: 0, + url: resolve(fullPath), + functions: [{ + functionName: '(empty-report)', + ranges: [{ + startOffset: 0, + endOffset: stat.size, + count: 0 + }], + isBlockCoverage: true + }] + }) + } + } + }) + } + + return emptyReports } /** diff --git a/test/fixtures/disable-fs-promises.js b/test/fixtures/disable-fs-promises.js deleted file mode 100644 index 0bbb0bd6..00000000 --- a/test/fixtures/disable-fs-promises.js +++ /dev/null @@ -1,4 +0,0 @@ -const fs = require('fs'); - -Object.defineProperty(fs, 'promises', {value: undefined}); -require('../../bin/c8.js'); diff --git a/test/integration.js b/test/integration.js index 385b3a26..76a244c8 100644 --- a/test/integration.js +++ b/test/integration.js @@ -28,637 +28,682 @@ 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') - ]) - output.toString('utf8').should.matchSnapshot() - }) - - it('supports externally set NODE_V8_COVERAGE', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--clean=false', - nodePath, - require.resolve('./fixtures/normal') - ], { - env: { - NODE_V8_COVERAGE: 'tmp/override' - } - }) - const stats = statSync('tmp/override') - stats.isDirectory().should.equal(true) - output.toString('utf8').should.matchSnapshot() - }) - - it('merges reports from subprocesses together', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/multiple-spawn', - '--clean=false', - nodePath, - require.resolve('./fixtures/multiple-spawn') - ]) - output.toString('utf8').should.matchSnapshot() - }) - - it('allows relative files to be included', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/multiple-spawn-2', - '--omit-relative=false', - '--clean=false', - nodePath, - require.resolve('./fixtures/multiple-spawn') - ], { - env: { NODE_DEBUG: 'c8' } - }) - output.toString('utf8').should.match( - /Error: ENOENT: no such file or directory.*loaders\.js/ - ) - }) - - it('exits with 1 when report output fails', () => { - const { status, stderr } = spawnSync(nodePath, [ - c8Path, - '--clean=false', - '--reporter=unknown', - nodePath, - '--version' - ]) - status.should.equal(1) - stderr.toString().should.match(/Cannot find module 'unknown'/u) - }) - - it('should allow for files outside of cwd', () => { - // Here we nest this test into the report directory making the multidir - // directories outside of cwd. If the `--allowExternal` flag is not provided - // the multidir files will now show up in the file report, even though they were - // required in - const { output, status } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/allowExternal', - '--clean=true', - '--allowExternal', - '--reporter=text', - nodePath, - require.resolve('./fixtures/report/allowExternal.js') - ], { - cwd: dirname(require.resolve('./fixtures/report/allowExternal.js')) - }) - status.should.equal(0) - output.toString('utf8').should.matchSnapshot() - }) - - it('should allow for multiple overrides of src location for --all', () => { - // Here we nest this test into the report directory making the multidir - // directories outside of cwd. Note, that the target srcOverride does not - // require fields from these directories but we want them initialized to 0 - // via --all. As such we --allowExternal and provide multiple --src patterns - // to override cwd. - const { output, status } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=../tmp/src', - '--clean=true', - '--allowExternal', - '--reporter=text', - '--all', - `--src=${dirname(require.resolve('./fixtures/multidir1/file1.js'))}`, - `--src=${dirname(require.resolve('./fixtures/multidir2/file2.js'))}`, - `--src=${dirname(require.resolve('./fixtures/report/srcOverride.js'))}`, - nodePath, - require.resolve('./fixtures/report/srcOverride.js') - ], { - cwd: dirname(require.resolve('./fixtures/report/srcOverride.js')) - }) - status.should.equal(0) - output.toString('utf8').should.matchSnapshot() - }) - - 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/fixtures/*.js"', - '--temp-directory=tmp/check-coverage', - '--lines=70', - '--branches=55', - '--statements=70' - ]) - status.should.equal(0) - output.toString('utf8').should.matchSnapshot() - }) - - it('exits with 1 if coverage is below threshold', () => { - const { output, status } = spawnSync(nodePath, [ - c8Path, - 'check-coverage', - '--exclude="test/*.js"', - '--temp-directory=tmp/check-coverage', - '--lines=101' - ]) - status.should.equal(1) - output.toString('utf8').should.matchSnapshot() - }) - - it('allows threshold to be applied on per-file basis', () => { - const { output, status } = spawnSync(nodePath, [ - c8Path, - 'check-coverage', - '--exclude="test/*.js"', - '--temp-directory=tmp/check-coverage', - '--lines=101', - '--per-file' - ]) - status.should.equal(1) - output.toString('utf8').should.matchSnapshot() - }) - - it('allows --check-coverage when executing script', () => { - const { output, status } = spawnSync(nodePath, [ +;[false, true].forEach((mergeAsync) => { + const title = mergeAsync ? 'c8 mergeAsync' : 'c8' + describe(title, () => { + it('reports coverage for script that exits normally', () => { + const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', + '--temp-directory=tmp/normal', '--clean=false', - '--temp-directory=tmp/check-coverage', - '--lines=101', - '--check-coverage', + `--merge-async=${mergeAsync}`, nodePath, require.resolve('./fixtures/normal') ]) - status.should.equal(1) output.toString('utf8').should.matchSnapshot() }) - it('--100', () => { - const { output, status } = spawnSync(nodePath, [ + it('supports externally set NODE_V8_COVERAGE', () => { + const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/check-coverage', - '--100', + '--clean=true', + `--merge-async=${mergeAsync}`, nodePath, require.resolve('./fixtures/normal') - ]) - - status.should.equal(1) - output.toString('utf8').should.matchSnapshot() - }) - - it('check-coverage command with --100', () => { - const { output, status } = spawnSync(nodePath, [ - c8Path, - 'check-coverage', - '--exclude="test/*.js"', - '--temp-directory=tmp/check-coverage', - '--100' - ]) - status.should.equal(1) + ], { + env: { + NODE_V8_COVERAGE: 'tmp/override' + } + }) + const stats = statSync('tmp/override') + stats.isDirectory().should.equal(true) output.toString('utf8').should.matchSnapshot() }) - }) - describe('report', () => { - before(() => { - spawnSync(nodePath, [ + it('merges reports from subprocesses together', () => { + const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=./tmp/report', + '--temp-directory=tmp/multiple-spawn', '--clean=false', + `--merge-async=${mergeAsync}`, 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() - }) - - it('supports --check-coverage, when generating reports', () => { - const { output, status } = spawnSync(nodePath, [ - c8Path, - 'report', - '--check-coverage', - '--lines=101', - '--exclude="test/*.js"', - '--temp-directory=tmp/report', - '--clean=false' + require.resolve('./fixtures/multiple-spawn') ]) - status.should.equal(1) output.toString('utf8').should.matchSnapshot() }) - }) - describe('ESM Modules', () => { - it('collects coverage for ESM modules', () => { - if (nodeMajorVersion === 10) return + it('allows relative files to be included', () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', + '--temp-directory=tmp/multiple-spawn-2', + '--omit-relative=false', '--clean=false', - '--temp-directory=tmp/esm', + `--merge-async=${mergeAsync}`, nodePath, - '--experimental-modules', - '--no-warnings', - require.resolve('./fixtures/import.mjs') - ]) - output.toString('utf8').should.matchSnapshot() + require.resolve('./fixtures/multiple-spawn') + ], { + env: { NODE_DEBUG: 'c8' } + }) + output.toString('utf8').should.match( + /Error: ENOENT: no such file or directory.*loaders\.js/ + ) }) - }) - describe('/* c8 ignore next */', () => { - it('ignores lines with special comment', () => { - const { output } = spawnSync(nodePath, [ + it('exits with 1 when report output fails', () => { + const { status, stderr } = spawnSync(nodePath, [ c8Path, - '--exclude="test/*.js"', '--clean=false', - '--temp-directory=tmp/special-comment', + '--reporter=unknown', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/c8-ignore-next.js') + '--version' ]) - output.toString('utf8').should.matchSnapshot() + status.should.equal(1) + stderr.toString().should.match(/Cannot find module 'unknown'/u) }) - // see: https://github.com/bcoe/c8/issues/254 - it('does not incorrectly mark previous branch as uncovered (see #254)', () => { - const { output } = spawnSync(nodePath, [ + it('should allow for files outside of cwd', () => { + // Here we nest this test into the report directory making the multidir + // directories outside of cwd. If the `--allowExternal` flag is not provided + // the multidir files will now show up in the file report, even though they were + // required in + const { output, status } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/issue-254', + '--temp-directory=tmp/allowExternal', '--clean=true', + '--allowExternal', '--reporter=text', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/issue-254') - ]) + require.resolve('./fixtures/report/allowExternal.js') + ], { + cwd: dirname(require.resolve('./fixtures/report/allowExternal.js')) + }) + status.should.equal(0) output.toString('utf8').should.matchSnapshot() }) - }) - describe('/* c8 ignore start/stop */', () => { - it('ignores lines with special comment', () => { - const { output } = spawnSync(nodePath, [ + it('should allow for multiple overrides of src location for --all', () => { + // Here we nest this test into the report directory making the multidir + // directories outside of cwd. Note, that the target srcOverride does not + // require fields from these directories but we want them initialized to 0 + // via --all. As such we --allowExternal and provide multiple --src patterns + // to override cwd. + const { output, status } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--clean=false', - '--temp-directory=tmp/start-stop', + '--temp-directory=../tmp/src', + '--clean=true', + '--allowExternal', + '--reporter=text', + '--all', + `--src=${dirname(require.resolve('./fixtures/multidir1/file1.js'))}`, + `--src=${dirname(require.resolve('./fixtures/multidir2/file2.js'))}`, + `--src=${dirname(require.resolve('./fixtures/report/srcOverride.js'))}`, + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/c8-ignore-start-stop.js') - ]) + require.resolve('./fixtures/report/srcOverride.js') + ], { + cwd: dirname(require.resolve('./fixtures/report/srcOverride.js')) + }) + status.should.equal(0) output.toString('utf8').should.matchSnapshot() }) - }) - describe('source-maps', () => { - beforeEach(cb => rimraf('tmp/source-map', cb)) + describe('check-coverage', () => { + before(() => { + spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/check-coverage', + '--clean=false', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/normal') + ]) + }) - describe('TypeScript', () => { - // Bugs: - // closing '}' on `if` is not covered. - it('remaps branches', () => { - const { output } = spawnSync(nodePath, [ + it('exits with 0 if coverage within threshold', () => { + const { output, status } = spawnSync(nodePath, [ c8Path, + 'check-coverage', + '--exclude="test/fixtures/*.js"', + '--temp-directory=tmp/check-coverage', + '--lines=70', + '--branches=55', + '--statements=70', + `--merge-async=${mergeAsync}` + ]) + status.should.equal(0) + output.toString('utf8').should.matchSnapshot() + }) + + it('exits with 1 if coverage is below threshold', () => { + const { output, status } = spawnSync(nodePath, [ + c8Path, + 'check-coverage', '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--temp-directory=tmp/check-coverage', + '--lines=101', + `--merge-async=${mergeAsync}` + ]) + status.should.equal(1) + output.toString('utf8').should.matchSnapshot() + }) + + it('allows threshold to be applied on per-file basis', () => { + const { output, status } = spawnSync(nodePath, [ + c8Path, + 'check-coverage', + '--exclude="test/*.js"', + '--temp-directory=tmp/check-coverage', + '--lines=101', + '--per-file', + `--merge-async=${mergeAsync}` + ]) + status.should.equal(1) + output.toString('utf8').should.matchSnapshot() + }) + + it('allows --check-coverage when executing script', () => { + const { output, status } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--clean=false', + '--temp-directory=tmp/check-coverage', + '--lines=101', + '--check-coverage', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/branches/branches.typescript.js') + require.resolve('./fixtures/normal') ]) + status.should.equal(1) output.toString('utf8').should.matchSnapshot() }) - // Bugs: - // closing '}' on `if` is not covered. - it('remaps classes', () => { - const { output } = spawnSync(nodePath, [ + it('--100', () => { + const { output, status } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--temp-directory=tmp/check-coverage', + '--100', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/classes/classes.typescript.js') + require.resolve('./fixtures/normal') + ]) + + status.should.equal(1) + output.toString('utf8').should.matchSnapshot() + }) + + it('check-coverage command with --100', () => { + const { output, status } = spawnSync(nodePath, [ + c8Path, + 'check-coverage', + '--exclude="test/*.js"', + '--temp-directory=tmp/check-coverage', + '--100', + `--merge-async=${mergeAsync}` ]) + status.should.equal(1) output.toString('utf8').should.matchSnapshot() }) }) - describe('UglifyJS', () => { - // Bugs: - // string in `console.info` shown as uncovered branch. - it('remaps branches', () => { - const { output } = spawnSync(nodePath, [ + describe('report', () => { + before(() => { + spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--temp-directory=./tmp/report', + '--clean=false', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/branches/branches.uglify.js') + 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', + `--merge-async=${mergeAsync}` + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('supports --check-coverage, when generating reports', () => { + const { output, status } = spawnSync(nodePath, [ + c8Path, + 'report', + '--check-coverage', + '--lines=101', + '--exclude="test/*.js"', + '--temp-directory=tmp/report', + '--clean=false', + `--merge-async=${mergeAsync}` ]) + status.should.equal(1) output.toString('utf8').should.matchSnapshot() }) + }) - // Bugs: - // string in `console.info` shown as uncovered branch. - it('remaps classes', () => { + describe('ESM Modules', () => { + it('collects coverage for ESM modules', () => { + if (nodeMajorVersion === 10) return const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--clean=false', + `--merge-async=${mergeAsync}`, + '--temp-directory=tmp/esm', nodePath, - require.resolve('./fixtures/source-maps/classes/classes.uglify.js') + '--experimental-modules', + '--no-warnings', + require.resolve('./fixtures/import.mjs') ]) output.toString('utf8').should.matchSnapshot() }) }) - describe('nyc', () => { - it('remaps branches', () => { + describe('/* c8 ignore next */', () => { + it('ignores lines with special comment', () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--clean=false', + '--temp-directory=tmp/special-comment', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/branches/branches.nyc.js') + require.resolve('./fixtures/c8-ignore-next.js') ]) output.toString('utf8').should.matchSnapshot() }) - it('remaps classes', () => { + // see: https://github.com/bcoe/c8/issues/254 + it('does not incorrectly mark previous branch as uncovered (see #254)', () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', + '--temp-directory=tmp/issue-254', '--clean=true', + '--reporter=text', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/classes/classes.nyc.js') + require.resolve('./fixtures/issue-254') ]) output.toString('utf8').should.matchSnapshot() }) }) - describe('rollup', () => { - it('remaps branches', () => { + + describe('/* c8 ignore start/stop */', () => { + it('ignores lines with special comment', () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--clean=false', + '--temp-directory=tmp/start-stop', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/branches/branches.rollup.js') + require.resolve('./fixtures/c8-ignore-start-stop.js') ]) output.toString('utf8').should.matchSnapshot() }) + }) + + describe('source-maps', () => { + beforeEach(cb => rimraf('tmp/source-map', cb)) + + describe('TypeScript', () => { + // Bugs: + // closing '}' on `if` is not covered. + it('remaps branches', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/branches/branches.typescript.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + // Bugs: + // closing '}' on `if` is not covered. + it('remaps classes', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/classes/classes.typescript.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + }) + + describe('UglifyJS', () => { + // Bugs: + // string in `console.info` shown as uncovered branch. + it('remaps branches', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/branches/branches.uglify.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + // Bugs: + // string in `console.info` shown as uncovered branch. + it('remaps classes', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/classes/classes.uglify.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + }) - it('remaps classes', () => { + describe('nyc', () => { + it('remaps branches', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/branches/branches.nyc.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('remaps classes', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/classes/classes.nyc.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + }) + describe('rollup', () => { + it('remaps branches', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/branches/branches.rollup.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('remaps classes', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/classes/classes.rollup.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + }) + describe('ts-node', () => { + it('reads source-map from cache, and applies to coverage', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + tsNodePath, + require.resolve('./fixtures/ts-node-basic.ts') + ]) + output.toString('utf8').should.matchSnapshot() + }) + }) + // See: https://github.com/bcoe/c8/issues/232 + it("does not attempt to load source map URLs that aren't", () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', '--temp-directory=tmp/source-map', '--clean=true', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/source-maps/classes/classes.rollup.js') + require.resolve('./fixtures/source-maps/fake-source-map.js') ]) output.toString('utf8').should.matchSnapshot() }) }) - describe('ts-node', () => { - it('reads source-map from cache, and applies to coverage', () => { + describe('--all', () => { + it('reports coverage for unloaded js files as 0 for line, branch and function', () => { const { output } = spawnSync(nodePath, [ c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', + '--temp-directory=tmp/vanilla-all', + '--clean=false', + '--all=true', + '--include=test/fixtures/all/vanilla/**/*.js', + '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/all/vanilla/main') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('reports coverage for unloaded transpiled ts files as 0 for line, branch and function', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--temp-directory=tmp/all-ts', + '--clean=false', + '--all=true', + '--include=test/fixtures/all/ts-compiled/**/*.js', + '--exclude="test/*.js"', // add an exclude to avoid default excludes of test/** + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/all/ts-compiled/main.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('reports coverage for unloaded ts files as 0 for line, branch and function when using ts-node', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--temp-directory=tmp/all-ts-node', + '--clean=false', + '--all=true', + '--include=test/fixtures/all/ts-only/**/*.ts', + '--exclude="test/*.js"', // add an exclude to avoid default excludes of test/** + `--merge-async=${mergeAsync}`, tsNodePath, - require.resolve('./fixtures/ts-node-basic.ts') + require.resolve('./fixtures/all/ts-only/main.ts') ]) output.toString('utf8').should.matchSnapshot() }) - }) - // See: https://github.com/bcoe/c8/issues/232 - it("does not attempt to load source map URLs that aren't", () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/source-map', - '--clean=true', - nodePath, - require.resolve('./fixtures/source-maps/fake-source-map.js') - ]) - output.toString('utf8').should.matchSnapshot() - }) - }) - describe('--all', () => { - it('reports coverage for unloaded js files as 0 for line, branch and function', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--temp-directory=tmp/vanilla-all', - '--clean=false', - '--all=true', - '--include=test/fixtures/all/vanilla/**/*.js', - '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** - nodePath, - require.resolve('./fixtures/all/vanilla/main') - ]) - output.toString('utf8').should.matchSnapshot() - }) - it('reports coverage for unloaded transpiled ts files as 0 for line, branch and function', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--temp-directory=tmp/all-ts', - '--clean=false', - '--all=true', - '--include=test/fixtures/all/ts-compiled/**/*.js', - '--exclude="test/*.js"', // add an exclude to avoid default excludes of test/** - nodePath, - require.resolve('./fixtures/all/ts-compiled/main.js') - ]) - output.toString('utf8').should.matchSnapshot() - }) + it('should allow for --all to be used in conjunction with --check-coverage', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--temp-directory=tmp/all-check-coverage', + '--clean=false', + '--check-coverage', + '--lines=100', + '--all=true', + '--include=test/fixtures/all/vanilla/**/*.js', + '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/all/vanilla/main') + ]) + output.toString('utf8').should.matchSnapshot() + }) - it('reports coverage for unloaded ts files as 0 for line, branch and function when using ts-node', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--temp-directory=tmp/all-ts-node', - '--clean=false', - '--all=true', - '--include=test/fixtures/all/ts-only/**/*.ts', - '--exclude="test/*.js"', // add an exclude to avoid default excludes of test/** - tsNodePath, - require.resolve('./fixtures/all/ts-only/main.ts') - ]) - output.toString('utf8').should.matchSnapshot() - }) + it('should allow for --all to be used with the check-coverage command (2 invocations)', () => { + // generate v8 output + spawnSync(nodePath, [ + c8Path, + '--temp-directory=tmp/all-check-coverage-as-command', + '--clean=false', + '--check-coverage', + '--lines=90', + '--all=true', + '--include=test/fixtures/all/vanilla/**/*.js', + '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/all/vanilla/main') + ]) - it('should allow for --all to be used in conjunction with --check-coverage', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--temp-directory=tmp/all-check-coverage', - '--clean=false', - '--check-coverage', - '--lines=100', - '--all=true', - '--include=test/fixtures/all/vanilla/**/*.js', - '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** - nodePath, - require.resolve('./fixtures/all/vanilla/main') - ]) - output.toString('utf8').should.matchSnapshot() + // invoke check-coverage as a command with --all + const { output } = spawnSync(nodePath, [ + c8Path, + 'check-coverage', + '--lines=90', + '--temp-directory=tmp/all-check-coverage-as-command', + '--clean=false', + '--all=true', + '--include=test/fixtures/all/vanilla/**/*.js', + '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** + `--merge-async=${mergeAsync}` + ]) + output.toString('utf8').should.matchSnapshot() + }) }) - - it('should allow for --all to be used with the check-coverage command (2 invocations)', () => { - // generate v8 output + // see: https://github.com/bcoe/c8/issues/149 + it('cobertura report escapes special characters', () => { spawnSync(nodePath, [ c8Path, - '--temp-directory=tmp/all-check-coverage-as-command', - '--clean=false', - '--check-coverage', - '--lines=90', - '--all=true', - '--include=test/fixtures/all/vanilla/**/*.js', - '--exclude=**/*.ts', // add an exclude to avoid default excludes of test/** + '--exclude="test/*.js"', + '--temp-directory=tmp/cobertura', + '--clean=true', + '--reporter=cobertura', + `--merge-async=${mergeAsync}`, nodePath, - require.resolve('./fixtures/all/vanilla/main') - ]) - - // invoke check-coverage as a command with --all - const { output } = spawnSync(nodePath, [ - c8Path, - 'check-coverage', - '--lines=90', - '--temp-directory=tmp/all-check-coverage-as-command', - '--clean=false', - '--all=true', - '--include=test/fixtures/all/vanilla/**/*.js', - '--exclude=**/*.ts' // add an exclude to avoid default excludes of test/** + require.resolve('./fixtures/computed-method') ]) - output.toString('utf8').should.matchSnapshot() - }) - }) - // see: https://github.com/bcoe/c8/issues/149 - it('cobertura report escapes special characters', () => { - spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/cobertura', - '--clean=false', - '--reporter=cobertura', - nodePath, - require.resolve('./fixtures/computed-method') - ]) - const cobertura = readFileSync(resolve(process.cwd(), './coverage/cobertura-coverage.xml'), 'utf8') - .replace(/[0-9]{13,}/, 'nnnn') - .replace(/.*<\/source>/, '/foo/file') - .replace(/\\/g, '/') - cobertura.toString('utf8').should.matchSnapshot() - }) - describe('report', () => { - it('supports reporting on directories outside cwd', () => { - // invoke a script that uses report as an api and supplies src dirs out - // of cwd - const { output } = spawnSync(nodePath, [ - require.resolve('./fixtures/report/report-multi-dir-external.js') - ], { - cwd: dirname(require.resolve('./fixtures/report/report-multi-dir-external.js')) + const cobertura = readFileSync(resolve(process.cwd(), './coverage/cobertura-coverage.xml'), 'utf8') + .replace(/[0-9]{13,}/, 'nnnn') + .replace(/.*<\/source>/, '/foo/file') + .replace(/\\/g, '/') + cobertura.toString('utf8').should.matchSnapshot() + }) + describe('report', () => { + it('supports reporting on directories outside cwd', () => { + // invoke a script that uses report as an api and supplies src dirs out + // of cwd + const { output } = spawnSync(nodePath, [ + require.resolve('./fixtures/report/report-multi-dir-external.js') + ], { + cwd: dirname(require.resolve('./fixtures/report/report-multi-dir-external.js')) + }) + output.toString('utf8').should.matchSnapshot() }) - output.toString('utf8').should.matchSnapshot() - }) - it('supports reporting on single directories outside cwd', () => { - // invoke a script that uses report as an api and supplies src dirs out - // of cwd. - const { output } = spawnSync(nodePath, [ - require.resolve('./fixtures/report/report-single-dir-external.js') - ], { - cwd: dirname(require.resolve('./fixtures/report/report-single-dir-external.js')) + it('supports reporting on single directories outside cwd', () => { + // invoke a script that uses report as an api and supplies src dirs out + // of cwd. + const { output } = spawnSync(nodePath, [ + require.resolve('./fixtures/report/report-single-dir-external.js') + ], { + cwd: dirname(require.resolve('./fixtures/report/report-single-dir-external.js')) + }) + output.toString('utf8').should.matchSnapshot() }) - output.toString('utf8').should.matchSnapshot() }) - }) - it('collects coverage for script with shebang', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/shebang', - '--clean=false', - require.resolve('./fixtures/shebang') - ]) - output.toString('utf8').should.matchSnapshot() - }) - - describe('--exclude-after-remap', () => { - it('applies exclude rules after source-maps are applied', () => { + it('collects coverage for script with shebang', () => { const { output } = spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--exclude="**/branch-1.js"', - '--exclude-after-remap', - '--temp-directory=tmp/source-map', - '--clean=true', - nodePath, - require.resolve('./fixtures/source-maps/branches/branches.rollup.js') + '--temp-directory=tmp/shebang', + '--clean=false', + `--merge-async=${mergeAsync}`, + require.resolve('./fixtures/shebang') ]) output.toString('utf8').should.matchSnapshot() }) - }) - describe('--extension', () => { - it('includes coverage when extensions specified', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--extension=.js', - '--extension=.special', - '--temp-directory=tmp/extension', - '--clean=true', - nodePath, - require.resolve('./fixtures/custom-ext.special') - ]) - output.toString('utf8').should.matchSnapshot() + describe('--exclude-after-remap', () => { + it('applies exclude rules after source-maps are applied', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--exclude="**/branch-1.js"', + '--exclude-after-remap', + '--temp-directory=tmp/source-map', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/source-maps/branches/branches.rollup.js') + ]) + output.toString('utf8').should.matchSnapshot() + }) }) - it('includes coverage when extensions specified with --all', () => { - const { output } = spawnSync(nodePath, [ - c8Path, - '--all', - '--exclude="test/*.js"', - '--extension=.js', - '--extension=.special', - '--temp-directory=tmp/extension', - '--clean=true', - nodePath, - require.resolve('./fixtures/custom-ext.special') - ]) - output.toString('utf8').should.matchSnapshot() + describe('--extension', () => { + it('includes coverage when extensions specified', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--exclude="test/*.js"', + '--extension=.js', + '--extension=.special', + '--temp-directory=tmp/extension', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/custom-ext.special') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('includes coverage when extensions specified with --all', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--all', + '--exclude="test/*.js"', + '--extension=.js', + '--extension=.special', + '--temp-directory=tmp/extension', + '--clean=true', + `--merge-async=${mergeAsync}`, + nodePath, + require.resolve('./fixtures/custom-ext.special') + ]) + output.toString('utf8').should.matchSnapshot() + }) }) }) }) diff --git a/test/integration.js.snap b/test/integration.js.snap index 077acf1e..821d9907 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -156,7 +156,7 @@ hey ---------------------------------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------------------------|---------|----------|---------|---------|------------------- -All files | 1.91 | 12 | 6.25 | 1.91 | +All files | 1.81 | 12.24 | 6.38 | 1.81 | c8 | 0 | 0 | 0 | 0 | index.js | 0 | 0 | 0 | 0 | 1 c8/bin | 0 | 0 | 0 | 0 | @@ -167,20 +167,19 @@ All files | 1.91 | 12 | 6.25 | 1.91 sorter.js | 0 | 0 | 0 | 0 | 1-196 c8/lib | 0 | 0 | 0 | 0 | is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10 - parse-args.js | 0 | 0 | 0 | 0 | 1-218 - report.js | 0 | 0 | 0 | 0 | 1-340 + parse-args.js | 0 | 0 | 0 | 0 | 1-224 + report.js | 0 | 0 | 0 | 0 | 1-417 source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100 c8/lib/commands | 0 | 0 | 0 | 0 | check-coverage.js | 0 | 0 | 0 | 0 | 1-70 - report.js | 0 | 0 | 0 | 0 | 1-41 - c8/test/fixtures | 15.95 | 35.29 | 20 | 15.95 | + report.js | 0 | 0 | 0 | 0 | 1-42 + c8/test/fixtures | 16.3 | 37.5 | 21.42 | 16.3 | async.js | 100 | 100 | 100 | 100 | c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22 c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21 computed-method.js | 0 | 0 | 0 | 0 | 1-15 custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 custom-ext2.special | 0 | 0 | 0 | 0 | 1-24 - disable-fs-promises.js | 0 | 0 | 0 | 0 | 1-4 issue-254.js | 0 | 0 | 0 | 0 | 1-7 multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12 normal.js | 0 | 0 | 0 | 0 | 1-24 @@ -367,6 +366,644 @@ All files | 75 | 50 | 100 | 75 | ," `; +exports[`c8 mergeAsync /* c8 ignore next */ does not incorrectly mark previous branch as uncovered (see #254) 1`] = ` +",--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + issue-254.js | 100 | 100 | 100 | 100 | +--------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync /* c8 ignore next */ ignores lines with special comment 1`] = ` +",covered +covered +-------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------------|---------|----------|---------|---------|------------------- +All files | 90.9 | 100 | 100 | 90.9 | + c8-ignore-next.js | 90.9 | 100 | 100 | 90.9 | 21-22 +-------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync /* 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 mergeAsync --all reports coverage for unloaded js files as 0 for line, branch and function 1`] = ` +",zero +positive +negative +--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 66.66 | 50 | 64.28 | + vanilla | 78.26 | 75 | 100 | 78.26 | + loaded.js | 73.68 | 71.42 | 100 | 73.68 | 4-5,16-18 + main.js | 100 | 100 | 100 | 100 | + vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 +--------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --all reports coverage for unloaded transpiled ts files as 0 for line, branch and function 1`] = ` +",zero +positive +negative +-----------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 57.14 | 50 | 64.28 | + ts-compiled | 78.26 | 66.66 | 100 | 78.26 | + loaded.ts | 73.68 | 66.66 | 100 | 73.68 | 4-5,16-18 + main.ts | 100 | 100 | 100 | 100 | + ts-compiled/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 +-----------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --all reports coverage for unloaded ts files as 0 for line, branch and function when using ts-node 1`] = ` +",zero +positive +negative +--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 57.14 | 50 | 64.28 | + ts-only | 78.26 | 66.66 | 100 | 78.26 | + loaded.ts | 73.68 | 66.66 | 100 | 73.68 | 4-5,16-18 + main.ts | 100 | 100 | 100 | 100 | + ts-only/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 +--------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --all should allow for --all to be used in conjunction with --check-coverage 1`] = ` +",zero +positive +negative +--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 66.66 | 50 | 64.28 | + vanilla | 78.26 | 75 | 100 | 78.26 | + loaded.js | 73.68 | 71.42 | 100 | 73.68 | 4-5,16-18 + main.js | 100 | 100 | 100 | 100 | + vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 +--------------|---------|----------|---------|---------|------------------- +,ERROR: Coverage for lines (64.28%) does not meet global threshold (100%) +ERROR: Coverage for branches (66.66%) does not meet global threshold (82%) +ERROR: Coverage for statements (64.28%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync --all should allow for --all to be used with the check-coverage command (2 invocations) 1`] = ` +",,ERROR: Coverage for lines (64.28%) does not meet global threshold (90%) +ERROR: Coverage for branches (66.66%) does not meet global threshold (82%) +ERROR: Coverage for statements (64.28%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync --exclude-after-remap applies exclude rules after source-maps are applied 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + branch-2.js | 100 | 100 | 100 | 100 | +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --extension includes coverage when extensions specified 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +--------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +--------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --extension includes coverage when extensions specified with --all 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +---------------------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +---------------------------------------|---------|----------|---------|---------|------------------- +All files | 1.81 | 12.24 | 6.38 | 1.81 | + c8 | 0 | 0 | 0 | 0 | + index.js | 0 | 0 | 0 | 0 | 1 + c8/bin | 0 | 0 | 0 | 0 | + c8.js | 0 | 0 | 0 | 0 | 1-52 + c8/coverage | 0 | 0 | 0 | 0 | + block-navigation.js | 0 | 0 | 0 | 0 | 1-87 + prettify.js | 0 | 0 | 0 | 0 | 1-2 + sorter.js | 0 | 0 | 0 | 0 | 1-196 + c8/lib | 0 | 0 | 0 | 0 | + is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10 + parse-args.js | 0 | 0 | 0 | 0 | 1-224 + report.js | 0 | 0 | 0 | 0 | 1-417 + source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100 + c8/lib/commands | 0 | 0 | 0 | 0 | + check-coverage.js | 0 | 0 | 0 | 0 | 1-70 + report.js | 0 | 0 | 0 | 0 | 1-42 + c8/test/fixtures | 16.3 | 37.5 | 21.42 | 16.3 | + async.js | 100 | 100 | 100 | 100 | + c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22 + c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21 + computed-method.js | 0 | 0 | 0 | 0 | 1-15 + custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 + custom-ext2.special | 0 | 0 | 0 | 0 | 1-24 + issue-254.js | 0 | 0 | 0 | 0 | 1-7 + multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12 + normal.js | 0 | 0 | 0 | 0 | 1-24 + shebang.js | 0 | 0 | 0 | 0 | 1-8 + subprocess.js | 0 | 0 | 0 | 0 | 1-15 + c8/test/fixtures/all/ts-compiled | 0 | 0 | 0 | 0 | + loaded.ts | 0 | 0 | 0 | 0 | 1-19 + main.ts | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/ts-compiled/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/all/vanilla | 0 | 0 | 0 | 0 | + loaded.js | 0 | 0 | 0 | 0 | 1-19 + main.js | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/report | 0 | 0 | 0 | 0 | + allowExternal.js | 0 | 0 | 0 | 0 | 1 + report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + srcOverride.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/source-maps | 0 | 0 | 0 | 0 | + branches.js | 0 | 0 | 0 | 0 | 1-20 + fake-source-map.js | 0 | 0 | 0 | 0 | 1-7 + c8/test/fixtures/source-maps/branches | 0 | 0 | 0 | 0 | + branch-1.js | 0 | 0 | 0 | 0 | 1-12 + branch-2.js | 0 | 0 | 0 | 0 | 1-9 + branches.js | 0 | 0 | 0 | 0 | 1-20 + branches.typescript.ts | 0 | 0 | 0 | 0 | 1-25 + c8/test/fixtures/source-maps/classes | 0 | 0 | 0 | 0 | + class-1.js | 0 | 0 | 0 | 0 | 1-5 + class-2.js | 0 | 0 | 0 | 0 | 1-23 + classes.js | 0 | 0 | 0 | 0 | 1-27 + classes.typescript.ts | 0 | 0 | 0 | 0 | 1-33 +---------------------------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync ESM Modules collects coverage for ESM modules 1`] = ` +",bar foo +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 83.33 | 100 | 66.66 | 83.33 | + export.cjs | 100 | 100 | 100 | 100 | + export.mjs | 71.42 | 100 | 50 | 71.42 | 2-3 + import.mjs | 100 | 100 | 100 | 100 | +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync check-coverage --100 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +,ERROR: Coverage for lines (83.33%) does not meet global threshold (100%) +ERROR: Coverage for functions (60%) does not meet global threshold (100%) +ERROR: Coverage for branches (85.71%) does not meet global threshold (100%) +ERROR: Coverage for statements (83.33%) does not meet global threshold (100%) +" +`; + +exports[`c8 mergeAsync check-coverage allows --check-coverage when executing script 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +,ERROR: Coverage for lines (83.33%) does not meet global threshold (101%) +ERROR: Coverage for statements (83.33%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync check-coverage allows threshold to be applied on per-file basis 1`] = ` +",,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 +ERROR: Coverage for branches (66.66%) does not meet threshold (82%) for test/fixtures/normal.js +ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixtures/normal.js +" +`; + +exports[`c8 mergeAsync check-coverage check-coverage command with --100 1`] = ` +",,ERROR: Coverage for lines (83.33%) does not meet global threshold (100%) +ERROR: Coverage for functions (60%) does not meet global threshold (100%) +ERROR: Coverage for branches (85.71%) does not meet global threshold (100%) +ERROR: Coverage for statements (83.33%) does not meet global threshold (100%) +" +`; + +exports[`c8 mergeAsync check-coverage exits with 0 if coverage within threshold 1`] = `",,"`; + +exports[`c8 mergeAsync check-coverage exits with 1 if coverage is below threshold 1`] = ` +",,ERROR: Coverage for lines (83.33%) does not meet global threshold (101%) +ERROR: Coverage for statements (83.33%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync cobertura report escapes special characters 1`] = ` +" + + + + /foo/file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" +`; + +exports[`c8 mergeAsync collects coverage for script with shebang 1`] = ` +",hello world +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 75 | 50 | 100 | 75 | + shebang.js | 75 | 50 | 100 | 75 | 7-8 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync merges reports from subprocesses together 1`] = ` +",first + +second + +-------------------|---------|----------|---------|---------|------------------- +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 mergeAsync report generates report from existing temporary files 1`] = ` +",-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync report supports --check-coverage, when generating reports 1`] = ` +",-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +,ERROR: Coverage for lines (83.33%) does not meet global threshold (101%) +ERROR: Coverage for statements (83.33%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync report supports reporting on directories outside cwd 1`] = ` +",-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 0 | 0 | 0 | 0 | + multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 +-----------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync report supports reporting on single directories outside cwd 1`] = ` +",----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +----------|---------|----------|---------|---------|------------------- +All files | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 +----------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync reports coverage for script that exits normally 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync should allow for files outside of cwd 1`] = ` +",hi +-------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + multidir1 | 100 | 100 | 100 | 100 | + file1.js | 100 | 100 | 100 | 100 | + report | 100 | 100 | 100 | 100 | + allowExternal.js | 100 | 100 | 100 | 100 | +-------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync should allow for multiple overrides of src location for --all 1`] = ` +",hihi +--------------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------------|---------|----------|---------|---------|------------------- +All files | 3.57 | 16.66 | 0 | 3.57 | + multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 + report | 3.84 | 25 | 0 | 3.84 | + allowExternal.js | 0 | 0 | 0 | 0 | 1 + report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + srcOverride.js | 100 | 100 | 100 | 100 | +--------------------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps TypeScript remaps branches 1`] = ` +",reachable +a = true +a = false +------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------------|---------|----------|---------|---------|------------------- +All files | 84 | 50 | 100 | 84 | + branches.typescript.ts | 84 | 50 | 100 | 84 | 7,11-12,18 +------------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps TypeScript remaps classes 1`] = ` +",covered +covered +covered +covered +covered +-----------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------------------|---------|----------|---------|---------|------------------- +All files | 81.81 | 85.71 | 60 | 81.81 | + classes.typescript.ts | 81.81 | 85.71 | 60 | 81.81 | 12-13,21-22,27-28 +-----------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps UglifyJS remaps branches 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 80 | 40 | 100 | 80 | + branches.js | 80 | 40 | 100 | 80 | 2,5-6,13 +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps UglifyJS remaps classes 1`] = ` +",covered +covered +covered +covered +covered +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 85.18 | 80 | 60 | 85.18 | + classes.js | 85.18 | 80 | 60 | 85.18 | 6-7,15,21 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps does not attempt to load source map URLs that aren't 1`] = ` +",--------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------|---------|----------|---------|---------|------------------- +All files | 71.42 | 50 | 100 | 71.42 | + fake-source-map.js | 71.42 | 50 | 100 | 71.42 | 5-6 +--------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps nyc remaps branches 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 80 | 40 | 100 | 80 | + branches.js | 80 | 40 | 100 | 80 | 2,6-7,13 +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps nyc remaps classes 1`] = ` +",covered +covered +covered +covered +covered +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 77.77 | 83.33 | 60 | 77.77 | + classes.js | 77.77 | 83.33 | 60 | 77.77 | 7-8,15-16,21-22 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps rollup remaps branches 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + branch-1.js | 100 | 100 | 100 | 100 | + branch-2.js | 100 | 100 | 100 | 100 | +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps rollup remaps classes 1`] = ` +",covered +covered +covered +covered +covered +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 78.57 | 83.33 | 60 | 78.57 | + class-1.js | 100 | 100 | 100 | 100 | + class-2.js | 73.91 | 83.33 | 60 | 73.91 | 7-8,15-16,21-22 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps ts-node reads source-map from cache, and applies to coverage 1`] = ` +",covered +covered +covered +covered +covered +------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------|---------|----------|---------|---------|------------------- +All files | 88.23 | 83.33 | 80 | 88.23 | + ts-node-basic.ts | 88.23 | 83.33 | 80 | 88.23 | 12-13,28-29 +------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync supports externally set NODE_V8_COVERAGE 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 60 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 merges reports from subprocesses together 1`] = ` ",first diff --git a/test/integration.js_10.snap b/test/integration.js_10.snap index f5305bc5..2e86377b 100644 --- a/test/integration.js_10.snap +++ b/test/integration.js_10.snap @@ -156,7 +156,7 @@ hey ---------------------------------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------------------------|---------|----------|---------|---------|------------------- -All files | 1.91 | 12 | 8.16 | 1.91 | +All files | 1.81 | 12.24 | 8.33 | 1.81 | c8 | 0 | 0 | 0 | 0 | index.js | 0 | 0 | 0 | 0 | 1 c8/bin | 0 | 0 | 0 | 0 | @@ -167,20 +167,19 @@ All files | 1.91 | 12 | 8.16 | 1.91 sorter.js | 0 | 0 | 0 | 0 | 1-196 c8/lib | 0 | 0 | 0 | 0 | is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10 - parse-args.js | 0 | 0 | 0 | 0 | 1-218 - report.js | 0 | 0 | 0 | 0 | 1-340 + parse-args.js | 0 | 0 | 0 | 0 | 1-224 + report.js | 0 | 0 | 0 | 0 | 1-417 source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100 c8/lib/commands | 0 | 0 | 0 | 0 | check-coverage.js | 0 | 0 | 0 | 0 | 1-70 - report.js | 0 | 0 | 0 | 0 | 1-41 - c8/test/fixtures | 15.95 | 35.29 | 25 | 15.95 | + report.js | 0 | 0 | 0 | 0 | 1-42 + c8/test/fixtures | 16.3 | 37.5 | 26.66 | 16.3 | async.js | 100 | 100 | 100 | 100 | c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22 c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21 computed-method.js | 0 | 0 | 0 | 0 | 1-15 custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 custom-ext2.special | 0 | 0 | 0 | 0 | 1-24 - disable-fs-promises.js | 0 | 0 | 0 | 0 | 1-4 issue-254.js | 0 | 0 | 0 | 0 | 1-7 multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12 normal.js | 0 | 0 | 0 | 0 | 1-24 @@ -257,24 +256,24 @@ hey --------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 74.04 | 58.82 | 63.41 | 74.04 | +All files | 71.81 | 57.95 | 61.9 | 71.81 | bin | 78.84 | 60 | 66.66 | 78.84 | c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 - lib | 78.59 | 54.23 | 73.07 | 78.59 | + lib | 75.23 | 53.22 | 70.37 | 75.23 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196 - report.js | 76.17 | 57.89 | 80 | 76.17 | ...284,290-292,313-318,329-330 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 56.09 | 75 | 70.26 | ...361,367-369,390-395,406-407 source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 - lib/commands | 41.44 | 66.66 | 16.66 | 41.44 | + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 - report.js | 80.48 | 62.5 | 50 | 80.48 | 9-10,15-20 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (74.04%) does not meet global threshold (101%) -ERROR: Coverage for branches (58.82%) does not meet global threshold (82%) -ERROR: Coverage for statements (74.04%) does not meet global threshold (95%) +,ERROR: Coverage for lines (71.81%) does not meet global threshold (101%) +ERROR: Coverage for branches (57.95%) does not meet global threshold (82%) +ERROR: Coverage for statements (71.81%) does not meet global threshold (95%) " `; @@ -284,17 +283,17 @@ ERROR: Coverage for branches (60%) does not meet threshold (82%) for bin/c8.js ERROR: Coverage for statements (78.84%) does not meet threshold (95%) for bin/c8.js ERROR: Coverage for lines (18.57%) does not meet threshold (101%) for lib/commands/check-coverage.js ERROR: Coverage for statements (18.57%) does not meet threshold (95%) for lib/commands/check-coverage.js -ERROR: Coverage for lines (80.48%) does not meet threshold (101%) for lib/commands/report.js +ERROR: Coverage for lines (80.95%) does not meet threshold (101%) for lib/commands/report.js ERROR: Coverage for branches (62.5%) does not meet threshold (82%) for lib/commands/report.js -ERROR: Coverage for statements (80.48%) does not meet threshold (95%) for lib/commands/report.js +ERROR: Coverage for statements (80.95%) does not meet threshold (95%) for lib/commands/report.js ERROR: Coverage for lines (90%) does not meet threshold (101%) for lib/is-cjs-esm-bridge.js ERROR: Coverage for branches (25%) does not meet threshold (82%) for lib/is-cjs-esm-bridge.js ERROR: Coverage for statements (90%) does not meet threshold (95%) for lib/is-cjs-esm-bridge.js -ERROR: Coverage for lines (97.24%) does not meet threshold (101%) for lib/parse-args.js +ERROR: Coverage for lines (97.32%) does not meet threshold (101%) for lib/parse-args.js ERROR: Coverage for branches (58.33%) does not meet threshold (82%) for lib/parse-args.js -ERROR: Coverage for lines (76.17%) does not meet threshold (101%) for lib/report.js -ERROR: Coverage for branches (57.89%) does not meet threshold (82%) for lib/report.js -ERROR: Coverage for statements (76.17%) does not meet threshold (95%) for lib/report.js +ERROR: Coverage for lines (70.26%) does not meet threshold (101%) for lib/report.js +ERROR: Coverage for branches (56.09%) does not meet threshold (82%) for lib/report.js +ERROR: Coverage for statements (70.26%) does not meet threshold (95%) for lib/report.js ERROR: Coverage for lines (45%) does not meet threshold (101%) for lib/source-map-from-file.js ERROR: Coverage for statements (45%) does not meet threshold (95%) for lib/source-map-from-file.js ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js @@ -305,19 +304,19 @@ ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixt `; exports[`c8 check-coverage check-coverage command with --100 1`] = ` -",,ERROR: Coverage for lines (77.73%) does not meet global threshold (100%) -ERROR: Coverage for functions (67.44%) does not meet global threshold (100%) -ERROR: Coverage for branches (62.06%) does not meet global threshold (100%) -ERROR: Coverage for statements (77.73%) does not meet global threshold (100%) +",,ERROR: Coverage for lines (75.18%) does not meet global threshold (100%) +ERROR: Coverage for functions (65.9%) does not meet global threshold (100%) +ERROR: Coverage for branches (61.11%) does not meet global threshold (100%) +ERROR: Coverage for statements (75.18%) does not meet global threshold (100%) " `; 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 (74.04%) does not meet global threshold (101%) -ERROR: Coverage for branches (58.82%) does not meet global threshold (82%) -ERROR: Coverage for statements (74.04%) does not meet global threshold (95%) +",,ERROR: Coverage for lines (71.81%) does not meet global threshold (101%) +ERROR: Coverage for branches (57.95%) does not meet global threshold (82%) +ERROR: Coverage for statements (71.81%) does not meet global threshold (95%) " `; @@ -385,6 +384,739 @@ All files | 75 | 50 | 100 | 75 | ," `; +exports[`c8 mergeAsync /* c8 ignore next */ does not incorrectly mark previous branch as uncovered (see #254) 1`] = ` +",--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + issue-254.js | 100 | 100 | 100 | 100 | +--------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync /* c8 ignore next */ ignores lines with special comment 1`] = ` +",covered +covered +--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 71.82 | 57.14 | 62.16 | 71.82 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 75.23 | 51.66 | 70.37 | 75.23 | + is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 53.84 | 75 | 70.26 | ...361,367-369,390-395,406-407 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 90.9 | 100 | 100 | 90.9 | + c8-ignore-next.js | 90.9 | 100 | 100 | 90.9 | 21-22 +--------------------------|---------|----------|---------|---------|-------------------------------- +," +`; + +exports[`c8 mergeAsync /* c8 ignore start/stop */ ignores lines with special comment 1`] = ` +",covered +covered +--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 72 | 55.42 | 62.16 | 72 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 75.23 | 51.66 | 70.37 | 75.23 | + is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 53.84 | 75 | 70.26 | ...361,367-369,390-395,406-407 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 100 | 75 | 100 | 100 | + c8-ignore-start-stop.js | 100 | 75 | 100 | 100 | 2 +--------------------------|---------|----------|---------|---------|-------------------------------- +," +`; + +exports[`c8 mergeAsync --all reports coverage for unloaded js files as 0 for line, branch and function 1`] = ` +",zero +positive +negative +--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 66.66 | 50 | 64.28 | + vanilla | 78.26 | 75 | 100 | 78.26 | + loaded.js | 73.68 | 71.42 | 100 | 73.68 | 4-5,16-18 + main.js | 100 | 100 | 100 | 100 | + vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 +--------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --all reports coverage for unloaded transpiled ts files as 0 for line, branch and function 1`] = ` +",zero +positive +negative +-----------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 57.14 | 50 | 64.28 | + ts-compiled | 78.26 | 66.66 | 100 | 78.26 | + loaded.ts | 73.68 | 66.66 | 100 | 73.68 | 4-5,16-18 + main.ts | 100 | 100 | 100 | 100 | + ts-compiled/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 +-----------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --all reports coverage for unloaded ts files as 0 for line, branch and function when using ts-node 1`] = ` +",zero +positive +negative +--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 75 | 77.77 | 66.66 | 75 | + ts-only | 91.3 | 87.5 | 100 | 91.3 | + loaded.ts | 89.47 | 83.33 | 100 | 89.47 | 8-9 + main.ts | 100 | 100 | 100 | 100 | + ts-only/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 +--------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --all should allow for --all to be used in conjunction with --check-coverage 1`] = ` +",zero +positive +negative +--------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------|---------|----------|---------|---------|------------------- +All files | 64.28 | 66.66 | 50 | 64.28 | + vanilla | 78.26 | 75 | 100 | 78.26 | + loaded.js | 73.68 | 71.42 | 100 | 73.68 | 4-5,16-18 + main.js | 100 | 100 | 100 | 100 | + vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 +--------------|---------|----------|---------|---------|------------------- +,ERROR: Coverage for lines (64.28%) does not meet global threshold (100%) +ERROR: Coverage for branches (66.66%) does not meet global threshold (82%) +ERROR: Coverage for statements (64.28%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync --all should allow for --all to be used with the check-coverage command (2 invocations) 1`] = ` +",,ERROR: Coverage for lines (64.28%) does not meet global threshold (90%) +ERROR: Coverage for branches (66.66%) does not meet global threshold (82%) +ERROR: Coverage for statements (64.28%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync --exclude-after-remap applies exclude rules after source-maps are applied 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + branch-2.js | 100 | 100 | 100 | 100 | +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --extension includes coverage when extensions specified 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +--------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +--------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync --extension includes coverage when extensions specified with --all 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +---------------------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +---------------------------------------|---------|----------|---------|---------|------------------- +All files | 1.81 | 12.24 | 8.33 | 1.81 | + c8 | 0 | 0 | 0 | 0 | + index.js | 0 | 0 | 0 | 0 | 1 + c8/bin | 0 | 0 | 0 | 0 | + c8.js | 0 | 0 | 0 | 0 | 1-52 + c8/coverage | 0 | 0 | 0 | 0 | + block-navigation.js | 0 | 0 | 0 | 0 | 1-87 + prettify.js | 0 | 0 | 0 | 0 | 1-2 + sorter.js | 0 | 0 | 0 | 0 | 1-196 + c8/lib | 0 | 0 | 0 | 0 | + is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10 + parse-args.js | 0 | 0 | 0 | 0 | 1-224 + report.js | 0 | 0 | 0 | 0 | 1-417 + source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100 + c8/lib/commands | 0 | 0 | 0 | 0 | + check-coverage.js | 0 | 0 | 0 | 0 | 1-70 + report.js | 0 | 0 | 0 | 0 | 1-42 + c8/test/fixtures | 16.3 | 37.5 | 26.66 | 16.3 | + async.js | 100 | 100 | 100 | 100 | + c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22 + c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21 + computed-method.js | 0 | 0 | 0 | 0 | 1-15 + custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 + custom-ext2.special | 0 | 0 | 0 | 0 | 1-24 + issue-254.js | 0 | 0 | 0 | 0 | 1-7 + multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12 + normal.js | 0 | 0 | 0 | 0 | 1-24 + shebang.js | 0 | 0 | 0 | 0 | 1-8 + subprocess.js | 0 | 0 | 0 | 0 | 1-15 + c8/test/fixtures/all/ts-compiled | 0 | 0 | 0 | 0 | + loaded.ts | 0 | 0 | 0 | 0 | 1-19 + main.ts | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/ts-compiled/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/all/vanilla | 0 | 0 | 0 | 0 | + loaded.js | 0 | 0 | 0 | 0 | 1-19 + main.js | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/report | 0 | 0 | 0 | 0 | + allowExternal.js | 0 | 0 | 0 | 0 | 1 + report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + srcOverride.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/source-maps | 0 | 0 | 0 | 0 | + branches.js | 0 | 0 | 0 | 0 | 1-20 + fake-source-map.js | 0 | 0 | 0 | 0 | 1-7 + c8/test/fixtures/source-maps/branches | 0 | 0 | 0 | 0 | + branch-1.js | 0 | 0 | 0 | 0 | 1-12 + branch-2.js | 0 | 0 | 0 | 0 | 1-9 + branches.js | 0 | 0 | 0 | 0 | 1-20 + branches.typescript.ts | 0 | 0 | 0 | 0 | 1-25 + c8/test/fixtures/source-maps/classes | 0 | 0 | 0 | 0 | + class-1.js | 0 | 0 | 0 | 0 | 1-5 + class-2.js | 0 | 0 | 0 | 0 | 1-23 + classes.js | 0 | 0 | 0 | 0 | 1-27 + classes.typescript.ts | 0 | 0 | 0 | 0 | 1-33 +---------------------------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync check-coverage --100 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +,ERROR: Coverage for lines (83.33%) does not meet global threshold (100%) +ERROR: Coverage for functions (66.66%) does not meet global threshold (100%) +ERROR: Coverage for branches (85.71%) does not meet global threshold (100%) +ERROR: Coverage for statements (83.33%) does not meet global threshold (100%) +" +`; + +exports[`c8 mergeAsync check-coverage allows --check-coverage when executing script 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 78.33 | 69.64 | 68.18 | 78.33 | + bin | 82.69 | 70 | 66.66 | 82.69 | + c8.js | 82.69 | 70 | 66.66 | 82.69 | 22,27-29,41-43,50-51 + lib | 79.22 | 64.93 | 74.07 | 79.22 | + is-cjs-esm-bridge.js | 90 | 62.5 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 77.45 | 66.07 | 81.25 | 77.45 | ...333,360-361,367-369,390-395 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 68.75 | 83.33 | 50 | 68.75 | + check-coverage.js | 52.85 | 75 | 50 | 52.85 | 9-11,14-36,47-49,61-64 + report.js | 95.23 | 90 | 50 | 95.23 | 9-10 + test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +--------------------------|---------|----------|---------|---------|-------------------------------- +,ERROR: Coverage for lines (78.33%) does not meet global threshold (101%) +ERROR: Coverage for branches (69.64%) does not meet global threshold (82%) +ERROR: Coverage for statements (78.33%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync check-coverage allows threshold to be applied on per-file basis 1`] = ` +",,ERROR: Coverage for lines (82.69%) does not meet threshold (101%) for bin/c8.js +ERROR: Coverage for branches (70%) does not meet threshold (82%) for bin/c8.js +ERROR: Coverage for statements (82.69%) does not meet threshold (95%) for bin/c8.js +ERROR: Coverage for lines (52.85%) does not meet threshold (101%) for lib/commands/check-coverage.js +ERROR: Coverage for branches (75%) does not meet threshold (82%) for lib/commands/check-coverage.js +ERROR: Coverage for statements (52.85%) does not meet threshold (95%) for lib/commands/check-coverage.js +ERROR: Coverage for lines (95.23%) does not meet threshold (101%) for lib/commands/report.js +ERROR: Coverage for lines (90%) does not meet threshold (101%) for lib/is-cjs-esm-bridge.js +ERROR: Coverage for branches (62.5%) does not meet threshold (82%) for lib/is-cjs-esm-bridge.js +ERROR: Coverage for statements (90%) does not meet threshold (95%) for lib/is-cjs-esm-bridge.js +ERROR: Coverage for lines (97.32%) does not meet threshold (101%) for lib/parse-args.js +ERROR: Coverage for branches (58.33%) does not meet threshold (82%) for lib/parse-args.js +ERROR: Coverage for lines (77.45%) does not meet threshold (101%) for lib/report.js +ERROR: Coverage for branches (66.07%) does not meet threshold (82%) for lib/report.js +ERROR: Coverage for statements (77.45%) does not meet threshold (95%) for lib/report.js +ERROR: Coverage for lines (45%) does not meet threshold (101%) for lib/source-map-from-file.js +ERROR: Coverage for statements (45%) does not meet threshold (95%) for lib/source-map-from-file.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 +ERROR: Coverage for branches (66.66%) does not meet threshold (82%) for test/fixtures/normal.js +ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixtures/normal.js +" +`; + +exports[`c8 mergeAsync check-coverage check-coverage command with --100 1`] = ` +",,ERROR: Coverage for lines (75.18%) does not meet global threshold (100%) +ERROR: Coverage for functions (63.63%) does not meet global threshold (100%) +ERROR: Coverage for branches (60.21%) does not meet global threshold (100%) +ERROR: Coverage for statements (75.18%) does not meet global threshold (100%) +" +`; + +exports[`c8 mergeAsync check-coverage exits with 0 if coverage within threshold 1`] = `",,"`; + +exports[`c8 mergeAsync check-coverage exits with 1 if coverage is below threshold 1`] = ` +",,ERROR: Coverage for lines (78.33%) does not meet global threshold (101%) +ERROR: Coverage for branches (69.64%) does not meet global threshold (82%) +ERROR: Coverage for statements (78.33%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync cobertura report escapes special characters 1`] = ` +" + + + + /foo/file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" +`; + +exports[`c8 mergeAsync collects coverage for script with shebang 1`] = ` +",hello world +--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 71.39 | 54.32 | 61.11 | 71.39 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 75.23 | 51.66 | 70.37 | 75.23 | + is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 53.84 | 75 | 70.26 | ...361,367-369,390-395,406-407 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 75 | 50 | 100 | 75 | + shebang.js | 75 | 50 | 100 | 75 | 7-8 +--------------------------|---------|----------|---------|---------|-------------------------------- +," +`; + +exports[`c8 mergeAsync merges reports from subprocesses together 1`] = ` +",first + +second + +--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 72.39 | 64.44 | 63.15 | 72.39 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 75.49 | 61.53 | 70.37 | 75.49 | + is-cjs-esm-bridge.js | 90 | 62.5 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.74 | 61.36 | 75 | 70.74 | ...333,360-361,367-369,390-395 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 100 | 100 | 100 | 100 | + multiple-spawn.js | 100 | 100 | 100 | 100 | + subprocess.js | 100 | 100 | 100 | 100 | +--------------------------|---------|----------|---------|---------|-------------------------------- +," +`; + +exports[`c8 mergeAsync report generates report from existing temporary files 1`] = ` +",--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 74.97 | 65.04 | 64.28 | 74.97 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 79.22 | 63.63 | 74.07 | 79.22 | + is-cjs-esm-bridge.js | 90 | 62.5 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 77.45 | 64.28 | 81.25 | 77.45 | ...333,360-361,367-369,390-395 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +--------------------------|---------|----------|---------|---------|-------------------------------- +," +`; + +exports[`c8 mergeAsync report supports --check-coverage, when generating reports 1`] = ` +",--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 74.97 | 65.04 | 64.28 | 74.97 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 79.22 | 63.63 | 74.07 | 79.22 | + is-cjs-esm-bridge.js | 90 | 62.5 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 77.45 | 64.28 | 81.25 | 77.45 | ...333,360-361,367-369,390-395 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +--------------------------|---------|----------|---------|---------|-------------------------------- +,ERROR: Coverage for lines (74.97%) does not meet global threshold (101%) +ERROR: Coverage for branches (65.04%) does not meet global threshold (82%) +ERROR: Coverage for statements (74.97%) does not meet global threshold (95%) +" +`; + +exports[`c8 mergeAsync report supports reporting on directories outside cwd 1`] = ` +",-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 0 | 0 | 0 | 0 | + multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 +-----------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync report supports reporting on single directories outside cwd 1`] = ` +",----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +----------|---------|----------|---------|---------|------------------- +All files | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 +----------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync reports coverage for script that exits normally 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +--------------------------|---------|----------|---------|---------|-------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------|---------|----------|---------|---------|-------------------------------- +All files | 71.81 | 57.95 | 61.9 | 71.81 | + bin | 78.84 | 60 | 66.66 | 78.84 | + c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 + lib | 75.23 | 53.22 | 70.37 | 75.23 | + is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 56.09 | 75 | 70.26 | ...361,367-369,390-395,406-407 + source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | + check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 + test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +--------------------------|---------|----------|---------|---------|-------------------------------- +," +`; + +exports[`c8 mergeAsync should allow for files outside of cwd 1`] = ` +",hi +-------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + multidir1 | 100 | 100 | 100 | 100 | + file1.js | 100 | 100 | 100 | 100 | + report | 100 | 100 | 100 | 100 | + allowExternal.js | 100 | 100 | 100 | 100 | +-------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync should allow for multiple overrides of src location for --all 1`] = ` +",hihi +--------------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------------------|---------|----------|---------|---------|------------------- +All files | 3.57 | 16.66 | 0 | 3.57 | + multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 + report | 3.84 | 25 | 0 | 3.84 | + allowExternal.js | 0 | 0 | 0 | 0 | 1 + report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + srcOverride.js | 100 | 100 | 100 | 100 | +--------------------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps TypeScript remaps branches 1`] = ` +",reachable +a = true +a = false +------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------------|---------|----------|---------|---------|------------------- +All files | 84 | 57.14 | 100 | 84 | + branches.typescript.ts | 84 | 57.14 | 100 | 84 | 7,11-12,18 +------------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps TypeScript remaps classes 1`] = ` +",covered +covered +covered +covered +covered +-----------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------------------|---------|----------|---------|---------|------------------- +All files | 81.81 | 85.71 | 60 | 81.81 | + classes.typescript.ts | 81.81 | 85.71 | 60 | 81.81 | 12-13,21-22,27-28 +-----------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps UglifyJS remaps branches 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 80 | 50 | 100 | 80 | + branches.js | 80 | 50 | 100 | 80 | 2,5-6,13 +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps UglifyJS remaps classes 1`] = ` +",covered +covered +covered +covered +covered +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 85.18 | 83.33 | 60 | 85.18 | + classes.js | 85.18 | 83.33 | 60 | 85.18 | 6-7,15,21 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps does not attempt to load source map URLs that aren't 1`] = ` +",--------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +--------------------|---------|----------|---------|---------|------------------- +All files | 71.42 | 50 | 100 | 71.42 | + fake-source-map.js | 71.42 | 50 | 100 | 71.42 | 5-6 +--------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps nyc remaps branches 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 80 | 40 | 100 | 80 | + branches.js | 80 | 40 | 100 | 80 | 2,6-7,13 +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps nyc remaps classes 1`] = ` +",covered +covered +covered +covered +covered +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 77.77 | 83.33 | 60 | 77.77 | + classes.js | 77.77 | 83.33 | 60 | 77.77 | 7-8,15-16,21-22 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps rollup remaps branches 1`] = ` +",reachable +a = true +a = false +-------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + branch-1.js | 100 | 100 | 100 | 100 | + branch-2.js | 100 | 100 | 100 | 100 | +-------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps rollup remaps classes 1`] = ` +",covered +covered +covered +covered +covered +------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------|---------|----------|---------|---------|------------------- +All files | 78.57 | 83.33 | 60 | 78.57 | + class-1.js | 100 | 100 | 100 | 100 | + class-2.js | 73.91 | 83.33 | 60 | 73.91 | 7-8,15-16,21-22 +------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync source-maps ts-node reads source-map from cache, and applies to coverage 1`] = ` +",covered +covered +covered +covered +covered +------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +------------------|---------|----------|---------|---------|------------------- +All files | 76.47 | 85.71 | 60 | 76.47 | + ts-node-basic.ts | 76.47 | 85.71 | 60 | 76.47 | 13-16,25-26,33-34 +------------------|---------|----------|---------|---------|------------------- +," +`; + +exports[`c8 mergeAsync supports externally set NODE_V8_COVERAGE 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +-----------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------|---------|----------|---------|---------|------------------- +All files | 83.33 | 85.71 | 66.66 | 83.33 | + async.js | 100 | 100 | 100 | 100 | + normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 +-----------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 merges reports from subprocesses together 1`] = ` ",first @@ -404,17 +1136,17 @@ exports[`c8 report generates report from existing temporary files 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 74.04 | 58.82 | 63.41 | 74.04 | +All files | 71.81 | 57.95 | 61.9 | 71.81 | bin | 78.84 | 60 | 66.66 | 78.84 | c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 - lib | 78.59 | 54.23 | 73.07 | 78.59 | + lib | 75.23 | 53.22 | 70.37 | 75.23 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196 - report.js | 76.17 | 57.89 | 80 | 76.17 | ...284,290-292,313-318,329-330 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 56.09 | 75 | 70.26 | ...361,367-369,390-395,406-407 source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 - lib/commands | 41.44 | 66.66 | 16.66 | 41.44 | + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 - report.js | 80.48 | 62.5 | 50 | 80.48 | 9-10,15-20 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 @@ -426,24 +1158,24 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 74.04 | 58.82 | 63.41 | 74.04 | +All files | 71.81 | 57.95 | 61.9 | 71.81 | bin | 78.84 | 60 | 66.66 | 78.84 | c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 - lib | 78.59 | 54.23 | 73.07 | 78.59 | + lib | 75.23 | 53.22 | 70.37 | 75.23 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196 - report.js | 76.17 | 57.89 | 80 | 76.17 | ...284,290-292,313-318,329-330 + parse-args.js | 97.32 | 58.33 | 100 | 97.32 | 165-166,187-188,201-202 + report.js | 70.26 | 56.09 | 75 | 70.26 | ...361,367-369,390-395,406-407 source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 - lib/commands | 41.44 | 66.66 | 16.66 | 41.44 | + lib/commands | 41.96 | 66.66 | 16.66 | 41.96 | check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 - report.js | 80.48 | 62.5 | 50 | 80.48 | 9-10,15-20 + report.js | 80.95 | 62.5 | 50 | 80.95 | 9-10,15-20 test/fixtures | 83.33 | 85.71 | 66.66 | 83.33 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (74.04%) does not meet global threshold (101%) -ERROR: Coverage for branches (58.82%) does not meet global threshold (82%) -ERROR: Coverage for statements (74.04%) does not meet global threshold (95%) +,ERROR: Coverage for lines (71.81%) does not meet global threshold (101%) +ERROR: Coverage for branches (57.95%) does not meet global threshold (82%) +ERROR: Coverage for statements (71.81%) does not meet global threshold (95%) " `; diff --git a/test/legacy-node.js b/test/legacy-node.js deleted file mode 100644 index c1daeca5..00000000 --- a/test/legacy-node.js +++ /dev/null @@ -1,22 +0,0 @@ -/* global describe, it */ - -const { execFile } = require('child_process') -const { existsSync } = require('fs') -const { join } = require('path') -const { promisify } = require('util') -const c8Path = require.resolve('./fixtures/disable-fs-promises') - -describe('c8 on Node.js < 10', () => { - it('skip coverage', async () => { - const tmp = join(__dirname, '..', 'tmp', 'legacy-nodejs') - - await promisify(execFile)(process.execPath, [ - c8Path, - `--temp-directory=${__filename}`, - process.execPath, - '--version' - ]) - - existsSync(tmp).should.equal(false) - }) -}) diff --git a/test/parse-args.js b/test/parse-args.js index ab8f4d99..004c7241 100644 --- a/test/parse-args.js +++ b/test/parse-args.js @@ -64,4 +64,16 @@ describe('parse-args', () => { argv.functions.should.be.equal(24) }) }) + + describe('--merge-async', () => { + it('should default to false', () => { + const argv = buildYargs().parse(['node', 'c8']) + argv.mergeAsync.should.be.equal(false) + }) + + it('should set to true when flag exists', () => { + const argv = buildYargs().parse(['node', 'c8', '--merge-async']) + argv.mergeAsync.should.be.equal(true) + }) + }) })