Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Compilers option is not working #135

Open
ErikLarsson82 opened this issue Apr 18, 2018 · 3 comments
Open

Compilers option is not working #135

ErikLarsson82 opened this issue Apr 18, 2018 · 3 comments

Comments

@ErikLarsson82
Copy link

ErikLarsson82 commented Apr 18, 2018

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?

@pghalliday
Copy link
Owner

pghalliday commented Apr 18, 2018

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?

@ngaruko
Copy link

ngaruko commented May 16, 2021

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',
        },
      }

@pghalliday
Copy link
Owner

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants