How to specify test directory for mocha?-open source projects mochajs/mocha
Robin Luiten
I am on Windows 7 using node.js v0.10.0 and mocha v1.8.2 and npm v1.2.14. I was just trying to get mocha to use the path test/unit to find my tests, After spending to long and trying several things I landed,
Using the “test/unit/*.js” option does not work on windows. For good reasons that windows shell doesn’t expand wildcards like unixen.
However using “test/unit” does work, without the file pattern. eg. “mocha test/unit” runs all files found in test/unit folder.
This only still runs one folder files as tests but you can pass multiple directory names as parameters.
Also to run a single test file you can specify the full path and filename. eg. “mocha test/unit/mytest1.js”
I actually setup in package.json for npm “scripts”: { “test”: “mocha test/unit” },
So that ‘npm test’ runs my unit tests.