mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Add ui.isForeign, add guards for Worker tests, and remove Dojo loader filter from test.
This commit is contained in:
@@ -128,6 +128,15 @@
|
|||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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|node)|modularize|npm)\b/.test([location.pathname, location.search]);
|
||||||
|
|
||||||
|
// used to indicate testing in Sauce Labs' automated test cloud
|
||||||
|
ui.isSauceLabs = location.port == '9001';
|
||||||
|
|
||||||
// expose Lo-Dash build file path
|
// expose Lo-Dash build file path
|
||||||
ui.buildPath = (function() {
|
ui.buildPath = (function() {
|
||||||
var result;
|
var result;
|
||||||
@@ -170,12 +179,6 @@
|
|||||||
'loadEventEnd': 0
|
'loadEventEnd': 0
|
||||||
};
|
};
|
||||||
|
|
||||||
// used to indicate testing a modularized build
|
|
||||||
ui.isModularize = /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|node)|modularize|npm)\b/.test([location.pathname, location.search, ui.buildPath]);
|
|
||||||
|
|
||||||
// used to indicate testing in Sauce Labs' automated test cloud
|
|
||||||
ui.isSauceLabs = location.port == '9001';
|
|
||||||
|
|
||||||
// expose `ui`
|
// expose `ui`
|
||||||
window.ui = ui;
|
window.ui = ui;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
addEventListener('message', function(e) {
|
addEventListener('message', function(e) {
|
||||||
if (e.data) {
|
if (e.data) {
|
||||||
importScripts('../' + e.data);
|
try {
|
||||||
|
importScripts('../' + e.data);
|
||||||
|
} catch(e) {
|
||||||
|
self._ = {};
|
||||||
|
}
|
||||||
postMessage(_.VERSION);
|
postMessage(_.VERSION);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|||||||
@@ -168,7 +168,7 @@
|
|||||||
removeBizarroMethods();
|
removeBizarroMethods();
|
||||||
}
|
}
|
||||||
// load test scripts
|
// load test scripts
|
||||||
document.write(ui.urlParams.loader == 'none'
|
document.write((ui.isForeign || ui.urlParams.loader == 'none')
|
||||||
? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
|
? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
|
||||||
: '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
|
: '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
|
||||||
);
|
);
|
||||||
@@ -182,7 +182,7 @@
|
|||||||
if (window.curl) {
|
if (window.curl) {
|
||||||
curl.config({ 'apiName': 'require' });
|
curl.config({ 'apiName': 'require' });
|
||||||
}
|
}
|
||||||
if (!window.require) {
|
if (ui.isForeign || !window.require) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// avoid reporting tests to Sauce Labs when script load errors occur
|
// avoid reporting tests to Sauce Labs when script load errors occur
|
||||||
@@ -256,8 +256,6 @@
|
|||||||
|
|
||||||
function loadModulesAndTests() {
|
function loadModulesAndTests() {
|
||||||
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
||||||
var oldDash = window._;
|
|
||||||
|
|
||||||
if (shimmed && shimmed.noConflict) {
|
if (shimmed && shimmed.noConflict) {
|
||||||
shimmedModule = shimmed.noConflict();
|
shimmedModule = shimmed.noConflict();
|
||||||
shimmedModule.moduleName = 'shimmed';
|
shimmedModule.moduleName = 'shimmed';
|
||||||
@@ -270,7 +268,7 @@
|
|||||||
lodashModule = lodash;
|
lodashModule = lodash;
|
||||||
lodashModule.moduleName = 'lodash';
|
lodashModule.moduleName = 'lodash';
|
||||||
}
|
}
|
||||||
if (oldDash || ui.isModularize) {
|
if (ui.isModularize) {
|
||||||
window._ = lodash;
|
window._ = lodash;
|
||||||
}
|
}
|
||||||
if (ui.isModularize) {
|
if (ui.isModularize) {
|
||||||
|
|||||||
16
test/test.js
16
test/test.js
@@ -23,6 +23,7 @@
|
|||||||
body = root.document && root.document.body,
|
body = root.document && root.document.body,
|
||||||
create = Object.create,
|
create = Object.create,
|
||||||
freeze = Object.freeze,
|
freeze = Object.freeze,
|
||||||
|
JSON = root.JSON,
|
||||||
noop = function() {},
|
noop = function() {},
|
||||||
params = root.arguments,
|
params = root.arguments,
|
||||||
push = Array.prototype.push,
|
push = Array.prototype.push,
|
||||||
@@ -30,9 +31,6 @@
|
|||||||
system = root.system,
|
system = root.system,
|
||||||
toString = Object.prototype.toString;
|
toString = Object.prototype.toString;
|
||||||
|
|
||||||
var JSON = root.JSON,
|
|
||||||
Worker = document && root.Worker;
|
|
||||||
|
|
||||||
/** The file path of the Lo-Dash file to test */
|
/** The file path of the Lo-Dash file to test */
|
||||||
var filePath = (function() {
|
var filePath = (function() {
|
||||||
var min = 0,
|
var min = 0,
|
||||||
@@ -68,6 +66,7 @@
|
|||||||
var ui = root.ui || (root.ui = {
|
var ui = root.ui || (root.ui = {
|
||||||
'buildPath': filePath,
|
'buildPath': filePath,
|
||||||
'loaderPath': '',
|
'loaderPath': '',
|
||||||
|
'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|node)|modularize|npm)\b/.test(filePath),
|
||||||
'urlParams': {}
|
'urlParams': {}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@
|
|||||||
var isJava = !document && !!root.java;
|
var isJava = !document && !!root.java;
|
||||||
|
|
||||||
/** Used to indicate testing a modularized build */
|
/** Used to indicate testing a modularized build */
|
||||||
var isModularize = ui.isModularize || /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|node)|modularize|npm)\b/.test([ui.buildPath, ui.urlParams.build, basename]);
|
var isModularize = ui.isModularize;
|
||||||
|
|
||||||
/** Detect if testing `npm` modules */
|
/** Detect if testing `npm` modules */
|
||||||
var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
|
var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
|
||||||
@@ -89,6 +88,9 @@
|
|||||||
/** Detect if running in Rhino */
|
/** Detect if running in Rhino */
|
||||||
var isRhino = isJava && typeof global == 'function' && global().Array === root.Array;
|
var isRhino = isJava && typeof global == 'function' && global().Array === root.Array;
|
||||||
|
|
||||||
|
/** Detect support for testing Web Workers */
|
||||||
|
var Worker = !(ui.isForeign || isModularize) && document && root.Worker;
|
||||||
|
|
||||||
/** Use a single "load" function */
|
/** Use a single "load" function */
|
||||||
var load = (typeof require == 'function' && !amd)
|
var load = (typeof require == 'function' && !amd)
|
||||||
? require
|
? require
|
||||||
@@ -403,7 +405,7 @@
|
|||||||
|
|
||||||
// add web worker
|
// add web worker
|
||||||
(function() {
|
(function() {
|
||||||
if (!Worker || isModularize) {
|
if (!Worker) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var worker = new Worker('./asset/worker.js?t=' + (+new Date));
|
var worker = new Worker('./asset/worker.js?t=' + (+new Date));
|
||||||
@@ -439,7 +441,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('supports loading ' + basename + ' as the "underscore" module', 1, function() {
|
test('supports loading ' + basename + ' as the "underscore" module', 1, function() {
|
||||||
if (amd && !/dojo/.test(ui.loaderPath)) {
|
if (amd) {
|
||||||
strictEqual((underscoreModule || {}).moduleName, 'underscore');
|
strictEqual((underscoreModule || {}).moduleName, 'underscore');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -448,7 +450,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('supports loading ' + basename + ' in a web worker', 1, function() {
|
asyncTest('supports loading ' + basename + ' in a web worker', 1, function() {
|
||||||
if (Worker && !isModularize) {
|
if (Worker) {
|
||||||
var limit = 15000,
|
var limit = 15000,
|
||||||
start = +new Date;
|
start = +new Date;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user