How to access mocha parameters from a test file?

I run mocha tests using gruntjs and grunt-simple-mocha: https://github.com/yaymukund/grunt-simple-mocha

How can I access the parameters defined in the grunt.js file in each mocha test?

What I would like to accomplish is to have some general configuration in my grunt file and use this in my tests.

+6
source share
2 answers

The only way I found is to use global values, which is not very good, but it works

inside grunt.js config

 global.hell = 'hey you'; 

inside the test

 console.log(global.hell); 

check out another way maybe it would be better

- EDIT

No, it seems, this is the one I will stop on if I do not want to end up black magic, as in mocha, as promised, because I do not have the skills to write this.

- EDIT

You can also take a look at this - https://github.com/visionmedia/mocha/wiki/Shared-Behaviours you can share some object between tests, but you are not sure if it will help with grunt

+3
source

As far as I know, there is no way to push any objects into your mocha costume. The only other interpretation I can think of on your subject would you like to load a common set of configurations among your test files. I do not believe that you can, with the exception of the top of the test files, download a common configuration file that is available for your test methods.

+1
source

Source: https://habr.com/ru/post/925756/


All Articles