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

Coverage Remapping Issue #5151

Closed
Aftabnack opened this issue Dec 21, 2017 · 7 comments
Closed

Coverage Remapping Issue #5151

Aftabnack opened this issue Dec 21, 2017 · 7 comments

Comments

@Aftabnack
Copy link
Contributor

Aftabnack commented Dec 21, 2017

Do you want to request a feature or report a bug?

Unsure Feature

What is the current behavior?

  • Coverage remapping that happens in html lcov-report that gets generated is onto the actual file contents. Need to be able to remap it onto tranformed version of the actual file content.

  • This is my scenario
    screenshot from 2017-12-21 20-53-20

Relevant Preprocessor code

const babelOpts = Object.assign({}, babelConf, {
    plugins: (babelConf && babelConf.plugins) || [],
    presets: ((babelConf && babelConf.presets) || []).concat([jestPreset]),
    retainLines: true,
    sourceMaps: 'inline'
});

module.exports = {
    process(src, filename, config, transformOptions) {
        src = transformJustPhnx(src, true); //Conversion of abstraction syntax to React Code
        const finalOpts = Object.assign(
            {
                filename
            },
            babelOpts
        );
        if (transformOptions && transformOptions.instrument) {
            finalOpts.auxiliaryCommentBefore = ' istanbul ignore next ';
            // Copied from jest-runtime transform.js
            finalOpts.plugins = finalOpts.plugins.concat([
                [
                    babelIstanbulPlugin,
                    {
                        cwd: config.rootDir,
                        exclude: []
                    }
                ]
            ]);
        }

        const transformResult = babelTransform(src, finalOpts); //React code to final output with Sourcemaps.
        return transformResult ? transformResult.code : src;
    },
    canInstrument: true
};

Current output in lcov-report

screenshot from 2017-12-21 20-55-38

Report that is achieved by superimposing it on the intermediate (Currently doing this when running SonarQube on the code)

screenshot from 2017-12-21 20-56-26

What is the expected behavior?

  • Need to be able to remap it onto the intermediate output of my Jest Preprocessor transformations.

Please provide your exact Jest configuration and mention your Jest, node,

yarn/npm version and operating system.

  • Jest : 22.0.1
  • Ubuntu 17.10
  • Node 8.6.0
  • npm 5.6.0
@Aftabnack
Copy link
Contributor Author

  • After doing a little digging myself, found out where exactly to add this to get this to work.
  • This is where the source code gets read for the report.

  • I have tested adding my transformation of the source after that line. It works perfectly.

screenshot from 2017-12-23 03-14-24


  • Now only question remains, is this a valid expectation to provide for sourcecode transformation? If so how do I go about adding a PR for this? Raising a thread on https://github.com/istanbuljs/istanbuljs too

@SimenB
Copy link
Member

SimenB commented Dec 23, 2017

I think being able to say "this is the source code I want instrumented" makes sense.

Are you saying that the fix to your problem must be in Istanbul? There's no change we can make?

@Aftabnack
Copy link
Contributor Author

Aftabnack commented Dec 23, 2017

  • I initially thought that the issue is with Jest, since I was seeing the same thing in error code frame.
  • The fix for the coverage report is in Istanbul, but the error code frame I need to investigate further.
  • The fix is needed for error code frame too, which I suspect would be from jest itself.
  • If it gets added to Istanbul, then the transform for the source code will be an external config. That config for that needs to be allowed to be passed from jest.

@SimenB
Copy link
Member

SimenB commented Dec 23, 2017

We have #5121 for sourcemaps from transforms, I guess the Jest side can be folded into that?

@Aftabnack
Copy link
Contributor Author

My understanding of source maps are very basic. If you are saying the error code frame can be picked up from the source maps then yes, that's what I am asking for! 😄

@SimenB
Copy link
Member

SimenB commented Dec 23, 2017

We should. I'll close this as a dupe, but leave a note over there to test this use case whenever we get around to fixing it. If it does not fix it, we can reopen.

Thanks for the detailed issue and detective work!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants