Yoni Levy
Yoni Levy

Reputation: 1592

mocha not running all tests in test dir

This is my folder structure

src/
   a.js
   b.js
   test/
     a.spec.js
     b.spec.js

and I've tried running

  1. ~/.../src $ mocha
  2. ~/.../src $ mocha test
  3. ~/.../src $ mocha test/
  4. ~/.../src $ mocha ./test/
  5. ~/.../src $ mocha ./test/*.js

but non worked... all I get is just one test file running and the rest are ignored.

The docs say that (1) should do the job but well it doesn't.

Upvotes: 12

Views: 16614

Answers (3)

Jonathan Reyes
Jonathan Reyes

Reputation: 1419

It's built like this so you can run your test suite on just a file or two if you're doing development on them. If you want to run mocha throughout your project just specify --recursive

You can see some documentation here.

Better yet, you can just specify it in your package.json for CD. First do npm install mocha --save-dev and then put this in your package.json file then run npm test

{
  "scripts": {
    "test": "./node_modules/.bin/mocha --recursive",
  }
}

Upvotes: 8

Yoni Levy
Yoni Levy

Reputation: 1592

This was my mistake. I had it.only in one of my files and I forgot it. Removing the .only was the answer. All the test files are running now.

Upvotes: 35

Manish Prasad
Manish Prasad

Reputation: 105

Create a moch.opts file under test directory and add recursive option

--recursive

Run ~/.../src $ mocha command; it should work.

Upvotes: -2

Related Questions