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

Regression: JSON reporters are broken after Karma 2.0.1 #3075

Closed
cexbrayat opened this issue Jul 10, 2018 · 1 comment · Fixed by karronoli/redpen#10 · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132
Closed

Comments

@cexbrayat
Copy link
Contributor

cexbrayat commented Jul 10, 2018

Starting from karma 2.0.1, the JSON reporters available:

are all failing as Karma now returns an object with a circular reference and all the reporters use JSON.stringify to generate their reports.

Expected behaviour

The JSON reporters should continue to work as they were previously.

Actual behaviour

Running a simple test with karma-json-reporter produces:

Chrome 67.0.3396 (Mac OS X 10.13.5): Executed 43 of 43 SUCCESS (9.014 secs / 8.844 secs)
10 07 2018 11:30:43.905:ERROR [karma]: TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at /Users/cedric/Code/ninjasquad/ponyracer/node_modules/karma-json-reporter/index.js:35:24
    at /Users/cedric/Code/ninjasquad/ponyracer/node_modules/karma/lib/helper.js:145:7
    at /Users/cedric/Code/ninjasquad/ponyracer/node_modules/graceful-fs/polyfills.js:287:18
    at FSReqWrap.oncomplete (fs.js:153:5)

Environment Details

  • Karma version (output of karma --version): 2.0.2 (same issue with 2.0.3 and 2.0.4)
  • Relevant part of your karma.config.js file
module.exports = function (config) {
  config.set({
    basePath: '',
    browserNoActivityTimeout: 30000,
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('karma-firefox-launcher'),
      require('karma-json-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'),
      reports: [ 'html', 'json-summary'],
      fixWebpackSourcePaths: true
    },
    jsonReporter: {
      stdout: false,
      outputFile: '../results/karma-results.json'
    },
    reporters: ['progress', 'json', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

Steps to reproduce the behaviour

  1. Add karma-json-reporter to karma.config.js
  2. Run the tests

Other info

After a brief analysis, it looks like the migration of the Browser class to ES2015 introduced the regression (see bb012e2) as it added a bunch of fields on the Browser object, some of them self referencing.

cexbrayat added a commit to cexbrayat/karma that referenced this issue Jul 10, 2018
After migrating the the `browser.js` file to ES2015, the `Browser` class has now fields with circular references (like `emitter`),
which breaks the Karma JSON reporters available starting with Karma 2.0.1.
This commit removes the circular dependencies by adding a `toJSON()` method to the `Browser` class,
which produces a similar result to the browser object before the migration.

Fixes karma-runner#3075
@cexbrayat
Copy link
Contributor Author

I submitted #3076 as a potential fix for this issue, by adding a toJSON() method to the problematic Browser class.

lusarz pushed a commit that referenced this issue Jul 11, 2018
After migrating the the `browser.js` file to ES2015, the `Browser` class has now fields with circular references (like `emitter`),
which breaks the Karma JSON reporters available starting with Karma 2.0.1.
This commit removes the circular dependencies by adding a `toJSON()` method to the `Browser` class,
which produces a similar result to the browser object before the migration.

Fixes #3075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant