Search code examples
javascriptnpmmocha.jspact

How to run multiple .js test files together using npm (pact files)?


I come from a Java and Maven background and when trying to run multiple test files together and sequentially, I'm used to do something like this:

mvn '-Dtest=com.my.directory.tests.*Test' test

Where all my files would have been named finishing with the word Test at the end.

However, I'm now writing some pact tests in Javascript and have them named finishing with .pact.js but can't find an equivalent npm command to run them all one after the other?

enter image description here

Thank you.


Solution

  • In your package.json scripts you can tell mocha to test all files matching a given pattern, in your case .pact.js within the pact directory:

      "scripts": {
        "test": "./node_modules/.bin/mocha 'src/pact/**/*.pact.js'",
        ...
      }