Open RonanQuigley opened 6 years ago
any updates ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
was this issue solved?
I suspect this is caused by another transformation injecting a branch and producing source-maps pointing the branch to the original code. This sometimes happens when transpiling code and is outside our control.
IMO, this issue should be resolved. I checked the transpiled code from TS and no else was added... It looks like a bug.
Was anyone able to resolve this?
I have this same issue with vanilla node code... no exports, no transpiling. I confirmed without a doubt that the if path is taken (my tests wouldn't pass otherwise, but I also threw in a console.log to ensure I wasn't crazy).
if (this.roles) {
roles = this.roles.map((role) => {
if (typeof role === 'string')
return role;
else if (role instanceof Role) // <<----- claims that this else path is never taken... but it most certainly is!
return role.name;
});
}
same thing happening on my imported file. ( jest test )
content of lambda_shared_folder/error
import { createSlackLogger } from "lambda_shared_folder/sendMessageToSlack";
import lambda from "aws-lambda";
export const createThrowError = (functionName: string) =>
async ({
errorName,
context,
sendSlackNotification = true,
}: {
errorName: string,
sendSlackNotification?: boolean
context: lambda.Context;
}) => {
const fullErrorName = `${functionName}_${errorName}`
if(sendSlackNotification){
const { logGroupName , logStreamName } = context
const slackLogger = createSlackLogger({
logGroupName,
logStreamName,
})
await slackLogger({ type: "ERROR", message: fullErrorName})
}
throw new Error(fullErrorName);
}
If I comment out if
part in imported file, it passes.
import { createSlackLogger } from "lambda_shared_folder/sendMessageToSlack";
import lambda from "aws-lambda";
export const createThrowError = (functionName: string) =>
async ({
errorName,
context,
sendSlackNotification = true,
}: {
errorName: string,
sendSlackNotification?: boolean
context: lambda.Context;
}) => {
const fullErrorName = `${functionName}_${errorName}`
// if(sendSlackNotification){
// const { logGroupName , logStreamName } = context
// const slackLogger = createSlackLogger({
// logGroupName,
// logStreamName,
// })
// await slackLogger({ type: "ERROR", message: fullErrorName})
// }
throw new Error(fullErrorName);
}
I don't think it should check content of imported file
Not sure it helps.
For temporary solution adding this code to jest.config.js
fixed problem.
jest.config.js
module.exports = {
...
transform: {
".+\\.(t|j)sx?$": [
"@swc/jest",
{
sourceMaps: true, // エラーを見やすくする( 有効じゃないと内容がズレて表示されます )
module: {
type: "commonjs", // 出力するファイルをcommonjsとする
},
jsc: {
parser: {
syntax: "typescript", // ソースコードをtypescriptとしてパースする
tsx: true, // jsx記法を許可する
},
transform: {
react: {
// 必須。省略すると "ReferenceError: React is not defined" が発生します
runtime: "automatic",
},
},
},
},
],
},
...
}
I'm not sure if this is a bug with babel-plugin-istanbul (if it's best to post there just let me know), nyc or just a misconfiguration issue I've missed, but when setting up a new project I've now encountered the following:
Expected Behavior
Coverage should report 100% when using ES6 imports for the test code below.
Observed Behavior
See the images, but the reporter seems to think that there are else branches when there isn't any. It also says the statement is not covered.
Bonus Points! Code (or Repository) that Reproduces Issue
This is using ES6 imports:
Produces the following:
It also happens if you use default exports.
For module.exports, coverage is correct
Forensic Information
Operating System: Windows 10 Environment Information: npm : 6.0.1 node : 10.1.0 nyc : 12.02 babel-plugin-istanbul : 4.1.6
This is the .babelrc.js
and this is the .nycrc:
I've also tried adding the instruments and sourceMap options to my package.json but that just causes the coverage to report back as empty. I'm using Mocha as my test runner.