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

ERROR [karma-server]: UncaughtException #47

Closed
mkollers opened this issue Mar 19, 2020 · 10 comments · Fixed by #49
Closed

ERROR [karma-server]: UncaughtException #47

mkollers opened this issue Mar 19, 2020 · 10 comments · Fixed by #49
Labels
enhancement New feature or request

Comments

@mkollers
Copy link

mkollers commented Mar 19, 2020

Everything works fine, but Karma server crashes during watch mode in an angular project. I have added a log to lib/server.js in karma and found that coverage is undefined:
TypeError: Cannot read property 'XXXX\src\app\app-routing.module.ts' of undefined at XXXX\node_modules\karma-sabarivka-reporter\src\instrumenter.ts:35:18 at Array.forEach (<anonymous>) at addFileListToCoverageData (XXXX\node_modules\karma-sabarivka-reporter\src\instrumenter.ts:32:16) at exports.sabarivkaReporter.Object.defineProperty.value.onBrowserComplete (XXXX\node_modules\karma-sabarivka-reporter\src\instrumenter.ts:16:5) at Server.<anonymous> (XXXX\node_modules\karma\lib\events.js:40:26) at Server.emit (events.js:203:15) at Browser.onComplete (XXXX\node_modules\karma\lib\browser.js:91:20) at Socket.socket.on (XXXX\frontend\node_modules\karma\lib\browser.js:208:44) at Socket.emit (events.js:203:15) at XXXX\node_modules\socket.io\lib\socket.js:528:12 at process._tickCallback (internal/process/next_tick.js:61:11)

I've got an angular project with the following karma config:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-sabarivka-reporter'),
      require('karma-jasmine'),
      require('karma-junit-reporter'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage/XXXX'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    coverageReporter: {
      include: 'src/app/**/!(*.spec|environment*).ts',
    },
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },
    junitReporter: {
      outputDir: 'test-results', // results will be saved as $outputDir/$browserName.xml
      outputFile: 'junit.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
      suite: '', // suite will become the package name attribute in xml testsuite element
      useBrowserName: false, // add browser name to report and classes names
      nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
      classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
      properties: {} // key value pair of properties to add to the <properties> section of the report
    },
    reporters: ['progress', 'kjhtml', 'junit', 'sabarivka'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadlessNoSandbox'],
    singleRun: false,
    restartOnFileChange: true
  });
};
@kopach
Copy link
Owner

kopach commented Mar 19, 2020

Hi @mkollers, thanks for using karma-sabarivka-reporter and this detailed issue request. Could you also update me with following info, so I could reproduce the issue:

  • version of karma
  • version of karma-sabarivka-reporter
  • version of karma-coverage-istanbul-reporter

Thank you

@mkollers
Copy link
Author

Hi @kopach , thanks for the fast response. The issue first appeared with the following versions:

  • 4.4.1 of karma
  • 3.0.0 of karma-sabarivka-reporter
  • 2.1.1 of `karma-coverage-istanbul-reporter``

But I also tested it with 3.1.0 of karma-sabarivka-reporter and had the same issue :)

@kopach
Copy link
Owner

kopach commented Mar 19, 2020

Hi @mkollers, I just was able to reproduce this issue. I assume you're in angular project with angular-cli tool. angular-cli works in that way, that karma-coverage-istanbul-reporter is added to reporters only if --code-coverage CLI param present. So, if you just run your tests like npm run test or ng test - coverage won't be produced. To fix this - make sure to run script like this: npm run test -- --code-coverage or ng test --code-coverage.

Please, let me know if it helped.

In any case, I'll try to update karma-sabarivka-reporter to throw some understandable error for such case

@kopach kopach added the bug Something isn't working label Mar 19, 2020
@albannach7
Copy link

albannach7 commented Mar 19, 2020

I have seen the same issue and found that it happens if I am karma-sabarivka-reporter in more than one karma.conf.js.
I am running ng test across multiple libraries , when I set sabarivka in multiple files I see the above error although the coverage report and test still run fine.
When I only set it for the main project it works fine

@mkollers
Copy link
Author

Hi @mkollers, I just was able to reproduce this issue. I assume you're in angular project with angular-cli tool. angular-cli works in that way, that karma-coverage-istanbul-reporter is added to reporters only if --code-coverage CLI param present. So, if you just run your tests like npm run test or ng test - coverage won't be produced. To fix this - make sure to run script like this: npm run test -- --code-coverage or ng test --code-coverage.

Please, let me know if it helped.

In any case, I'll try to update karma-sabarivka-reporter to throw some understandable error for such case

Hi @kopach, thank you for the fast reply. That should fix it! But if you could improve the karma-sabarivka-reporter in a way, that it would not crash the karma server, it would be awesome.

During the development process, I'd like to disable code coverage and watch my code, which currently breaks because of the karma server crash. I just want to run coverage during CI Builds.

Is this an understandable request, or should I think about a process where I disable karma-sabarivka-reporter in the development process?

@kopach
Copy link
Owner

kopach commented Mar 20, 2020

@mkollers, yes sure. I'll do that still this week.

@kopach
Copy link
Owner

kopach commented Mar 20, 2020

Hi @albannach7, thanks for your feedback. I'll add some warning for such cases. Let's see, if after that you'll still face same issue. I'll inform you once fix is ready.

@kopach kopach added enhancement New feature or request and removed bug Something isn't working labels Mar 20, 2020
@kopach
Copy link
Owner

kopach commented Mar 20, 2020

Hi @mkollers, fix is now available in v3.1.1. From now on karma-sabarivka-reporter won't throw an error but log warning message in case coverage-istanbul isn't available

@kopach
Copy link
Owner

kopach commented Mar 20, 2020

@albannach7, please update also to v3.1.1 and check if this helped for your case. If not - please create separate issue and I'll try to help. Thanks

@mkollers
Copy link
Author

Hi @mkollers, fix is now available in v3.1.1. From now on karma-sabarivka-reporter won't throw an error but log warning message in case coverage-istanbul isn't available

Works like a charm, thank's a lot for the fast resolution :)

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

Successfully merging a pull request may close this issue.

3 participants