c8
c8 copied to clipboard
Line in constructor of class that extends another class, calls super, and has a return statement erroneously marked as uncovered
- Version: v14.15.4
- Platform: Linux 5.4.0-58-generic #64~18.04.1-Ubuntu SMP Wed Dec 9 17:11:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Summary
When:
- class
AextendsBand - class
A’s constructor callssuper()and - class
Aconstructor contains a return statement
Then:
The line containing the closing brace of the constructor method is shown as uncovered by c8.
To reproduce
(Testing with latest c8, tape and tap-nyc in a "type": "module" node project.)
- Create class
Ain A.js:
import B from './B.js'
export default class A extends B {
constructor () {
super()
return
}
}
- Create class
Bin B.js:
export default class B {}
- Create the test in
test.js:
import test from 'tape'
import A from './A.js'
test('bug', t => {
const a = new A()
t.true(a instanceof A, 'the returned object is as expected')
t.end()
})
- Run coverage:
npx c8 node test.js | npx tap-nyc
What should happen
Coverage should be 100%
What actually happens
Class A’s coverage is 66.67%, with line 7 flagged as uncovered.
Workaround
Ignore the return statement and the line after it. e.g., modify the constructor in class A from the above example to match the following:
import B from './B.js'
export default class A extends B {
constructor () {
super()
/* c8 ignore next 2 */
return
}
}