Search code examples
node.jsunit-testingjasminejasmine-nodejasmine-ts

How can I get jasmine-ts to execute my specs with a specific seed?


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?


Solution

  • 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.