admin管理员组

文章数量:1317906

When I run npm test it outputs:

 mocha ./tests/ --recursive --reporter mocha-junit-reporter

And all tests run well. But when I try to invoke mocha ./tests/flickr/mytest --reporter junit-reporter I got:

 Unknown "reporter": junit-reporter

How to pass it correctly?

When I run npm test it outputs:

 mocha ./tests/ --recursive --reporter mocha-junit-reporter

And all tests run well. But when I try to invoke mocha ./tests/flickr/mytest --reporter junit-reporter I got:

 Unknown "reporter": junit-reporter

How to pass it correctly?

Share Improve this question edited Mar 29, 2019 at 11:19 Nino Filiu 18.6k11 gold badges62 silver badges96 bronze badges asked Mar 29, 2019 at 10:54 CherryCherry 33.6k74 gold badges243 silver badges394 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

From mocha-junit-reporter's readme:

# install the package
npm install mocha-junit-reporter --save-dev

# run the test with reporter
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=./path_to_your/file.xml

I spotted two issues in your mand:

mocha ./tests/flickr/mytest --reporter junit-reporter

First issue is mocha in above is a mocha mand from global node module. However, when executing npm test, it actually targets local mocha mand inside our node_modules folder.

Second issue is the name of reporter should be mocha-junit-reporter not junit-reporter

Solution

Workaround is to target local mocha

./node_modules/.bin/mocha ./tests/flickr/mytest --reporter mocha-junit-reporter

This is preferrable solution.

Alternative solution is to install mocha-junit-reporter for global node modules as below:

npm install -g mocha-junit-reporter
mocha ./tests/flickr/mytest --reporter mocha-junit-reporter

This is not too preferrable because you can target different version of mocha and mocha-junit-reporter in global pare to the one in local node modules.

Cheers

本文标签: javascriptHow to run mocha tests with reporterStack Overflow