Skip to content

Commit

Permalink
Create centralized globals.json for test globals
Browse files Browse the repository at this point in the history
Removes the need to update two objects.

It's too easy to update one and for get the other. It wasn't consistent as it was.

And it's in the test/setup directory which seems pretty self explanatory.
  • Loading branch information
paulfalgout authored and jamesplease committed Dec 30, 2015
1 parent eb37a17 commit 02387c5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,4 @@ If you want to access the module itself in your unit test files, you will need t
test environment to support the module. To do this:

1. Load the module in the [test setup file](https://github.com/babel/generator-babel-boilerplate/blob/master/test/setup/setup.js).
Attach any exported variables to global object if you'll be using them in your tests.
2. Add those same global variables to the `mochaGlobals` array in `package.json` under
`babelBoilerplateOptions`
2. Add any exported variables to globals object in the [test globals json](https://github.com/babel/generator-babel-boilerplate/blob/master/test/setup/.globals.js).
6 changes: 1 addition & 5 deletions app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
},
"babelBoilerplateOptions": {
"entryFileName": "<%= repo %>",
"mainVarName": "<%= variable %>",
"mochaGlobals": [
"stub", "spy", "expect", "sandbox", "mock",
"useFakeTimers", "useFakeXMLHttpRequest", "useFakeServer"
]
"mainVarName": "<%= variable %>"
}
}
10 changes: 1 addition & 9 deletions app/templates/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
extends: "./setup/.globals.json",
"parser": "babel-eslint",
"rules": {
"strict": 0,
Expand All @@ -9,14 +10,5 @@
"browser": true,
"node": true,
"mocha": true
},
"globals": {
"spy": true,
"stub": true,
"mock": true,
"useFakeTimers": true,
"useFakeXMLHttpRequest": true,
"useFakeServer": true,
"expect": true
}
}
12 changes: 12 additions & 0 deletions app/templates/test/setup/.globals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"globals": {
"expect": true,
"mock": true,
"sandbox": true,
"spy": true,
"stub": true,
"useFakeServer": true,
"useFakeTimers": true,
"useFakeXMLHttpRequest": true
}
}
4 changes: 2 additions & 2 deletions app/templates/test/setup/browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var config = require('../../package.json').babelBoilerplateOptions;
+var mochaGlobals = require('./.globals.json').globals;

This comment has been minimized.

Copy link
@jamesplease

jamesplease Dec 30, 2015

Member

lol


window.mocha.setup('bdd');
window.onload = function() {
window.mocha.checkLeaks();
window.mocha.globals(config.mochaGlobals);
window.mocha.globals(Object.keys(mochaGlobals));
window.mocha.run();
require('./setup')(window);
};

0 comments on commit 02387c5

Please sign in to comment.