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

KotlinJs Code Coverage #818

Closed
shadowrider opened this issue Apr 19, 2018 · 6 comments
Closed

KotlinJs Code Coverage #818

shadowrider opened this issue Apr 19, 2018 · 6 comments

Comments

@shadowrider
Copy link

I couldn't find anyone trying to use nyc to get code coverage for Kotlin files. I image it would work similar to how it works with TypeScript, where nyc uses source map files. Does anyone know what needs to be done in order for this to work? I would love to contribute to nyc to support this feature, but currently have no idea where to start.

Expected Behavior

Ability to get code coverage for Kotlin files which get transpiled to JS.

Observed Behavior

Coverage summary reports as Unknown%

Things I've tried

Command: nyc mocha path/to/test/bundle.test.js --require=source-map-support/register --recursive
Config:

{
    "tempDirectory": "./coverage/.nyc_output",
    "report-dir": "./coverage",
    "lines": 100,
    "statements": 100,
    "functions": 100,
    "branches": 100,
    "include": [
      "src/main/**/*.kt",
      "../src/main/**/*.kt"
    ],
    "exclude": [
      "**/coverage",
      "**/test"
    ],
    "reporter": [
      "lcov",
      "text-summary"
    ],
    "require": [
    ],
    "extension": [
      ".kt"
    ],
    "cache": true,
    "all": true
  }

If I require babel-register then I get errors as babel tried to go through Kotlin files.

Forensic Information

Operating System: macos 10.12
Environment Information: OpenJDK 1.8.0_162, Kotlin 1.2.30, Node 8.11.1, NPM 5.6, Babel-Core 6.26, Mocha 5.1.1, NYC 11.7.1

@JaKXz
Copy link
Member

JaKXz commented Apr 19, 2018

Do you have an example repo to reproduce this? :)

From what you've shown, this is totally what I would try as well but I've never worked with KotlinJs before

@shadowrider
Copy link
Author

Would you like me to put one together? It takes a few minutes to update js/package.json in https://github.com/elizarov/KotlinMultiplatformPlayground

@Snipx
Copy link

Snipx commented May 7, 2018

Same issue here. I've been trying to debug the root cause and for now I am inclined to think the problem is somehow hidden in source mapping. But not sure yet if it's indeed the root cause and which side causes the problem. Have you had any success with the problem, @shadowrider ?

UPD: The correspondence between JS code and Kotlin code is quite tricky. Sourcemap generated by Kotlin is not ideal either. This results in failure to map JS code to Kotlin sources correctly. In particular, this condition in source-map module causes failure in fetching source lines in most cases:

https://github.com/mozilla/source-map/blob/75663e0187002920ad98ed1de21e54cb85114609/lib/source-map-consumer.js#L616

It seems there is a similar issue already filed for TypeScript: mozilla/source-map#261

Meanwhile, I think a fix can be done in instanbuljs: if we take a look at

https://github.com/istanbuljs/istanbuljs/blob/ac824a46b25a815977394d96843a31657a2be77b/packages/istanbul-lib-source-maps/lib/transformer.js#L32

we can see that iterating over line numbers until sourceMap.originalPositionFor(location.start) returns something and doing the same for sourceMap.originalPositionFor(location.end) but iterating backwards can probably find us the piece of original source code we are interested in.

To be even more precise, I think getMapping should return a collection of pieces of original source code that correspond to the location in the original file. Because if position A in the generated code maps to position X in the original code and position B in the generated code maps to position Y in the original code, this does not necessarily mean that everything between A and B maps to code between X and Y, right? There might be something else between X and Y as well in the general case.
What do you think, @JaKXz ?

@JaKXz
Copy link
Member

JaKXz commented Jan 30, 2019

@shadowrider sorry for dropping this for so long. Yes I would love to see a small demo repo to try things out on.

My question is what is the/is there a babel equivalent for Kotlin? If your test runner is executing on transpiled js files with sourcemaps, then nyc should be able to map them back to the original source files. My first stab-in-the-dark guess would be to remove the extension: [] config, and point nyc to the transpiled js and see if you can get coverage on those files (messy as it might be) as a first step.

cc @coreyfarrell any thoughts on this, specifically @Snipx's question?

@stale
Copy link

stale bot commented Mar 31, 2019

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.

@stale stale bot added the stale label Mar 31, 2019
@stale stale bot closed this as completed Apr 7, 2019
@darran-kelinske-fivestars

I am interested in pursuing this again. Did anyone make any progress that was undocumented?

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