Closed silkentrance closed 8 years ago
Ah, I think I found out why this happens. I am using babel 6.x here and there is some weird stuff going on with the comments when transpiling the sources.
I had to move the ignore comment to the top of the class declaration, sigh. This makes abstract classes with methods that actually do something very hard to generate proper coverage for or fail the build if the coverage for these methods is not being accounted for...
/* istanbul ignore next */
class AbstractBase {
/**
* @abstract
*/
meth() {}
}
Hey, found a yet different solution, perhaps this one is worth noting down in the FAQ or documentation?
It also applies to normal methods that should not be considered when calculating the coverage
class AbstractBase {
/**
* @abstract
*/
/* istanbul ignore next */ meth() {}
}
The comment must stand right next to the method's name. Otherwise the association will be lost in the transpiled code.
But alas, this only works for the first method so commented. The comment of a second method will be moved and can no longer be associated with the method.
(0, _createClass3.default)(AbstractInjector, [{
key: 'canInject',
/**
* Returns true whether this is able to handle the injection request.
*
* @abstract
* @param {TargetType} target - the target object or function
* @param {String} attr - the target's attribute
* @param {DescriptorType} descriptor - the descriptor
* @returns {Boolean} - true whether this can handle the request,
* false otherwise
*/
/*eslint no-unused-vars:0*/
/* istanbul ignore next */value: function canInject(target, attr, descriptor) {}
/**
* Instructs this to inject according to the specified injection descriptor.
*
* @abstract
* @param {InjectionDescriptor} injectionDescriptor - the injection descriptor
* @throws {InjectionError}
* @returns {void}
*/
/*eslint no-unused-vars:0*/
/* istanbul ignore next */
}, {
key: 'inject',
value: function inject(injectionDescriptor) {}
}]);
I suppose that this is a bug in the transpiler.
See https://phabricator.babeljs.io/T7189 for the babel issue generated from this.
While having to move the comment right in front the method identifier seems to be a bug in istanbul, sigh...
And here is the issue reported against istanbul https://github.com/gotwarlost/istanbul/issues/561
This ignore issue has been around for a long time:
I can try updating the Istanbul version to see if that solves the ignore issue though. I'll ping you here when that is done.
@jmcriffey this would be great, thank you!
@silkentrance babel-istanbul
version 0.7.0 is now using the latest version of istanbul
. If that doesn't fix the ignore issues, unfortunately you'll have to put your comments in a spot that won't be missed by istanbul
.
Thanks again for updating istanbul. It did not fix the issue as it is babel transpiler related but it might fix other issues :+1:
This happens with babel-istanbul@0.6.0
I have a class such as
When generating coverage data for the classes under test that derive from that abstract base, none of them will actually call upon
super.meth()
because it actually does nothing.In the generated coverage report, the method is reported and decreases overall coverage.
And even using
/* istanbul ignore next */
will not instruct istanbul to simply ignore the statement.Am I doing something wrong here?