diff --git a/test/asset/test-ui.js b/test/asset/test-ui.js index 51ad8e73a..958364ea9 100644 --- a/test/asset/test-ui.js +++ b/test/asset/test-ui.js @@ -128,11 +128,14 @@ init(); }); + // used to indicate that Lo-Dash is in strict mode + ui.isStrict = /\b(?:lodash-es6|transpiled)\b/.test([location.pathname, location.search]); + // used to indicate testing a foreign file ui.isForeign = RegExp('^(\\w+:)?//').test(build); // used to indicate testing a modularized build - ui.isModularize = /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm)\b/.test([location.pathname, location.search]); + ui.isModularize = /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm|transpiled)\b/.test([location.pathname, location.search]); // used to indicate testing in Sauce Labs' automated test cloud ui.isSauceLabs = location.port == '9001'; diff --git a/test/backbone.html b/test/backbone.html index 26c613972..d8446139e 100644 --- a/test/backbone.html +++ b/test/backbone.html @@ -126,6 +126,9 @@ QUnit.config.autostart = false; require(getConfig(), ['underscore', 'backbone'], function(lodash) { + ui.isStrict || (ui.isStrict = 'default' in lodash); + lodash = (lodash['default'] || lodash); + mixinPrereqs(lodash); if (ui.isModularize) { diff --git a/test/index.html b/test/index.html index 210a648c5..5ad3bab35 100644 --- a/test/index.html +++ b/test/index.html @@ -258,6 +258,15 @@ function loadModulesAndTests() { require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) { + ui.isStrict || (ui.isStrict = 'default' in lodash); + lodash = lodash['default'] || lodash; + + lodashModule = lodash; + lodashModule.moduleName = 'lodash'; + + shimmed = shimmed && (shimmed['default'] || shimmmed); + underscore = underscore && (underscore['default'] || underscore); + if (shimmed && shimmed.noConflict) { shimmedModule = shimmed.noConflict(); shimmedModule.moduleName = 'shimmed'; @@ -266,16 +275,12 @@ underscoreModule = underscore.noConflict(); underscoreModule.moduleName = 'underscore'; } - if (lodash) { - lodashModule = lodash; - lodashModule.moduleName = 'lodash'; - } if (ui.isModularize) { window._ = lodash; } if (ui.isModularize) { require(getConfig(), ['lodash/internals/baseEach'], function(baseEach) { - lodash._baseEach = baseEach; + lodash._baseEach = baseEach['default'] || baseEach; loadTests(); }); } else { @@ -289,7 +294,7 @@ if (window.requirejs) { addBizarroMethods(); require(getConfig(), ['lodash'], function(lodash) { - lodashBizarro = lodash.noConflict(); + lodashBizarro = (lodash['default'] || lodash).noConflict(); delete requirejs.s.contexts._; removeBizarroMethods(); diff --git a/test/test.js b/test/test.js index 6e11c676e..be3886366 100644 --- a/test/test.js +++ b/test/test.js @@ -67,7 +67,8 @@ var ui = root.ui || (root.ui = { 'buildPath': filePath, 'loaderPath': '', - 'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm)\b/.test(filePath), + 'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm|transpiled)\b/.test(filePath), + 'isStrict': /\b(?:lodash-es6|transpiled)\b/.test(filePath), 'urlParams': {} }); @@ -83,12 +84,15 @@ /** Detect if testing `npm` modules */ var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]); - /** Detects if running in PhantomJS */ + /** Detect if running in PhantomJS */ var isPhantom = phantom || typeof callPhantom == 'function'; /** Detect if running in Rhino */ var isRhino = isJava && typeof global == 'function' && global().Array === root.Array; + /** Detect if Lo-Dash is in strict mode */ + var isStrict = ui.isStrict; + /** Used to test Web Workers */ var Worker = !(ui.isForeign || isModularize) && document && root.Worker; @@ -170,7 +174,7 @@ /** The `lodash` function to test */ var _ = root._ || (root._ = ( _ = load(filePath) || root._, - _ = _._ || _, + _ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _, (_.runInContext ? _.runInContext(root) : _) )); @@ -322,7 +326,7 @@ var path = require('path'), baseEach = require(path.join(path.dirname(filePath), 'internals', 'baseEach.js')); - _._baseEach = baseEach.baseEach || baseEach; + _._baseEach = baseEach.baseEach || baseEach['default'] || baseEach; } // allow bypassing native checks var _fnToString = Function.prototype.toString; @@ -380,7 +384,7 @@ emptyObject(require.cache); // load Lo-Dash and expose it to the bad extensions/shims - lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro; + lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro; // restore native methods setProperty(Array, 'isArray', _isArray); @@ -2645,9 +2649,9 @@ _.each(['assign', 'bindAll', 'defaults'], function(methodName) { var func = _[methodName]; - test('`_.' + methodName + '` should not throw strict mode errors', 1, function() { + test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', 1, function() { var object = { 'a': null, 'b': function(){} }, - pass = true; + pass = !isStrict; if (freeze) { freeze(object); @@ -2658,7 +2662,7 @@ func(object, { 'a': 1 }); } } catch(e) { - pass = false; + pass = !pass; } ok(pass); } @@ -5726,7 +5730,7 @@ }); test('`_.' + methodName + '` should work with `arguments` objects (test in IE < 9)', 1, function() { - if (!isPhantom) { + if (!(isPhantom || isStrict)) { var actual = func(args); deepEqual(actual.sort(), ['0', '1', '2']); } else { @@ -5735,7 +5739,7 @@ }); test('`_.' + methodName + '` should custom properties on `arguments` objects', 1, function() { - if (!isPhantom) { + if (!(isPhantom || isStrict)) { args.a = 1; var actual = func(args); @@ -5747,7 +5751,7 @@ }); test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties of `arguments` objects', 1, function() { - if (!isPhantom) { + if (!(isPhantom || isStrict)) { Object.prototype.a = 1; var expected = isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a'], actual = func(args); diff --git a/test/underscore.html b/test/underscore.html index 2f4905fc6..6fd4805c3 100644 --- a/test/underscore.html +++ b/test/underscore.html @@ -234,6 +234,9 @@ QUnit.config.autostart = false; require(getConfig(), [moduleId], function(lodash) { + ui.isStrict || (ui.isStrict = 'default' in lodash); + lodash = (lodash['default'] || lodash); + if (ui.isModularize) { window._ = lodash; }