Search code examples
node.jstestingjasminejasmine-node

Jasming config flag (--config) does not use the right config file


I have my node server on path F:\proj\dev-react-node-java\src\server. I used 'jasmine init' to create spec folder here and running 'jasmine' in terminal runs the specs (tests) correctly.

I wish to run the tests from F:\proj\dev-react-node-java so I used the command

jasmine --config=src/server/spec/support/jasmine.json

at this path but I get the message 'No specs found'. Why is it not using the correct configuration file (jasmine.json)?

I am sure --config reaches for this file because:

  1. Giving wrong path gives 'Cannot find module' error.
  2. Writing errorful json also generates and error.

Here is the jasmine.json code for reference:

{
  "spec_dir": "spec",
  "spec_files": [
    "**/*[sS]pec.js"
  ],
  "helpers": [
    "helpers/**/*.js"
  ],
  "stopSpecOnExpectationFailure": false,
  "random": true
}

spec/support/jasmine.json is the default path as far as I understand since running 'jasmine' command at path say F:\proj\dev-react-node-java\src\server\spec also results in No specs found.

jasmine version is 3.6.1

P.S. This is my first question asked here. Please inform if I made any mistakes in asking. Thank you.


Solution

  • I did find the reason. It is indeed not an issue with the config flag but rather with my jasmine.json file.

    What I thought the use of config flag was to specify the path to the file instead of the default spec/support/jasmine.json. It would then have the same behaviour as if the relative path to config was spec/support/jasmine.json.

    But

    F:\proj\dev-react-node-java>jasmine --config=src/server/spec/support/jasmine.json

    is not the same as

    F:\proj\dev-react-node-java\src\server>jasmine --config=spec/support/jasmine.json

    What it does instead is like copying it to the path from where the command was called and then using it to run the tests.

    Hence, what worked was changing the spec_dir field.

    {
      "spec_dir": "src/server/spec",
      "spec_files": [
        "**/*[sS]pec.js"
      ],
      "helpers": [
        "helpers/**/*.js"
      ],
      "stopSpecOnExpectationFailure": false,
      "random": true
    }
    

    A little more clarification/examples in the docs would have been nicer but perhaps I misunderstood the functionality.