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 configuration with fast run and debug #183

Open
segrey opened this issue Sep 1, 2015 · 4 comments
Open

Coverage configuration with fast run and debug #183

segrey opened this issue Sep 1, 2015 · 4 comments
Labels

Comments

@segrey
Copy link

segrey commented Sep 1, 2015

Related discussion karma-runner/karma#630

As expected coverage slows down test run and makes debugging impossible.
The workaround is to maintain two configs - the first one with coverage configured, and the second without coverage.
To improve the situation, there is a feature that allows external integrations (e.g. IDE) to turn off coverage preprocessor by removing coverage reporter: https://github.com/karma-runner/karma-coverage/blob/v0.5.1/lib/preprocessor.js#L54
This feature has been using by IntelliJ integration until a configuration that need coverage preprocessor for test run has emerged: https://github.com/karma-runner/karma-coverage/blob/v0.5.1/examples/coffee/karma.conf.coffee

Now IntelliJ uses a new trick to perform "Run", "Debug" and "Run with Coverage" actions with single karma.conf.js. However, it expects one thing from users - they should remove coverage reporter if coverage preprocessor is not needed for test run (still common use case, IMO):

The downsides of the current approach:

  • Undiscoverable for users
  • Coverage won't be gathered if tests are run outside of IntelliJ, e.g. in Terminal

It'd be appreciated if it would be possible to improve the situation. A possible solution could be changing current coffeescript recommended configuration by making it possible to run tests without required coverage preprocessor. Also that would speed up tests.
Thanks.

@segrey
Copy link
Author

segrey commented Sep 1, 2015

Related WebStorm issue: https://youtrack.jetbrains.com/issue/WEB-17537

@dignifiedquire
Copy link
Member

I'm sorry, maybe I'm being thick but what exactly would you like to see ideally in terms of features from karma/karma-coverage?

@segrey
Copy link
Author

segrey commented Sep 7, 2015

No problem. Generally, I would like to see a clear way that would allow to run(fast)/debug/run-with-coverage using single configuration file. Previously, there was some way, but as it turned out that way does not play well with recommended coffee configuration. For example, the fix could be in changing this recommended configuration (not sure it's the best solution).

@segrey
Copy link
Author

segrey commented Dec 29, 2015

@dignifiedquire I've changed slightly how IntelliJ integration disables coverage to have faster test runs/debug capabilities.
Could you please take a look at karma-runner/karma-intellij@7b5ab8f and let me your opinion on this. Personally, I think that checking for instrument and instruments keys is a bit odd and fragile, but it allows to fix all known cases. Probably, it can be improved somehow.

New logic:

  if (canCoverageBeDisabledSafely(config.coverageReporter)) {
    var ind = reporters.indexOf(karmaCoverageReporterName);
    if (ind >= 0) {
      reporters.splice(ind, 1);
      console.log('IntelliJ integration disabled coverage for faster run and debug capabilities');
    }
  }

/**
 * @param {Object} coverageReporter
 * @returns {boolean} true if tests can be successfully run without coverage reporter and preprocessor
 */
function canCoverageBeDisabledSafely(coverageReporter) {
  return coverageReporter == null || (
      !Object.prototype.hasOwnProperty.call(coverageReporter, 'instrumenter') &&
      !Object.prototype.hasOwnProperty.call(coverageReporter, 'instrumenters')
    );
}

This logic tries to preserve coverage reporter for configurations, like in https://github.com/karma-runner/karma-coverage/blob/v0.5.3/examples/coffee/karma.conf.coffee, where tests do not run without coverage. But for majority of karma test configurations, where tests can run successfully without coverage, this logic will disable coverage resulting in faster test runs and having debug capability.

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

No branches or pull requests

2 participants