Skip to content

Instantly share code, notes, and snippets.

@odlp
Last active March 10, 2022 20:57
Show Gist options
  • 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
}
}
}
@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