Skip to content

Commit 60b451c

Browse files
authored
fix: --all now respects --extension flag. (bcoe#357)
1 parent 7540e38 commit 60b451c

File tree

5 files changed

+217
-21
lines changed

5 files changed

+217
-21
lines changed

lib/report.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ class Report {
190190
result: emptyReports
191191
})
192192
const workingDirs = this.src
193+
const { extension } = this.exclude
193194
for (const workingDir of workingDirs) {
194195
this.exclude.globSync(workingDir).forEach((f) => {
195196
const fullPath = resolve(workingDir, f)
196197
if (!fileIndex.has(fullPath)) {
197198
const ext = extname(fullPath)
198-
if (ext === '.js' || ext === '.ts' || ext === '.mjs') {
199+
if (extension.includes(ext)) {
199200
const stat = statSync(fullPath)
200201
const sourceMap = getSourceMapFromFile(fullPath)
201202
if (sourceMap) {

test/fixtures/custom-ext2.special

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require('./async')
2+
3+
console.info('i am a line of code 2')
4+
5+
function apple (awesome) {
6+
if (false || true) {
7+
console.info('what2')
8+
}
9+
if (true || false) {
10+
console.log('hey2')
11+
}
12+
}
13+
14+
function missed () {
15+
16+
}
17+
18+
function missed2 () {
19+
20+
}
21+
22+
apple()
23+
apple()
24+
apple()

test/integration.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,22 @@ describe('c8', () => {
639639
'--extension=.js',
640640
'--extension=.special',
641641
'--temp-directory=tmp/extension',
642-
'--clean=false',
642+
'--clean=true',
643+
nodePath,
644+
require.resolve('./fixtures/custom-ext.special')
645+
])
646+
output.toString('utf8').should.matchSnapshot()
647+
})
648+
649+
it('includes coverage when extensions specified with --all', () => {
650+
const { output } = spawnSync(nodePath, [
651+
c8Path,
652+
'--all',
653+
'--exclude="test/*.js"',
654+
'--extension=.js',
655+
'--extension=.special',
656+
'--temp-directory=tmp/extension',
657+
'--clean=true',
643658
nodePath,
644659
require.resolve('./fixtures/custom-ext.special')
645660
])

test/integration.js.snap

+78
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,84 @@ All files | 83.33 | 85.71 | 60 | 83.33 |
144144
,"
145145
`;
146146

147+
exports[`c8 --extension includes coverage when extensions specified with --all 1`] = `
148+
",hey
149+
i am a line of code
150+
what
151+
hey
152+
what
153+
hey
154+
what
155+
hey
156+
---------------------------------------|---------|----------|---------|---------|-------------------
157+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
158+
---------------------------------------|---------|----------|---------|---------|-------------------
159+
All files | 1.91 | 12 | 6.25 | 1.91 |
160+
c8 | 0 | 0 | 0 | 0 |
161+
index.js | 0 | 0 | 0 | 0 | 1
162+
c8/bin | 0 | 0 | 0 | 0 |
163+
c8.js | 0 | 0 | 0 | 0 | 1-52
164+
c8/coverage | 0 | 0 | 0 | 0 |
165+
block-navigation.js | 0 | 0 | 0 | 0 | 1-87
166+
prettify.js | 0 | 0 | 0 | 0 | 1-2
167+
sorter.js | 0 | 0 | 0 | 0 | 1-196
168+
c8/lib | 0 | 0 | 0 | 0 |
169+
is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10
170+
parse-args.js | 0 | 0 | 0 | 0 | 1-218
171+
report.js | 0 | 0 | 0 | 0 | 1-337
172+
source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100
173+
c8/lib/commands | 0 | 0 | 0 | 0 |
174+
check-coverage.js | 0 | 0 | 0 | 0 | 1-70
175+
report.js | 0 | 0 | 0 | 0 | 1-41
176+
c8/test/fixtures | 15.95 | 35.29 | 20 | 15.95 |
177+
async.js | 100 | 100 | 100 | 100 |
178+
c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22
179+
c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21
180+
computed-method.js | 0 | 0 | 0 | 0 | 1-15
181+
custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20
182+
custom-ext2.special | 0 | 0 | 0 | 0 | 1-24
183+
disable-fs-promises.js | 0 | 0 | 0 | 0 | 1-4
184+
issue-254.js | 0 | 0 | 0 | 0 | 1-7
185+
multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12
186+
normal.js | 0 | 0 | 0 | 0 | 1-24
187+
shebang.js | 0 | 0 | 0 | 0 | 1-8
188+
subprocess.js | 0 | 0 | 0 | 0 | 1-15
189+
c8/test/fixtures/all/ts-compiled | 0 | 0 | 0 | 0 |
190+
loaded.ts | 0 | 0 | 0 | 0 | 1-19
191+
main.ts | 0 | 0 | 0 | 0 | 1-4
192+
c8/test/fixtures/all/ts-compiled/dir | 0 | 0 | 0 | 0 |
193+
unloaded.ts | 0 | 0 | 0 | 0 | 1-5
194+
c8/test/fixtures/all/vanilla | 0 | 0 | 0 | 0 |
195+
loaded.js | 0 | 0 | 0 | 0 | 1-19
196+
main.js | 0 | 0 | 0 | 0 | 1-4
197+
c8/test/fixtures/all/vanilla/dir | 0 | 0 | 0 | 0 |
198+
unloaded.js | 0 | 0 | 0 | 0 | 1-5
199+
c8/test/fixtures/multidir1 | 0 | 0 | 0 | 0 |
200+
file1.js | 0 | 0 | 0 | 0 | 1
201+
c8/test/fixtures/multidir2 | 0 | 0 | 0 | 0 |
202+
file2.js | 0 | 0 | 0 | 0 | 1
203+
c8/test/fixtures/report | 0 | 0 | 0 | 0 |
204+
allowExternal.js | 0 | 0 | 0 | 0 | 1
205+
report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12
206+
report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12
207+
srcOverride.js | 0 | 0 | 0 | 0 | 1
208+
c8/test/fixtures/source-maps | 0 | 0 | 0 | 0 |
209+
branches.js | 0 | 0 | 0 | 0 | 1-20
210+
fake-source-map.js | 0 | 0 | 0 | 0 | 1-7
211+
c8/test/fixtures/source-maps/branches | 0 | 0 | 0 | 0 |
212+
branch-1.js | 0 | 0 | 0 | 0 | 1-12
213+
branch-2.js | 0 | 0 | 0 | 0 | 1-9
214+
branches.js | 0 | 0 | 0 | 0 | 1-20
215+
branches.typescript.ts | 0 | 0 | 0 | 0 | 1-25
216+
c8/test/fixtures/source-maps/classes | 0 | 0 | 0 | 0 |
217+
class-1.js | 0 | 0 | 0 | 0 | 1-5
218+
class-2.js | 0 | 0 | 0 | 0 | 1-23
219+
classes.js | 0 | 0 | 0 | 0 | 1-27
220+
classes.typescript.ts | 0 | 0 | 0 | 0 | 1-33
221+
---------------------------------------|---------|----------|---------|---------|-------------------
222+
,"
223+
`;
224+
147225
exports[`c8 ESM Modules collects coverage for ESM modules 1`] = `
148226
",bar foo
149227
------------|---------|----------|---------|---------|-------------------

0 commit comments

Comments
 (0)