From 02387c57f1d5bec8b09a89690b2e35dd0c43a7dc Mon Sep 17 00:00:00 2001 From: Paul Falgout Date: Thu, 12 Nov 2015 19:57:02 -0600 Subject: [PATCH] Create centralized globals.json for test globals 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. --- README.md | 4 +--- app/templates/package.json | 6 +----- app/templates/test/.eslintrc | 10 +--------- app/templates/test/setup/.globals.json | 12 ++++++++++++ app/templates/test/setup/browser.js | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 app/templates/test/setup/.globals.json diff --git a/README.md b/README.md index 47a2e18..51307f3 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/app/templates/package.json b/app/templates/package.json index c2499c1..312ed76 100644 --- a/app/templates/package.json +++ b/app/templates/package.json @@ -54,10 +54,6 @@ }, "babelBoilerplateOptions": { "entryFileName": "<%= repo %>", - "mainVarName": "<%= variable %>", - "mochaGlobals": [ - "stub", "spy", "expect", "sandbox", "mock", - "useFakeTimers", "useFakeXMLHttpRequest", "useFakeServer" - ] + "mainVarName": "<%= variable %>" } } diff --git a/app/templates/test/.eslintrc b/app/templates/test/.eslintrc index 5a72805..00597af 100644 --- a/app/templates/test/.eslintrc +++ b/app/templates/test/.eslintrc @@ -1,4 +1,5 @@ { + extends: "./setup/.globals.json", "parser": "babel-eslint", "rules": { "strict": 0, @@ -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 } } diff --git a/app/templates/test/setup/.globals.json b/app/templates/test/setup/.globals.json new file mode 100644 index 0000000..437436b --- /dev/null +++ b/app/templates/test/setup/.globals.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": true, + "mock": true, + "sandbox": true, + "spy": true, + "stub": true, + "useFakeServer": true, + "useFakeTimers": true, + "useFakeXMLHttpRequest": true + } +} diff --git a/app/templates/test/setup/browser.js b/app/templates/test/setup/browser.js index 7884a01..e27961e 100644 --- a/app/templates/test/setup/browser.js +++ b/app/templates/test/setup/browser.js @@ -1,9 +1,9 @@ -var config = require('../../package.json').babelBoilerplateOptions; ++var mochaGlobals = require('./.globals.json').globals; 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); };