diff --git a/common/util.js b/common/util.js index 172185aa..adf5063a 100644 --- a/common/util.js +++ b/common/util.js @@ -2,7 +2,8 @@ const exec = require('execon'); const jonny = require('jonny'); -const Scope = global || window; + +const Scope = typeof window !== 'undefined' ? window : global; module.exports.getStrBigFirst = getStrBigFirst; module.exports.kebabToCamelCase = kebabToCamelCase; diff --git a/test/common/util.js b/test/common/util.js index 991f3538..f79ecfad 100644 --- a/test/common/util.js +++ b/test/common/util.js @@ -2,7 +2,8 @@ const test = require('tape'); const DIR = '../../'; -const Util = require(DIR + 'common/util'); +const UtilPath = DIR + 'common/util'; +const Util = require(UtilPath); const { getStrBigFirst, kebabToCamelCase, @@ -132,3 +133,20 @@ test('util: escapeRegExp', (t) => { t.end(); }); +test('util: scope', (t) => { + global.window = {}; + clean(UtilPath); + + require(UtilPath); + + t.pass('should set window in scope'); + + delete global.window; + + t.end(); +}); + +function clean(path) { + delete require.cache[require.resolve(path)]; +} +