javascript - Mocha throws an error when no tests are found. Can this be suppressed? -
i'm running mocha on command line this:
mocha --recursive "./src/**/*.spec.js" this works great. however, if no test files found, throws error:
cannot resolve path (or pattern) './src/**/*.spec.js' is there way suppress error message when no tests exist?
(to clarify, relevant because it's part of react slingshot starter kit, no tests exist after delete example tests begin project).
this known issue , reported several times, e.g. here or here. relevant github issue feature request replaces error more descriptive message. pr merged soon.
for now, can include shell script in starter kit execute mocha test runner if test files present.
test.sh (needs bash 4.0 or newer globstar support)
#!/bin/bash count=`ls -1 src/**/*.spec.js -name 'prams' -type d 2> /dev/null | wc -l` if [ "$count" -gt "0" ]; npm run test:mocha --silent else echo -e "\033[0;31mwrite tests!" && exit 1 fi package.json
"scripts": { "test": "./test.sh", "test:mocha": "mocha 'src/**/*.spec.js'" }, unfortunately won't work glob braced sections - mocha throw error if there tests available in on of directories first directory in set empty.
Comments
Post a Comment