karma-runner / karma-teamcity-reporter

A Karma plugin. Report results for Teamcity CI.
MIT License
34 stars 47 forks source link

TypeError: Cannot read property 'log' of undefined #86

Open tmjeee opened 5 years ago

tmjeee commented 5 years ago
07 11 2018 10:00:32.674:ERROR [karma-server]: TypeError: Cannot read property 'log' of undefined
    at TeamcityReporter.getLog (C:\repos\bitbucket\iicewebmdm\node_modules\karma-teamcity-reporter\index.js:126:29)
    at TeamcityReporter.specSuccess (C:\repos\bitbucket\iicewebmdm\node_modules\karma-teamcity-reporter\index.js:81:20)

karma-teamcity-reporter: 1.1.0 karma: 3.1.1 Angular: 7 karma-phantomjs-launcher: 1.0.4

I'm getting this error pretty consistently when running angular tests in parallel off phantomjs. Is this an issue? Any possible fixes / workaround?

Pringels commented 5 years ago

+1 Also experiencing this. Although it seems flaky.

In my case I am not using phantomjs at all but rather browserstack.

hazems commented 5 years ago

+1, this is an issue for me.

johnjbarton commented 5 years ago

Setting logLevel DEBUG http://karma-runner.github.io/3.0/config/configuration-file.html might help you debug this (I don't use this plugin).

nickbullock commented 4 years ago

Still facing it with karma-parallel. logLevel DEBUG didn't help, but this comment did https://github.com/karma-runner/karma/issues/3342#issuecomment-513018754

andy-maca commented 4 years ago

Got the same issue with ChromeHeadless,

10 07 2020 12:24:59.551:ERROR [karma-server]: TypeError: Cannot read property 'log' of undefined
    at TeamcityReporter.getLog (X:\work\1536afa0d351403c\Web\node_modules\karma-teamcity-reporter\index.js:126:29)
    at TeamcityReporter.specSuccess (X:\work\1536afa0d351403c\Web\node_modules\karma-teamcity-reporter\index.js:81:20)
    at TeamcityReporter.BaseReporter.onSpecComplete (X:\work\1536afa0d351403c\Web\node_modules\karma\lib\reporters\base.js:107:12)
    at Server.<anonymous> (X:\work\1536afa0d351403c\Web\node_modules\karma\lib\events.js:40:26)
    at Server.emit (events.js:187:15)
    at Browser.onResult (X:\work\1536afa0d351403c\Web\node_modules\karma\lib\browser.js:159:20)
    at Socket.socket.on (X:\work\1536afa0d351403c\Web\node_modules\karma\lib\browser.js:209:42)
    at Socket.emit (events.js:182:13)
    at X:\work\1536afa0d351403c\Web\node_modules\socket.io\lib\socket.js:528:12
    at process._tickCallback (internal/process/next_tick.js:61:11)
marius-hi commented 4 years ago

I'm experiencing the same issue when running Karma with karma-teamcity-reporter (see the error below). This is randomly crashing and only on TeamCity agents. karma-teamcity-reporter: 1.1.0 karma: 5.1.1 angular: 10.0.2 karma-chrome-launcher: 3.1.0 with ChromeHeadless

I enabled DEBUG mode and the only thing that I can see is that the socket disconnects. I tried to dig in the report and could observe that when it crashes, the function onBrowserStart() is not called which won't initialise the browser at the beginning. Therefore, at the moment of reporting a message this.browserResults[browser.id] from getLog() won't be available and browserResult.log will be undefined.

The question is what could be the reason why Karma doesn't report the browser informations at startup and always call onBrowserStart() ?

