如何在jasmine-ts 0.3.0中指定特定种子执行测试?
I’ve run into exactly this issue with jasmine-ts 0.3.0 before, and there are two reliable workarounds to specify a seed for reproducing random test failures:
1. Override Random Mode and Seed via Command Line
The problem with your initial command is that the random: true in your jasmine.json takes precedence over the standalone --seed flag. To fix this, explicitly pass both --random=true and --seed=<your-seed> in the command line — this will override the configuration file’s random setting and enforce your specified seed:
jasmine-ts --random=true --seed=123 --config="./jasmine.json"
This works because jasmine-ts respects command-line arguments for both randomization and seed when they’re explicitly provided, even if the config file has conflicting settings.
2. Use the JASMINE_SEED Environment Variable
Jasmine (and by extension jasmine-ts) supports setting the seed via an environment variable, which bypasses the configuration file’s randomization settings entirely. This is especially useful if you don’t want to modify your jasmine.json or remember to pass multiple flags.
For Linux/macOS:
JASMINE_SEED=123 jasmine-ts --config="./jasmine.json"
For Windows Command Prompt:
set JASMINE_SEED=123 && jasmine-ts --config="./jasmine.json"
For Windows PowerShell:
$env:JASMINE_SEED=123; jasmine-ts --config="./jasmine.json"
When you use this method, jasmine will use the seed from the environment variable regardless of whether random is set to true or false in your jasmine.json.
内容的提问来源于stack exchange,提问作者pushkin

