From f462f87183bc6b8061e7f5616ce64340ad53c844 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 3 Sep 2013 23:37:53 -0500 Subject: [PATCH] Finish making tests runnable for `lodash-amd`. --- test/index.html | 2 +- test/test-ui.js | 2 +- test/test.js | 45 +++++++++++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/test/index.html b/test/index.html index 4f7a9697a..5669b119b 100644 --- a/test/index.html +++ b/test/index.html @@ -54,7 +54,7 @@ return; } var reBasename = /[\w.-]+$/, - basePath = ('//' + location.host + location.pathname).replace(/\btest\/$/, ''), + basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''), modulePath = ui.buildPath.replace(/\.js$/, ''), locationPath = modulePath.replace(reBasename, ''), moduleMain = modulePath.match(reBasename)[0]; diff --git a/test/test-ui.js b/test/test-ui.js index 6824ab77a..94c89c95c 100644 --- a/test/test-ui.js +++ b/test/test-ui.js @@ -74,7 +74,7 @@ }()); // used to indicate testing a modularized build - ui.isModularize = /\b(?:lodash-(?:amd|node)|modularize)\b/.test(ui.buildPath); + ui.isModularize = /\b(?:lodash-(?:amd|node)|modularize)\b/.test([location.pathname, location.search, ui.buildPath]); // initialize controls addListener(window, 'load', function() { diff --git a/test/test.js b/test/test.js index 72c22e665..ad00a4144 100644 --- a/test/test.js +++ b/test/test.js @@ -27,10 +27,12 @@ result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js'; try { - return typeof define == 'undefined' && require('fs').realpathSync(result); - } catch(e) { - return result; - } + if (typeof define == 'undefined') { + return require('fs').realpathSync(result); + } + } catch(e) { } + + return result; }()); /** The `ui` object */ @@ -41,11 +43,11 @@ }); /** Used to indicate testing a modularized build */ - var isModularize = /\b(?:lodash-(?:amd|node)|modularize)\b/.test([ui.buildPath, ui.urlParams.build]); + var isModularize = ui.isModularize || /\b(?:lodash-(?:amd|node)|modularize)\b/.test([ui.buildPath, ui.urlParams.build]); /*--------------------------------------------------------------------------*/ - // exit early if running tests in phantomjs page + // exit early if going to run tests in a PhantomJS web page if (phantom && isModularize) { var page = require('webpage').create(); page.open(filePath, function(status) { @@ -95,6 +97,9 @@ toString = Object.prototype.toString, Worker = !phantom && window.Worker; + /** Detects if running in a PhantomJS web page */ + var isPhantomPage = typeof callPhantom == 'function'; + /** Use a single "load" function */ var load = !amd && typeof require == 'function' ? require : window.load; @@ -1983,7 +1988,11 @@ }); test('should work with `arguments` objects (test in IE < 9)', function() { - strictEqual(_.isEmpty(args), false); + if (!isPhantomPage) { + strictEqual(_.isEmpty(args), false); + } else { + skipTest(); + } }); }(1, 2, 3)); @@ -1997,8 +2006,12 @@ args2 = (function() { return arguments; }(1, 2, 3)), args3 = (function() { return arguments; }(1, 2)); - strictEqual(_.isEqual(args1, args2), true); - strictEqual(_.isEqual(args1, args3), false); + if (!isPhantomPage) { + strictEqual(_.isEqual(args1, args2), true); + strictEqual(_.isEqual(args1, args3), false); + } else { + skipTest(2); + } }); test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { @@ -2239,7 +2252,11 @@ var args = arguments; test('should work with `arguments` objects (test in IE < 9)', function() { - deepEqual(_.keys(args), ['0', '1', '2']); + if (!isPhantomPage) { + deepEqual(_.keys(args), ['0', '1', '2']); + } else { + skipTest(); + } }); test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { @@ -3421,7 +3438,11 @@ }); test('should work with `arguments` objects (test in IE < 9)', function() { - equal(_.size(args), 3); + if (!isPhantomPage) { + equal(_.size(args), 3); + } else { + skipTest(); + } }); test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { @@ -4434,7 +4455,7 @@ deepEqual([args[0], args[1], args[2]], [1, [3], 5], message('pull')); _.remove(args, function(value) { return typeof value == 'number'; }); - deepEqual(_.values(args), [[3]], message('remove')); + ok(args.length == 1 && _.isEqual(args[0], [3]), message('remove')); }); test('should accept falsey primary arguments', function() {