grunt-mocha-test icon indicating copy to clipboard operation
grunt-mocha-test copied to clipboard

Compilers option is not working

Open ErikLarsson82 opened this issue 6 years ago • 3 comments

Hi,

Using command line $ mocha --compilers js:babel-core/register object spread operator "..." works.

However, using grunt mochaTest, I cannot get the compiler option to be included.

"grunt": "^1.0.1",
"mocha": "^5.1.0", "grunt-mocha-test": "^0.13.3",

mochaTest: { test: { src: ['test/**/*.js'] }, options: { require: ['./test/prepare.js', "babel-core/register"] }

I've tried as many permutations of the options configuation I can think of; "js:babel-core/register", "babel-register", using require, using compilers.

I even tried grunt.config.set('mochaTest.options.compilers', 'js:babel-core/register') but with no luck.

What am I missing and how can I troubleshoot what CLI-command is actually being used?

ErikLarsson82 avatar Apr 18 '18 09:04 ErikLarsson82

It doesn't use pass through to the CLI, it loads the mocha library programatically. I haven't used it for a while but I think you had the configuration correct the first time using require. It creates the Mocha object (passing in the options) here:

https://github.com/pghalliday/grunt-mocha-test/blob/master/tasks/lib/MochaWrapper.js#L30

However, just looking at it now I see that we handle the require option differently and actually require the modules here.

https://github.com/pghalliday/grunt-mocha-test/blob/master/tasks/lib/MochaWrapper.js#L15

I think this is because Mocha class doesn't do it and it is usually done by the CLI.

I also notice that this is done before the clearRequireCache option is handled which doesn't seem quite right - do you have that option turned on as well?

pghalliday avatar Apr 18 '18 20:04 pghalliday

I having a similar issue. In my project, I have a hooks.js file with exports.mochaHooks and if I run mocha --require "tests/non-ui/hooks.js" "tests/non-ui/**/*.js", the hooks are executed, but if I include the file in grunt file tasks, hooks are not executed -

'e2e-non-ui': {
        src: 'tests/non-ui/**/*.js',
        options: {
          timeout: 60000,
          require: 'tests/non-ui/hooks.js',
        },
      }

ngaruko avatar May 16 '21 04:05 ngaruko

I think this will require more investigation, but unfortunately I do not have the bandwidth available to look into this. The tests appear to still be passing, however Mocha has moved on a lot since this was implemented and it's possible there are issues with the integration with newer versions. If you wish to investigate this yourself and submit a pull request, I would suggest to start with updating the Mocha version and checking that the require tests still work.

pghalliday avatar May 17 '21 08:05 pghalliday