;(function(root, undefined) { 'use strict'; /** Method and object shortcuts */ var phantom = root.phantom, amd = root.define && define.amd, document = !phantom && root.document, body = document && document.body, create = Object.create, freeze = Object.freeze, params = root.arguments, process = root.process, push = Array.prototype.push, slice = Array.prototype.slice, system = root.system, toString = Object.prototype.toString, Worker = document && root.Worker; /** The file path of the Lo-Dash file to test */ var filePath = (function() { var min = 0, result = []; if (phantom) { result = params = phantom.args; } else if (system) { min = 1; result = params = system.args; } else if (process) { min = 2; result = params = process.argv; } else if (params) { result = params; } var last = result[result.length - 1]; result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js'; try { if (!amd) { return require('fs').realpathSync(result); } } catch(e) { } return result; }()); /** The `ui` object */ var ui = root.ui || (root.ui = { 'buildPath': filePath, 'loaderPath': '', 'urlParams': {} }); /** The basename of the Lo-Dash file to test */ var basename = /[\w.-]+$/.exec(filePath)[0]; /** 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]); /** Detect if testing `npm` modules */ var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]); /** Detects if running in a PhantomJS web page */ var isPhantomPage = typeof callPhantom == 'function'; /** Detect if running in Rhino */ var isRhino = root.java && typeof global == 'function' && global().Array === root.Array; /** Use a single "load" function */ var load = !amd && typeof require == 'function' ? require : root.load; /** The unit testing framework */ var QUnit = (function() { var noop = Function.prototype; return root.QUnit || ( root.addEventListener || (root.addEventListener = noop), root.setTimeout || (root.setTimeout = noop), root.QUnit = load('../vendor/qunit/qunit/qunit.js') || root.QUnit, (load('../vendor/qunit-clib/qunit-clib.js') || { 'runInContext': noop }).runInContext(root), addEventListener === noop && delete root.addEventListener, root.QUnit ); }()); /*--------------------------------------------------------------------------*/ // log params passed to `test.js` if (params) { console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params))); } // 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) { if (status != 'success') { console.log('PhantomJS failed to load page: ' + filePath); phantom.exit(1); } }); page.onCallback = function(details) { phantom.exit(details.failed ? 1 : 0); }; page.onConsoleMessage = function(message) { console.log(message); }; page.onInitialized = function() { page.evaluate(function() { document.addEventListener('DOMContentLoaded', function() { var xhr = new XMLHttpRequest; xhr.open('get', '../vendor/qunit-clib/qunit-clib.js'); xhr.onload = function() { var script = document.createElement('script'); script.text = xhr.responseText; document.head.appendChild(script); QUnit.done(callPhantom); }; xhr.send(null); }); }); }; return; } /*--------------------------------------------------------------------------*/ /** The `lodash` function to test */ var _ = root._ || (root._ = ( _ = load(filePath) || root._, _ = _._ || _, (_.runInContext ? _.runInContext(root) : _) )); /** Used to pass falsey values to methods */ var falsey = [, '', 0, false, NaN, null, undefined]; /** Used to pass empty values to methods */ var empties = [[], {}].concat(falsey.slice(1)); /** Used as the size when optimizations are enabled for large arrays */ var largeArraySize = 75; /** Used to set property descriptors */ var defineProperty = (function() { try { var o = {}, func = Object.defineProperty, result = func(o, o, o) && func; } catch(e) { } return result; }()); /** Used to check problem JScript properties (a.k.a. the [[DontEnum]] bug) */ var shadowedProps = [ 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf' ]; /** Used to check problem JScript properties too */ var shadowedObject = _.invert(shadowedProps); /** * Skips a given number of tests with a passing result. * * @private * @param {number} [count=1] The number of tests to skip. */ function skipTest(count) { count || (count = 1); while (count--) { ok(true, 'test skipped'); } } /*--------------------------------------------------------------------------*/ // add object from iframe (function() { if (!document) { return; } var iframe = document.createElement('iframe'); iframe.frameBorder = iframe.height = iframe.width = 0; body.appendChild(iframe); var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc; idoc.write([ '