Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha's glob behaviour [duplicate]

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.

like image 272
user1778856 Avatar asked Feb 18 '16 13:02

user1778856


2 Answers

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.

like image 123
inf3rno Avatar answered Dec 05 '22 09:12

inf3rno


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..

like image 44
Eugene Lai Avatar answered Dec 05 '22 11:12

Eugene Lai