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 Reporting from OPA5#iStartMyAppInAFrame() #138

Closed
LukasHeimann opened this issue Dec 10, 2019 · 6 comments · Fixed by #194
Closed

Coverage Reporting from OPA5#iStartMyAppInAFrame() #138

LukasHeimann opened this issue Dec 10, 2019 · 6 comments · Fixed by #194

Comments

@LukasHeimann
Copy link

Hi experts,

in my karma config, I added the basic options to get coverage reporting to work:

        preprocessors: {
          'webapp/{!(test)/**/,}*.js': ['coverage']
        },
// ...
        coverageReporter: {
          dir: initialDirectory + '/target/report',
          includeAllSources: true,
          reporters: [
            { type: 'html', subdir: 'coverage'}
          ]
        },

My tests are currently mostly OPA5, and as i need to run everything inside an flpSandbox, I start my app in an IFrame using OPA5#iStartMyAppInAFrame(). However, it seems like the coverage now is not reported correctly, as everything that happens within the IFrame is not covered.

I only found this official (?) blogpost regarding the topic. However, it seems to use deprecated features of UI5 (jQuery.sap.require()), uses features I have never before used (sap.ui.qunit.qunit-coverage), and it features a workaround for reporting out of the IFrame involving manually monkey-patching window.eval.

Are there better ways to get this to work? Am I missing some option in karma-ui5? Or is this something I'd better address towards UI5 directly?

I'm testing a UI5 application in script mode.

Thank you very much for your help!
Kind regards
Lukas

@matz3
Copy link
Member

matz3 commented Dec 16, 2019

This is a known gap, which is also mentioned in the UI5 Dev Guide (https://ui5.sap.com/#/topic/ae448243822448d8ba04b4784f4b09a0.html).

While the solution from the blog post might work, it is not recommended from our side and might break in future.

A better solution would be to either have an additional preprocessor or to extend the coverage preprocessor to add some more code that passes the coverage object from the parent to the frame.
Also see istanbuljs/istanbuljs#199.

This is planned to be addressed (no concrete timeline).

(Internal reference CPOUI5FOUNDATION-44)

@LukasHeimann
Copy link
Author

Hi @matz3, thanks for sharing the information!

I didn't know there was information about this in the UI5 SDK, sorry for having missed that.
For now, the coverage isn't a major blocker for me, so I'll stay subscribed and wait until code coverage in iFrames is officially supported by you and the team :)

Thank you very much for your work!
Kind regards
Lukas

@shahzeb79
Copy link
Contributor

@matz3 Is code coverage now supported? anyupdates?

@RandomByte
Copy link
Member

As discussed with @shahzeb79 there are no updates as of today. We are planning to work on this soon(™️). Possibly @ecker can provide a more precise timeline.

@LukasHeimann
Copy link
Author

LukasHeimann commented Oct 6, 2020

Hi @matz3,

I just came around trying this out in our project. As we have karma integrated with grunt, the configuration feels a bit clunky:

  const karmaConfig = grunt.config.get("karma.options");
  require("karma-ui5/helper").configureIframeCoverage(karmaConfig);
  grunt.config.set("karma.options", karmaConfig);

I don't know it you want to consider simplifying this a bit, or at least add it to the documentation, because this is non-obvious and I'm not sure I've covered all necessary cases.

@matz3
Copy link
Member

matz3 commented Oct 22, 2020

As the execution order of plugins is not defined/guaranteed, we can't do the coverage configuration enhancement within our plugin. That's why we needed to introduce a separate helper module.

But we haven't looked into how this would be done with grunt or other task runners.
Mainly because we currently only use karma directly, so there is no need.

Feel free to create a PR to add documentation to the README and/or to enhance the configureIframeCoverage function to better work with grunt.

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

Successfully merging a pull request may close this issue.

4 participants