Skip to content
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

Missing branch coverage in typescript async method #291

Open
RoniSegal opened this issue Feb 12, 2019 · 17 comments
Open

Missing branch coverage in typescript async method #291

RoniSegal opened this issue Feb 12, 2019 · 17 comments

Comments

@RoniSegal
Copy link

I have the bellow method written in typescript and transpiled to es5:

image.

The transpiled code is:

SchedulerController.prototype.pollOnce = function () {
        return __awaiter(this, void 0, void 0, function () {
            var logger, scheduledEvent, err_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        logger = this.logger.withMethod("pollOnce");
                        _a.label = 1;
                    case 1:
                        _a.trys.push([1, 5, , 6]);
                        return [4 /*yield*/, this.getNextScheduledEvent(logger)];
                    case 2:
                        scheduledEvent = _a.sent();
                        if (!scheduledEvent) return [3 /*break*/, 4];
                        return [4 /*yield*/, this.runJob(scheduledEvent)];
                    case 3:
                        _a.sent();
                        _a.label = 4;
                    case 4: return [3 /*break*/, 6];
                    case 5:
                        err_1 = _a.sent();
                        logger.error("Error in iteration", err_1);
                        return [3 /*break*/, 6];
                    case 6: return [2 /*return*/];
                }
            });
        });
    };

The source map data for

 if (!scheduledEvent) return [3 /*break*/, 4];

points to line 126

Expected Behavior

line 126 should considered as branch

Observed Behavior

line 126 considered as statement

@coreyfarrell
Copy link
Member

From what you're showing this line should be considered both a branch if (!scheduledEvent) and a statement return [3 /*break*/, 4];. To triage this issue we will need to see a minimal reproduction. If you create a minimal demo repository showing the build / test process it will help us help you.

@RoniSegal
Copy link
Author

RoniSegal commented Feb 18, 2019

I created a repo with reproduction: https://github.com/RoniSegal/missing-branch-coverage.
you can see that in file 'lib/scheduler-controller.ts' 0 branches reported, but actually it contains 4 'if' and 1 'else'

@RoniSegal
Copy link
Author

Any updates on this?

@JaKXz JaKXz added the invalid label Feb 20, 2019
@JaKXz
Copy link
Member

JaKXz commented Feb 20, 2019

@RoniSegal as Corey mentioned we need to see a minimal reproduction in a public repo. Then we can help investigate.

@coreyfarrell
Copy link
Member

@JaKXz https://github.com/RoniSegal/missing-branch-coverage was provided - the link is easy to miss in @RoniSegal's comment from two days ago.

@RoniSegal
Copy link
Author

@JaKXz sorry for that, I updated the comment and now its more clear

@RoniSegal
Copy link
Author

RoniSegal commented Feb 25, 2019

There is an update on this issue?

@coreyfarrell
Copy link
Member

@RoniSegal I just tried your repo:

git clone https://github.com/RoniSegal/missing-branch-coverage
cd missing-branch-coverage
npm install
npm test

Got the following error:

> nyc --reporter=html mocha tsOutputs/test

Warning: Could not find any test files matching pattern: tsOutputs/test
No test files found
npm ERR! Test failed.  See above for more details.

Please fix this error, once the test is working someone can take a look. Keep in mind this issue will require someone with knowledge of both istanbul and TypeScript, so it may take longer to get help. Any updates will be posted here.

One other suggestion, take a look at @istanbuljs/nyc-config-typescript.

@RoniSegal
Copy link
Author

RoniSegal commented Mar 7, 2019

@coreyfarrell Just updated my repo, it missed npm run build.
Per the other suggestion I must use compiled code that may not use this config

@coreyfarrell
Copy link
Member

I'm able to reproduce this issue now. I checked the the if (event === "failed") branch. tsc translated this to if (event == "failed") at line 70. In the raw coverage data I was able to see that we saw the branch at line 70, we recorded that the tests hit this branch. But then it was not displayed in the final report. I suspect this is showing that something went wrong with source-map remapping, so this is likely a bug in istanbul-lib-source-maps.

@RoniSegal
Copy link
Author

RoniSegal commented Mar 10, 2019

@coreyfarrell thanks for looking into it, should i open a new issue and point it to istanbul-lib-source-map?

@coreyfarrell

This comment has been minimized.

@RoniSegal
Copy link
Author

RoniSegal commented Mar 13, 2019

@coreyfarrell Seems that istanbul-lib-source-maps is part of istanbuljs repo (under packages),
Is it still should be transfered?

@coreyfarrell
Copy link
Member

@RoniSegal that is correct, I got mixed up for some reason thought this was reported against nyc.

@RoniSegal
Copy link
Author

Any updates on this?
Thanks

@coreyfarrell
Copy link
Member

@RoniSegal Sorry there is not, source maps issues are very difficult. If any updates are available they will be posted here.

@nadavye
Copy link

nadavye commented Jan 28, 2020

Hi Guys,
Any update on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants