Open samhatoum opened 6 years ago
Comment by Sanjo Wednesday Apr 13, 2016 at 04:45 GMT
Right now you can probably force a file to load first by prefixing the file name with . E.g. beforeAll.js. Because files are loaded in alphabetical order I think.
Comment by joshhunt Tuesday Jun 07, 2016 at 08:49 GMT
Sorry for dropping off the grid - I'll check this out tomorrow and report back!
Comment by tiagolr Friday Mar 17, 2017 at 21:45 GMT
I am using two different options for this:
1 - run code in chimp.config.js
that executes in chimp process before tests start
2 - run code in this.BeforeFeatures(...)
that executes in cucumber process before tests start
In your case the first option should work well, I'm using it too to setup global variables.
Here is a pasteBin of my config file: http://pastebin.com/fXeVVTiW
edit: the configs contain a verification to prevent cucumber process from parsing the file, that has to do with the script and tests folder location.
Comment by paulbjensen Sunday Aug 13, 2017 at 07:19 GMT
Hi,
I tried the suggestion that @Sanjo made, and it works. I created a file named __beforeAll.test.js, and places it inside of the test/controllers folder in my app, as npm test script would load files from that directory first, e.g.
"script": {
"test": "NODE_ENV=test mocha test/**/* test/*"
}
I needed to load the timekeeper npm module first to intercept the Date class in order to create a test relating to time, and so needed to load timekeeper before all of the application's code, as timekeeper mocks the Date
class and Date.now
function.
Thanks to @sanjo for the suggestion.
Issue by joshhunt Tuesday Apr 12, 2016 at 23:15 GMT Originally opened as https://github.com/xolvio/chimp/issues/332
Mocha has the 'require' option which allows you to run a setup file before all the tests are even required. We take this opportunity to set up some global variables and functions, which are required for the tests to be required properly.
I noticed that chimp has a similar option
--require
, however it does not load this file before it loads the others. I put some very basicconsole.log
at the top of key files, which shows the orderBecause
setup.js
was required after our test cases, the test cases will fail to load properly because they don't have the globals set up yet.Am I using the
--require
option correctly, or is there another option to do what we need?