Skip to content

Instantly share code, notes, and snippets.

@odlp
Last active March 10, 2022 20:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odlp/e1586f4f198d157de50e8303b18acfd9 to your computer and use it in GitHub Desktop.
Save odlp/e1586f4f198d157de50e8303b18acfd9 to your computer and use it in GitHub Desktop.
Jasmine / Karma seed reporter for random test order
var SeedReporter = function(baseReporterDecorator) {
baseReporterDecorator(this);
this.onBrowserComplete = function(browser, result) {
if (result.order && result.order.random && result.order.seed) {
this.write("%s: Randomized with seed %s\n", browser, result.order.seed);
}
};
};
module.exports = {
"reporter:jasmine-seed": ["type", SeedReporter]
};
const jasmineSeedReporter = require("./spec/javascript/support/jasmine_seed_reporter.js")
module.exports = function(config) {
// abridged
plugins: [
"karma-*",
jasmineSeedReporter
],
reporters: ["progress", "jasmine-seed"],
client: {
jasmine: {
random: true
// seed: 1234 // Specify if you need to re-run the same seed
}
}
}
@dellagustin
Copy link

Almost worked, but I had to do some changes to this karma.conf.js example:

// filaname was wrong, _ instead of -
const jasmineSeedReporter = require('./spec/javascript/support/jasmine-seed-reporter.js')

module.exports = function(config) {
  // abridged  
  plugins: [
    'karma-*',
    // here I had to change the path and add the ./spec/javascript, but maybe because my karma.conf.js is at the root of my project
    require('./spec/javascript/support/jasmine-seed-reporter.js')
  ],

  // here I had to change jasmineSeedReporter by the name of the reporter exported in jasmine-seed-reporter.js, jasmine-seed
  reporters: ['progress', 'jasmine-seed'],

  client: {
    jasmine: {
      random: true
      // seed: 1234 // Specify if you need to re-run the same seed
    }
  }
}

then it worked for me.

thanks

@Furg
Copy link

Furg commented Jul 30, 2019

Good job guys! 👍 Just note that it was failing for me because seed value should be a string.

@Quron
Copy link

Quron commented Dec 26, 2019

Hi, thanks for this solution 👍

By the way i found what logs is duplicate with this reporter and fix it add stub for onBrowserLog. Maybe it help somebody else.

const SeedReporter = function(baseReporterDecorator) {
	baseReporterDecorator(this);

	this.onBrowserLog = function(browser, log, type) {
		// For prevent log duplicate.
	};

...
};

@iainprior-diligent
Copy link

Thanks @Furg - that comment saved me hours...

@douglasrlee
Copy link

Is there a way to print the seed before the tests start? We have a specific issue where an error is thrown in the after all and therefore throwing the error all the way up it seems. So since the tests can't complete I don't get the seed value to replicate.

@odlp
Copy link
Author

odlp commented May 20, 2020

@douglasrlee - I haven't tried it, but this reporter seems to print the seed before & after the spec run which might help you: https://github.com/dmitryshindin/karma-jasmine-order-reporter

@JWess
Copy link

JWess commented Mar 10, 2022

@douglasrlee - I haven't tried it, but this reporter seems to print the seed before & after the spec run which might help you: https://github.com/dmitryshindin/karma-jasmine-order-reporter

Fantastic! Thanks. Here is a screenshot of it working:
image

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