[16:44:23][JavaScript Unit Tests] 07 08 2020 14:41:12.249:ERROR [karma-server]: UncaughtException:: Cannot read property 'log' of undefined [16:44:23][JavaScript Unit Tests] 07 08 2020 14:41:12.249:ERROR [karma-server]: TypeError: Cannot read property 'log' of undefined [16:44:23][JavaScript Unit Tests] at TeamcityReporter.getLog (/opt/jetbrains/TeamcityBuildAgent/work/a0c7df66c0e3b0de/client/node_modules/karma-teamcity-reporter/index.js:126:29) [16:44:23][JavaScript Unit Tests] at TeamcityReporter.specSuccess (/opt/jetbrains/TeamcityBuildAgent/work/a0c7df66c0e3b0de/client/node_modules/karma-teamcity-reporter/index.js:81:20) [16:44:23][JavaScript Unit Tests] at TeamcityReporter.BaseReporter.onSpecComplete (/opt/jetbrains/TeamcityBuildAgent/work/a0c7df66c0e3b0de/client/node_modules/karma/lib/reporters/base.js:107:12) [16:44:23][JavaScript Unit Tests] at Server.<anonymous> (/opt/jetbrains/TeamcityBuildAgent/work/a0c7df66c0e3b0de/client/node_modules/karma/lib/events.js:40:26) [16:44:23][JavaScript Unit Tests] at Server.emit (events.js:203:15) [16:44:23][JavaScript Unit Tests] at Browser.onResult (/opt/jetbrains/TeamcityBuildAgent/work/a0c7df66c0e3b0de/client/node_modules/karma/lib/browser.js:159:20) [16:44:23][JavaScript Unit Tests] at Socket.socket.on (/opt/jetbrains/TeamcityBuildAgent/work/a0c7df66c0e3b0de/client/node_modules/karma/lib/browser.js:209:42) [16:44:23][JavaScript Unit Tests] at Socket.emit (events.js:198:13)

Franziskus1988 commented 4 years ago

To conclude: onBrowserStart and onRunStart sporadically don't get triggered when running a headless browser in TC. I don't know enough to estimate if this is a TC, Karma or browser problem. A ugly fix could be checking if browserResult is undefined in this.getLog and call initializeBrowser if it is the case.

andy-maca commented 3 years ago

I made a workaround by creating a patcher like this in karma-teamcity-reporter-patcher.js:

module.exports = function(tcReporterPlugin) {

  const TCReporter = tcReporterPlugin['reporter:teamcity'][1];

  var newTCReporter = function(baseReporterDecorator) {
    TCReporter.call(this, baseReporterDecorator);

    var specSuccess = this.specSuccess;
    var specFailure = this.specFailure;
    var specSkipped = this.specSkipped;

    this.specSuccess = function(browser, result) {
      this.browserResults[browser.id] && specSuccess.call(this, browser, result);
    }

    this.specFailure = function(browser, result) {
      this.browserResults[browser.id] && specFailure.call(this, browser, result);
    }

    this.specSkipped = function(browser, result) {
      this.browserResults[browser.id] && specSkipped.call(this, browser, result);
    }
  }

  newTCReporter.$inject = TCReporter.$inject;

  tcReporterPlugin['reporter:teamcity'][1] = newTCReporter;

  return tcReporterPlugin;
}

Then in karma.config.js, use it like this:

const patcher = require("./karma-teamcity-reporter-patcher.js");
...

plugins: [
      require("karma-jasmine"),
      require("karma-chrome-launcher"),
      require("karma-firefox-launcher"),
      require("karma-coverage-istanbul-reporter"),
      teamcityReporterPatcher(require("karma-teamcity-reporter")),
      require("karma-spec-reporter"),
      require("@angular-devkit/build-angular/plugins/karma")
    ],
Franziskus1988 commented 3 years ago

@dignifiedquire Is this repo still supported? E.g. this issue here is open for 2 and a half years now...

bobbyg603 commented 2 years ago

thanks @andy-maca! our first run with this patch was green - hopefully things stay green!

eliBlooma commented 1 year ago

I got this issue. Then run the build again and it was gone. Hope this helps someone.