diff --git a/index.d.ts b/index.d.ts index 04f3be6f..9ce05a40 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,7 +17,8 @@ export declare class Report { wrapperLength?: number, resolve?: string, all?: boolean, + src?: Array, + allowExternal: boolean }) - run(): Promise; -} \ No newline at end of file +} diff --git a/lib/commands/report.js b/lib/commands/report.js index b1b2bcb8..766283a3 100644 --- a/lib/commands/report.js +++ b/lib/commands/report.js @@ -20,7 +20,9 @@ exports.outputReport = async function (argv) { resolve: argv.resolve, omitRelative: argv.omitRelative, wrapperLength: argv.wrapperLength, - all: argv.all + all: argv.all, + allowExternal: argv.allowExternal, + src: argv.src }) await report.run() if (argv.checkCoverage) await checkCoverages(argv, report) diff --git a/lib/parse-args.js b/lib/parse-args.js index 5fb599e7..6d12a4bf 100644 --- a/lib/parse-args.js +++ b/lib/parse-args.js @@ -89,6 +89,18 @@ function buildYargs (withCommands = false) { describe: 'supplying --all will cause c8 to consider all src files in the current working directory ' + 'when the determining coverage. Respects include/exclude.' }) + .options('allowExternal', { + default: false, + type: 'boolean', + 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('src', { + default: undefined, + type: 'string', + describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' + + 'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects' + }) .pkgConf('c8') .config(config) .demandCommand(1) diff --git a/lib/report.js b/lib/report.js index 50ba9528..c8593126 100644 --- a/lib/report.js +++ b/lib/report.js @@ -21,7 +21,9 @@ class Report { omitRelative, wrapperLength, resolve: resolvePaths, - all + all, + src, + allowExternal = false }) { this.reporter = reporter this.reportsDirectory = reportsDirectory @@ -30,13 +32,24 @@ class Report { this.resolve = resolvePaths this.exclude = new Exclude({ exclude: exclude, - include: include + include: include, + relativePath: !allowExternal }) this.omitRelative = omitRelative this.sourceMapCache = {} this.wrapperLength = wrapperLength this.all = all - this.src = process.cwd() + this.src = this._getSrc(src) + } + + _getSrc (src) { + if (typeof src === 'string') { + return [src] + } else if (Array.isArray(src)) { + return src + } else { + return [process.cwd()] + } } async run () { @@ -159,33 +172,35 @@ class Report { v8ProcessCovs.unshift({ result: emptyReports }) - const workingDir = process.cwd() - this.exclude.globSync(workingDir).forEach((f) => { - const fullPath = resolve(workingDir, f) - if (!fileIndex.has(fullPath)) { - const ext = extname(f) - if (ext === '.js' || ext === '.ts' || ext === '.mjs') { - const stat = statSync(f) - const sourceMap = getSourceMapFromFile(f) - if (sourceMap !== undefined) { - this.sourceMapCache[`file://${fullPath}`] = { data: JSON.parse(readFileSync(sourceMap).toString()) } + const workingDirs = this.src + 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 (ext === '.js' || ext === '.ts' || ext === '.mjs') { + const stat = statSync(fullPath) + const sourceMap = getSourceMapFromFile(fullPath) + if (sourceMap !== undefined) { + this.sourceMapCache[`file://${fullPath}`] = { data: JSON.parse(readFileSync(sourceMap).toString()) } + } + emptyReports.push({ + scriptId: 0, + url: resolve(fullPath), + functions: [{ + functionName: '(empty-report)', + ranges: [{ + startOffset: 0, + endOffset: stat.size, + count: 0 + }], + isBlockCoverage: true + }] + }) } - emptyReports.push({ - scriptId: 0, - url: resolve(f), - functions: [{ - functionName: '(empty-report)', - ranges: [{ - startOffset: 0, - endOffset: stat.size, - count: 0 - }], - isBlockCoverage: true - }] - }) } - } - }) + }) + } } return mergeProcessCovs(v8ProcessCovs) diff --git a/lib/source-map-from-file.js b/lib/source-map-from-file.js index 8bc97114..1911e11f 100644 --- a/lib/source-map-from-file.js +++ b/lib/source-map-from-file.js @@ -14,10 +14,10 @@ function getSourceMapFromFile (file) { if (results !== null) { const sourceMap = results[results.length - 1].split('=')[1] if (isAbsolute(sourceMap)) { - return sourceMap + return sourceMap.trim() } else { const base = dirname(file) - return join(base, sourceMap) + return join(base, sourceMap).trim() } } } diff --git a/test/fixtures/multidir1/file1.js b/test/fixtures/multidir1/file1.js new file mode 100644 index 00000000..1ac74b42 --- /dev/null +++ b/test/fixtures/multidir1/file1.js @@ -0,0 +1 @@ +console.log("hi") diff --git a/test/fixtures/multidir2/file2.js b/test/fixtures/multidir2/file2.js new file mode 100644 index 00000000..1ac74b42 --- /dev/null +++ b/test/fixtures/multidir2/file2.js @@ -0,0 +1 @@ +console.log("hi") diff --git a/test/fixtures/report/allowExternal.js b/test/fixtures/report/allowExternal.js new file mode 100644 index 00000000..2e8b3043 --- /dev/null +++ b/test/fixtures/report/allowExternal.js @@ -0,0 +1 @@ +require("../multidir1/file1") \ No newline at end of file diff --git a/test/fixtures/report/report-multi-dir-external.js b/test/fixtures/report/report-multi-dir-external.js new file mode 100644 index 00000000..b3ecbb94 --- /dev/null +++ b/test/fixtures/report/report-multi-dir-external.js @@ -0,0 +1,12 @@ +const Report = require('../../../lib/report') +const report = new Report({ + include: ['**/*.js'], + exclude: [], + reporter: ['text'], + tempDirectory: './temp', + omitRelative: true, + all: true, + src: ['../multidir1/', '../multidir2/'], + allowExternal: true +}) +report.run() diff --git a/test/fixtures/report/report-single-dir-external.js b/test/fixtures/report/report-single-dir-external.js new file mode 100644 index 00000000..7ed87f8b --- /dev/null +++ b/test/fixtures/report/report-single-dir-external.js @@ -0,0 +1,12 @@ +const Report = require('../../../lib/report') +const report = new Report({ + include: ['**/*.js'], + exclude: [], + reporter: ['text'], + tempDirectory: './temp', + omitRelative: true, + all: true, + src: '../multidir1/', + allowExternal: true +}) +report.run() diff --git a/test/fixtures/report/srcOverride.js b/test/fixtures/report/srcOverride.js new file mode 100644 index 00000000..abdf9456 --- /dev/null +++ b/test/fixtures/report/srcOverride.js @@ -0,0 +1 @@ +console.log('hihi') \ No newline at end of file diff --git a/test/fixtures/report/temp/coverage.json b/test/fixtures/report/temp/coverage.json new file mode 100644 index 00000000..9632d156 --- /dev/null +++ b/test/fixtures/report/temp/coverage.json @@ -0,0 +1 @@ +{"result":[]} \ No newline at end of file diff --git a/test/fixtures/source-maps/padded.js b/test/fixtures/source-maps/padded.js new file mode 100644 index 00000000..05c8cceb --- /dev/null +++ b/test/fixtures/source-maps/padded.js @@ -0,0 +1,10 @@ +"use strict"; +exports.__esModule = true; +var loaded_1 = require("./loaded"); +console.log(loaded_1["default"](0)); +console.log(loaded_1["default"](1)); +console.log(loaded_1["default"](-1)); +//# sourceMappingURL=padded.js.map + + +//ew extra whitespace ^ diff --git a/test/integration.js b/test/integration.js index 7a2708f1..fe177f69 100644 --- a/test/integration.js +++ b/test/integration.js @@ -4,6 +4,7 @@ const { readFileSync } = require('fs') const { resolve } = require('path') const { spawnSync } = require('child_process') const { statSync } = require('fs') +const { dirname } = require('path') const c8Path = require.resolve('../bin/c8') const nodePath = process.execPath const tsNodePath = './node_modules/.bin/ts-node' @@ -96,6 +97,53 @@ describe('c8', () => { 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 fiels 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, [ @@ -112,10 +160,10 @@ describe('c8', () => { const { output, status } = spawnSync(nodePath, [ c8Path, 'check-coverage', - '--exclude="test/*.js"', + '--exclude="test/fixtures/*.js"', '--temp-directory=tmp/check-coverage', '--lines=70', - '--branches=60', + '--branches=56', '--statements=70' ]) status.should.equal(0) @@ -168,7 +216,7 @@ describe('c8', () => { spawnSync(nodePath, [ c8Path, '--exclude="test/*.js"', - '--temp-directory=tmp/report', + '--temp-directory=./tmp/report', '--clean=false', nodePath, require.resolve('./fixtures/normal') @@ -180,7 +228,7 @@ describe('c8', () => { c8Path, 'report', '--exclude="test/*.js"', - '--temp-directory=tmp/report', + '--temp-directory=./tmp/report', '--clean=false' ]) output.toString('utf8').should.matchSnapshot() @@ -431,7 +479,6 @@ describe('c8', () => { output.toString('utf8').should.matchSnapshot() }) }) - // see: https://github.com/bcoe/c8/issues/149 it('cobertura report escapes special characters', () => { spawnSync(nodePath, [ @@ -449,4 +496,27 @@ describe('c8', () => { .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() + }) + + 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() + }) + }) }) diff --git a/test/integration.js.snap b/test/integration.js.snap index c161c4b0..94a4f80f 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -105,6 +105,20 @@ All files | 83.33 | 100 | 66.67 | 83.33 | ," `; +exports[`c8 can 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 check-coverage allows --check-coverage when executing script 1`] = ` ",hey i am a line of code @@ -230,6 +244,29 @@ ERROR: Coverage for statements (83.33%) does not meet global threshold (96%) " `; +exports[`c8 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 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 reports coverage for script that exits normally 1`] = ` ",hey i am a line of code @@ -249,6 +286,39 @@ All files | 83.33 | 85.71 | 60 | 83.33 | ," `; +exports[`c8 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 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.67 | 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.85 | 25 | 0 | 3.85 | + 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 source-maps TypeScript remaps branches 1`] = ` ",reachable a = true diff --git a/test/integration.js_10.snap b/test/integration.js_10.snap index 7811867e..da34f241 100644 --- a/test/integration.js_10.snap +++ b/test/integration.js_10.snap @@ -6,17 +6,17 @@ covered --------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 76.09 | 62.96 | 67.65 | 76.09 | +All files | 76.53 | 61.9 | 68.57 | 76.53 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81 | 54.9 | 83.33 | 81 | + lib | 81.24 | 53.7 | 84.21 | 81.24 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 95.8 | 45.45 | 100 | 95.8 | 97-98,106-107,120-121 - report.js | 76.14 | 64.52 | 83.33 | 76.14 | ...152,158-189,220-221,249-251 + parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 + report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 - lib/commands | 43.18 | 75 | 16.67 | 43.18 | + lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 - report.js | 92.59 | 71.43 | 50 | 92.59 | 9-10 + report.js | 93.1 | 71.43 | 50 | 93.1 | 9-10 test/fixtures | 86.21 | 91.67 | 71.43 | 86.21 | async.js | 100 | 100 | 100 | 100 | c8-ignore-next.js | 90.91 | 100 | 100 | 90.91 | 21-22 @@ -130,24 +130,24 @@ hey --------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 75.57 | 60.53 | 66.67 | 75.57 | +All files | 76.04 | 59.49 | 67.65 | 76.04 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81 | 54.9 | 83.33 | 81 | + lib | 81.24 | 53.7 | 84.21 | 81.24 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 95.8 | 45.45 | 100 | 95.8 | 97-98,106-107,120-121 - report.js | 76.14 | 64.52 | 83.33 | 76.14 | ...152,158-189,220-221,249-251 + parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 + report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 - lib/commands | 43.18 | 75 | 16.67 | 43.18 | + lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 - report.js | 92.59 | 71.43 | 50 | 92.59 | 9-10 + report.js | 93.1 | 71.43 | 50 | 93.1 | 9-10 test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (75.57%) does not meet global threshold (101%) -ERROR: Coverage for branches (60.53%) does not meet global threshold (82%) -ERROR: Coverage for statements (75.57%) does not meet global threshold (96%) +,ERROR: Coverage for lines (76.04%) does not meet global threshold (101%) +ERROR: Coverage for branches (59.49%) does not meet global threshold (82%) +ERROR: Coverage for statements (76.04%) does not meet global threshold (96%) " `; @@ -157,18 +157,17 @@ ERROR: Coverage for branches (60%) does not meet threshold (82%) for bin/c8.js ERROR: Coverage for statements (78.85%) does not meet threshold (96%) for bin/c8.js ERROR: Coverage for lines (21.31%) does not meet threshold (101%) for lib/commands/check-coverage.js ERROR: Coverage for statements (21.31%) does not meet threshold (96%) for lib/commands/check-coverage.js -ERROR: Coverage for lines (92.59%) does not meet threshold (101%) for lib/commands/report.js +ERROR: Coverage for lines (93.1%) does not meet threshold (101%) for lib/commands/report.js ERROR: Coverage for branches (71.43%) does not meet threshold (82%) for lib/commands/report.js -ERROR: Coverage for statements (92.59%) does not meet threshold (96%) for lib/commands/report.js +ERROR: Coverage for statements (93.1%) does not meet threshold (96%) 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 (96%) for lib/is-cjs-esm-bridge.js -ERROR: Coverage for lines (95.8%) does not meet threshold (101%) for lib/parse-args.js +ERROR: Coverage for lines (96.13%) does not meet threshold (101%) for lib/parse-args.js ERROR: Coverage for branches (45.45%) does not meet threshold (82%) for lib/parse-args.js -ERROR: Coverage for statements (95.8%) does not meet threshold (96%) for lib/parse-args.js -ERROR: Coverage for lines (76.14%) does not meet threshold (101%) for lib/report.js -ERROR: Coverage for branches (64.52%) does not meet threshold (82%) for lib/report.js -ERROR: Coverage for statements (76.14%) does not meet threshold (96%) for lib/report.js +ERROR: Coverage for lines (75.99%) does not meet threshold (101%) for lib/report.js +ERROR: Coverage for branches (61.76%) does not meet threshold (82%) for lib/report.js +ERROR: Coverage for statements (75.99%) does not meet threshold (96%) for lib/report.js ERROR: Coverage for lines (44%) does not meet threshold (101%) for lib/source-map-from-file.js ERROR: Coverage for statements (44%) does not meet threshold (96%) for lib/source-map-from-file.js ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js @@ -181,9 +180,9 @@ ERROR: Coverage for statements (75%) does not meet threshold (96%) for test/fixt 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 (75.57%) does not meet global threshold (101%) -ERROR: Coverage for branches (60.53%) does not meet global threshold (82%) -ERROR: Coverage for statements (75.57%) does not meet global threshold (96%) +",,ERROR: Coverage for lines (76.04%) does not meet global threshold (101%) +ERROR: Coverage for branches (59.49%) does not meet global threshold (82%) +ERROR: Coverage for statements (76.04%) does not meet global threshold (96%) " `; @@ -255,17 +254,17 @@ exports[`c8 report generates report from existing temporary files 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 75.57 | 60.53 | 66.67 | 75.57 | +All files | 76.04 | 59.49 | 67.65 | 76.04 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81 | 54.9 | 83.33 | 81 | + lib | 81.24 | 53.7 | 84.21 | 81.24 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 95.8 | 45.45 | 100 | 95.8 | 97-98,106-107,120-121 - report.js | 76.14 | 64.52 | 83.33 | 76.14 | ...152,158-189,220-221,249-251 + parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 + report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 - lib/commands | 43.18 | 75 | 16.67 | 43.18 | + lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 - report.js | 92.59 | 71.43 | 50 | 92.59 | 9-10 + report.js | 93.1 | 71.43 | 50 | 93.1 | 9-10 test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20 @@ -277,27 +276,50 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 75.57 | 60.53 | 66.67 | 75.57 | +All files | 76.04 | 59.49 | 67.65 | 76.04 | bin | 78.85 | 60 | 66.67 | 78.85 | c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51 - lib | 81 | 54.9 | 83.33 | 81 | + lib | 81.24 | 53.7 | 84.21 | 81.24 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 - parse-args.js | 95.8 | 45.45 | 100 | 95.8 | 97-98,106-107,120-121 - report.js | 76.14 | 64.52 | 83.33 | 76.14 | ...152,158-189,220-221,249-251 + parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133 + report.js | 75.99 | 61.76 | 84.62 | 75.99 | ...165,171-204,235-236,264-266 source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23 - lib/commands | 43.18 | 75 | 16.67 | 43.18 | + lib/commands | 44.44 | 75 | 16.67 | 44.44 | check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61 - report.js | 92.59 | 71.43 | 50 | 92.59 | 9-10 + report.js | 93.1 | 71.43 | 50 | 93.1 | 9-10 test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (75.57%) does not meet global threshold (101%) -ERROR: Coverage for branches (60.53%) does not meet global threshold (82%) -ERROR: Coverage for statements (75.57%) does not meet global threshold (96%) +,ERROR: Coverage for lines (76.04%) does not meet global threshold (101%) +ERROR: Coverage for branches (59.49%) does not meet global threshold (82%) +ERROR: Coverage for statements (76.04%) does not meet global threshold (96%) " `; +exports[`c8 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 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 reports coverage for script that exits normally 1`] = ` ",hey i am a line of code @@ -317,6 +339,39 @@ All files | 83.33 | 85.71 | 66.67 | 83.33 | ," `; +exports[`c8 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 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.67 | 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.85 | 25 | 0 | 3.85 | + 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 source-maps TypeScript remaps branches 1`] = ` ",reachable a = true diff --git a/test/source-map-from-file.js b/test/source-map-from-file.js new file mode 100644 index 00000000..172cd316 --- /dev/null +++ b/test/source-map-from-file.js @@ -0,0 +1,14 @@ +/* global describe, it */ +const getSourceMapFromFile = require('../lib/source-map-from-file') +const assert = require('assert') +const path = require('path') +describe('source-map-from-file', () => { + it('should parse source maps from compiled targets', () => { + const sourceMap = getSourceMapFromFile('./test/fixtures/all/ts-compiled/main.js') + assert.strictEqual(sourceMap, ['test', 'fixtures', 'all', 'ts-compiled', 'main.js.map'].join(path.sep)) + }) + it('should handle extra whitespace characters', () => { + const sourceMap = getSourceMapFromFile('./test/fixtures/source-maps/padded.js') + assert.strictEqual(sourceMap, ['test', 'fixtures', 'source-maps', 'padded.js.map'].join(path.sep)) + }) +})