Add ui.isForeign, add guards for Worker tests, and remove Dojo loader filter from test.

This commit is contained in:
John-David Dalton
2014-05-11 16:02:48 -07:00
parent d5c3b258f3
commit 0f8c20c3ab
4 changed files with 26 additions and 19 deletions

View File

@@ -128,6 +128,15 @@
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
ui.buildPath = (function() {
var result;
@@ -170,12 +179,6 @@
'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`
window.ui = ui;

View File

@@ -1,6 +1,10 @@
addEventListener('message', function(e) {
if (e.data) {
importScripts('../' + e.data);
try {
importScripts('../' + e.data);
} catch(e) {
self._ = {};
}
postMessage(_.VERSION);
}
}, false);

View File

@@ -168,7 +168,7 @@
removeBizarroMethods();
}
// 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 data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
);
@@ -182,7 +182,7 @@
if (window.curl) {
curl.config({ 'apiName': 'require' });
}
if (!window.require) {
if (ui.isForeign || !window.require) {
return;
}
// avoid reporting tests to Sauce Labs when script load errors occur
@@ -256,8 +256,6 @@
function loadModulesAndTests() {
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
var oldDash = window._;
if (shimmed && shimmed.noConflict) {
shimmedModule = shimmed.noConflict();
shimmedModule.moduleName = 'shimmed';
@@ -270,7 +268,7 @@
lodashModule = lodash;
lodashModule.moduleName = 'lodash';
}
if (oldDash || ui.isModularize) {
if (ui.isModularize) {
window._ = lodash;
}
if (ui.isModularize) {

View File

@@ -23,6 +23,7 @@
body = root.document && root.document.body,
create = Object.create,
freeze = Object.freeze,
JSON = root.JSON,
noop = function() {},
params = root.arguments,
push = Array.prototype.push,
@@ -30,9 +31,6 @@
system = root.system,
toString = Object.prototype.toString;
var JSON = root.JSON,
Worker = document && root.Worker;
/** The file path of the Lo-Dash file to test */
var filePath = (function() {
var min = 0,
@@ -68,6 +66,7 @@
var ui = root.ui || (root.ui = {
'buildPath': filePath,
'loaderPath': '',
'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|node)|modularize|npm)\b/.test(filePath),
'urlParams': {}
});
@@ -78,7 +77,7 @@
var isJava = !document && !!root.java;
/** 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 */
var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
@@ -89,6 +88,9 @@
/** Detect if running in Rhino */
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 */
var load = (typeof require == 'function' && !amd)
? require
@@ -403,7 +405,7 @@
// add web worker
(function() {
if (!Worker || isModularize) {
if (!Worker) {
return;
}
var worker = new Worker('./asset/worker.js?t=' + (+new Date));
@@ -439,7 +441,7 @@
});
test('supports loading ' + basename + ' as the "underscore" module', 1, function() {
if (amd && !/dojo/.test(ui.loaderPath)) {
if (amd) {
strictEqual((underscoreModule || {}).moduleName, 'underscore');
}
else {
@@ -448,7 +450,7 @@
});
asyncTest('supports loading ' + basename + ' in a web worker', 1, function() {
if (Worker && !isModularize) {
if (Worker) {
var limit = 15000,
start = +new Date;