Mocha: How to require multiple modules?

Created on 12 May 2016  Â·  6Comments  Â·  Source: mochajs/mocha

I am setting up tests for my app using mocha and wanted to use multiple modules but it seems the -r (--require) argument only allows to use one module(?).

Most helpful comment

--require module --require some_other_module --require yet_another_module

All 6 comments

--require module --require some_other_module --require yet_another_module

@boneskull does it work on your system? Because when I try it, it doesn't give an error, but only loads the first package mentioned. Ditto when done using mocha.opts.

yes.

// a.js
console.log('a');
// b.js
console.log('b');
// test.js
const assert = require('assert');

describe('test', function () {
    it('should pass', function () {
        assert(true);
    });
});
$ mocha --require a --require b test.js
a
b


  test
    ✓ should pass


  1 passing (6ms)

@boneskull Any particular reason a list isn't supported? -r foo bar or -r foo, bar

--require x --require y

@boneskull My apologies if I wasn't clear; why not support something like --globals where values are separated by commas (or spaces)?

Was this page helpful?
0 / 5 - 0 ratings