4

I am running unit tests using jasmine-ts version 0.3.0.

The previous version worked fine, but the moment I upgraded, I'd get the output:

No specs found

I found a github issue (and this one) where someone commented:

All arguments passed to jasmine-ts need to have one of these in that argument argv.config || process.env.JASMINE_CONFIG_PATH || "spec/support/jasmine.json";

Indeed, creating a jasmine.json file solved the "No specs issue":

{
    "spec_dir": "../src/**/specs",
    "spec_files": [
        "**/*[sS]pec.ts"
    ],
    "stopSpecOnExecutionFailure": false,
    "random": true
}

Running my tests randomly, I discovered that I had some failures, so I wanted to seed the jasmine execution with a specific seed to reproduce the issue.

I tried adding a "seed": 123 config to my jasmine.json, but that didn't work. I found some docs describing what jasmine.json is supposed to look like, and it didn't contain any mention of a seed config.

What did mention seed was the section about command-line options here.

So I tried:

jasmine-ts --seed=123 --config="./jasmine.json"

(Remember, the config file is apparently required - or at least I didn't see any option for specifying where my specs are without using it)

This however did not work as jasmine logged:

Randomized with seed 94263

The config file that I provide apparently overrides the command-line options. I can see this by specifying the option --random=false, but the output still says Randomized with seed ..., since my jasmine.json contains "random": true.

So... I can't specify seed in jasmine.json, and specifying --seed=... has no effect.

How can I set the seed using jasmine-ts 0.3.0 in that case?

pushkin
  • 9,575
  • 15
  • 51
  • 95

3 Answers3

1

Ran into the same problem with regular Jasmine and found that it doesn't copy that in loadConfig for some reason, but there is a method on the jasmine object you create if running it from your own script:

const jasmine = new Jasmine();
jasmine.seed(1234);
Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
  • How does that fit with using `jasmine.json` to run tests. Do I have to use the same jasmine object to run the tests instead, or how does that work? – pushkin Jul 17 '19 at 23:52
  • To clarify, would I have to run that in the beforeAll of each spec file (or one spec file), or what? – pushkin Jul 18 '19 at 17:48
  • Not sure how ‘jasmine-ts’ is different from the js version. I have node script to run tests. It imports Jasmine from a node package and I call ‘seed()’ on the jasmine object I create before calling ‘loadConfig(json)’ – Jason Goemaat Jul 21 '19 at 19:26
  • @JasonGoemaat THANKS! I never would have found this in the docs. – Jimmy Bosse Sep 03 '20 at 18:25
1

As of jasmine-ts version 0.3.2 (here's the closed issue), command line arguments now get forwarded to jasmine, so given a package.json like:

{
   ...
   "scripts": {
      "test": "jasmine-ts.cmd --config=jasmine.json"
   }
}

You can run npm run test -- --seed=1234 from command line.

pushkin
  • 9,575
  • 15
  • 51
  • 95
0

Was running into this issue while upgrading to angular 12. I had a particular seed that was failing due to the order of some async tests that weren't properly resolved between executions.

I was able to get a specific seed to run by updating the karma.conf.js file:

client:{
  captureConsole: true,
  clearContext: false, // leave Jasmine Spec Runner output visible in browser
  jasmine: {
    seed: 19224, // set value to here and comment out when done 
    random: false // set this to false while running the seed and switch back to true for normal builds.
  }

Doing this was a simple way for me to run a specific jasmine seed.

Nortain
  • 143
  • 7