5

My directory follows this structure:

src
  /test
    - file-test.js
  - file.js

My Mocha script uses

mocha -R spec --recursive ./**/*-test.js

Which leads to the fantastical error of Error: Cannot find module 'tap'.

But peculiarly the following two options work

  1. mocha -R spec --recursive ./src/**/*-test.js
  2. Renaming file-test.js to file.test.js and using mocha -R spec --recursive ./**/*.test.js

But I have no idea why those two options work, and my original plan did not.

user1778856
  • 641
  • 4
  • 10
  • 17
  • Just an idea, but can you try to escape the minus sign, like so `mocha -R spec --recursive ./**/*\-test.js`. Maybe even multiple times, once for bash, once for JS. Might rely on RegEx matching – martinczerwi Feb 18 '16 at 13:08
  • @martinczerwi: I've tried the following two: `"test": "mocha -R spec --recursive ./**/*\\-test.js"` and `"test": "mocha -R spec --recursive ./**/*\\\\-test.js"` which both give me a "Cannot resolve path" error – user1778856 Feb 18 '16 at 13:12
  • @Louis: That post did not help my problem. instead it leads to Cannot resolve path error – user1778856 Feb 18 '16 at 18:54
  • @user1778856 You should edit your question to make the issue reproducible, taking into account the answer on the other question. Otherwise, we're just guessing. – Louis Feb 18 '16 at 18:58

2 Answers2

11

Maybe this is a long shot, but the glob pattern must be between double quotes if this is an npm script: mocha -R spec --recursive "./**/*-test.js". I had a similar error with mocha.

inf3rno
  • 24,976
  • 11
  • 115
  • 197
  • [Here's the open issue](https://github.com/mochajs/mocha/issues/1115) requesting documentation of this in mochajs... This is the right answer, but I should mention that I've noticed a drastic slowdown using this method. Has this been other people's experience? – chrisjlebron Apr 28 '16 at 22:08
  • @chrisjlebron I don't remember having slowdown, but I always used mocha with this syntax as far as I can tell. My tests take less than a second. – inf3rno Apr 29 '16 at 13:30
1

I know this is a while back, but I've had a similar issue, if you specify a matching file pattern eg. src/**/*.spec.js then --recursive is apparently redundant https://stackoverflow.com/a/43005752 The above comment about escaping the path because npm uses "" double quotes should be correct I believe. So instead of something like this: mocha --recursive ./**/*-test.js This worked for me: mocha \"./**/*-test.js\"

Hope that helped..

Eugene Lai
  • 49
  • 1
  • 4