-
-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nyc test coverage on branches is not accurate - Seems to be happening with nyc@v15, mocha@10.2.0 and Node@v18.17 #1540
Comments
Seems to me that branch coverage is not getting updated in the nyc |
I think i'm having a similar problem.- Seems that the report branch coverage is not being so accurate since it marks me like i'm not going through certaing lines that i'm already covering. Did you managed to make it work of any way? @varunrajasekhar |
@jjuannn - I think it is the way nyc intercepts the branch coverage etc. I see in the core logic of nyc methods, the branchCoverage Object is unable to retrieve the correct mapping (always shows empty obj for all the files). I couldnt figure out why it does so. May it has something to do with istanbul v/s nyc configurations. Still waiting for response from the @SUPPORTERS, @maintainers |
having exactly same issue |
My issue is resolved , in my case it's caused by @babel/node. which is used to support ES6 modules, but nyc seems confused with some ES6 module. So I have to stick with CommonJS modules, and this not only impact file where it contains ES6 module , but also other files not using ES6.... (so weird)
then I have to change to
|
as @zhangboli51 stated, if i change my exports to use example for import { InvocationResponse } from '@aws-sdk/client-lambda';
import { NotFoundError, ForbiddenError, NotImplementedError, NotSupportedError, InputInvalidError, AppError } from './errors';
class LambdaHelpers {
static parseResponse<T>(res: InvocationResponse): T {
const payload = JsonHelpers.jsonParser<any>(new TextDecoder('utf8').decode(res.Payload));
if (res.FunctionError) {
switch (payload.errorType) {
case NotFoundError.name:
throw new NotFoundError(payload.errorMessage);
case ForbiddenError.name:
throw new ForbiddenError(payload.errorMessage);
case NotImplementedError.name:
throw new NotImplementedError(payload.errorMessage);
case NotSupportedError.name:
throw new NotSupportedError(payload.errorMessage);
case InputInvalidError.name:
throw new InputInvalidError(payload.errorMessage);
}
throw new AppError(payload.errorMessage);
}
return payload;
}
}
class JsonHelpers {
static jsonParser<T>(value: string): T {
return JSON.parse(value, JsonHelpers.jsonReviver);
}
static jsonReviver<T>(key: string, value: any): T {
const dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
if (typeof value === 'string' && dateFormat.test(value)) {
return new Date(value) as any as T;
}
return value;
}
}
module.exports = {
LambdaHelpers,
JsonHelpers
}; |
Link to bug demonstration repository
Expected Behavior
Branch Coverage to be giving more accurate value
Observed Behavior
Branch Coverage seems to be wrong from our end
Troubleshooting steps
cache: false
in my nyc configThe Nyc branch coverage seems to be a bit off to me. I think it is giving me wrong branch coverages.The value and the tests dont seem to be valid to me. We recently upgrade our legacy app from istanbul to nyc. Istanbul had much more valid coverage listed.
Our app is using Node 18.17.0 (cannot downgrade - only option is to upgrade) Nyc - 15.1.0, corresponding mocha => 10.2.0, sinon => 1.17.3 (Since we use sinon stubs)
Our "npm run test" scripts is "test": "nyc node_modules/.bin/mocha -- -u bdd -R spec test/server//.js --exit",
nyc.config.js { "all": true, "include": ["test/server/controllers/.js","test/server/services/.js","test/server/utils/**.js"], "exclude":["test/server/index","test/server/coverage/lcov-report", "target", "server"], "reporter":["html", "cobertura", "text", "text-summary"], "check-coverage": true, "report-dir":"./target/coverage" }
What am I supposed to do on this to have the correct branch coverage ?
I am also attaching the istanbul test report
This one is Istanbul Coverage report
Environment Information
This one is Nyc reportThis one is istanbul report
paste the output here
The text was updated successfully, but these errors were encountered: