5 <title>lodash Test Suite</title>
6 <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
15 // Avoid reporting tests to Sauce Labs when script errors occur.
16 if (location.port == '9001') {
17 window.onerror = function(message) {
19 QUnit.config.done.length = 0;
21 global_test_results = { 'message': message };
25 <script src="../node_modules/lodash/lodash.js"></script>
26 <script>var lodashStable = _.noConflict();</script>
27 <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
28 <script src="../node_modules/qunit-extras/qunit-extras.js"></script>
29 <script src="../node_modules/platform/platform.js"></script>
30 <script src="./asset/test-ui.js"></script>
31 <div id="qunit"></div>
32 <div id="exports"></div>
33 <div id="module"></div>
35 function setProperty(object, key, value) {
37 Object.defineProperty(object, key, {
49 function addBizarroMethods() {
50 var funcProto = Function.prototype,
51 objectProto = Object.prototype;
53 var hasOwnProperty = objectProto.hasOwnProperty,
54 fnToString = funcProto.toString,
55 nativeString = fnToString.call(objectProto.toString),
57 propertyIsEnumerable = objectProto.propertyIsEnumerable,
58 reToString = /toString/g;
60 function constant(value) {
66 function createToString(funcName) {
67 return constant(nativeString.replace(reToString, funcName));
70 // Allow bypassing native checks.
71 setProperty(funcProto, 'toString', (function() {
73 setProperty(funcProto, 'toString', fnToString);
74 var result = hasOwnProperty.call(this, 'toString') ? this.toString() : fnToString.call(this);
75 setProperty(funcProto, 'toString', wrapper);
81 // Add prototype extensions.
82 funcProto._method = noop;
85 setProperty(Object, '_create', Object.create);
86 setProperty(Object, 'create', (function() {
88 return function(prototype) {
89 if (prototype === Object(prototype)) {
90 object.prototype = prototype;
91 var result = new object;
92 object.prototype = undefined;
98 setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
99 setProperty(Object, 'getOwnPropertySymbols', undefined);
101 setProperty(objectProto, '_propertyIsEnumerable', propertyIsEnumerable);
102 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
103 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
106 setProperty(window, '_Map', window.Map);
108 setProperty(window, 'Map', (function(Map) {
115 setProperty(window, 'Map', Map);
120 setProperty(Map, 'toString', createToString('Map'));
122 setProperty(window, '_Set', window.Set);
123 setProperty(window, 'Set', noop);
125 setProperty(window, '_Symbol', window.Symbol);
126 setProperty(window, 'Symbol', undefined);
128 setProperty(window, '_WeakMap', window.WeakMap);
129 setProperty(window, 'WeakMap', noop);
131 // Fake `WinRTError`.
132 setProperty(window, 'WinRTError', Error);
134 // Fake free variable `global`.
135 setProperty(window, 'exports', window);
136 setProperty(window, 'global', window);
137 setProperty(window, 'module', {});
140 function removeBizarroMethods() {
141 var funcProto = Function.prototype,
142 objectProto = Object.prototype;
144 setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
146 if (Object._create) {
147 Object.create = Object._create;
149 delete Object.create;
151 if (Object._getOwnPropertySymbols) {
152 Object.getOwnPropertySymbols = Object._getOwnPropertySymbols;
154 delete Object.getOwnPropertySymbols;
159 setProperty(window, 'Map', undefined);
164 setProperty(window, 'Set', undefined);
172 setProperty(window, 'WeakMap', undefined);
174 setProperty(window, '_Map', undefined);
175 setProperty(window, '_Set', undefined);
176 setProperty(window, '_Symbol', undefined);
177 setProperty(window, '_WeakMap', undefined);
179 setProperty(window, 'WinRTError', undefined);
181 setProperty(window, 'exports', document.getElementById('exports'));
182 setProperty(window, 'global', undefined);
183 setProperty(window, 'module', document.getElementById('module'));
185 delete funcProto._method;
186 delete Object._create;
187 delete Object._getOwnPropertySymbols;
188 delete objectProto._propertyIsEnumerable;
191 // Load lodash to expose it to the bad extensions/shims.
192 if (!ui.isModularize) {
194 document.write('<script src="' + ui.buildPath + '"><\/script>');
198 // Store lodash to test for bad extensions/shims.
199 if (!ui.isModularize) {
200 var lodashBizarro = window._;
201 window._ = undefined;
202 removeBizarroMethods();
204 // Load test scripts.
205 document.write((ui.isForeign || ui.urlParams.loader == 'none')
206 ? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
207 : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
217 curl.config({ 'apiName': 'require' });
219 if (ui.isForeign || !window.require) {
222 var reBasename = /[\w.-]+$/,
223 basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
224 modulePath = ui.buildPath.replace(/\.js$/, ''),
225 moduleMain = modulePath.match(reBasename)[0],
226 locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
227 shimmedLocationPath = './abc/../' + locationPath,
228 underscoreLocationPath = './xyz/../' + locationPath,
231 function getConfig() {
234 'urlArgs': 't=' + uid++,
239 'location': basePath + 'test',
242 // Work around no global being exported.
244 'loader': 'curl/loader/legacy'
254 if (ui.isModularize) {
255 result.packages.push({
257 'location': locationPath,
261 'location': shimmedLocationPath,
264 'name': 'underscore',
265 'location': underscoreLocationPath,
269 result.paths.lodash = modulePath;
270 result.paths.shimmed = shimmedLocationPath + '/' + moduleMain;
271 result.paths.underscore = underscoreLocationPath + '/' + moduleMain;
276 function loadTests() {
277 require(getConfig(), ['test'], function() {
282 function loadModulesAndTests() {
283 require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
284 lodashModule = lodash;
285 lodashModule.moduleName = 'lodash';
288 shimmedModule = shimmed.result(shimmed, 'noConflict') || shimmed;
289 shimmedModule.moduleName = 'shimmed';
292 underscoreModule = underscore.result(underscore, 'noConflict') || underscore;
293 underscoreModule.moduleName = 'underscore';
297 if (ui.isModularize) {
298 require(getConfig(), [
301 'lodash/_isIterateeCall'
302 ], function(baseEach, isIndex, isIterateeCall) {
303 lodash._baseEach = baseEach;
304 lodash._isIndex = isIndex;
305 lodash._isIterateeCall = isIterateeCall;
314 QUnit.config.autostart = false;
316 if (window.requirejs) {
318 require(getConfig(), ['lodash'], function(lodash) {
319 lodashBizarro = lodash.result(lodash, 'noConflict') || lodash;
320 delete requirejs.s.contexts._;
322 removeBizarroMethods();
323 loadModulesAndTests();
326 loadModulesAndTests();
330 // Set a more readable browser name.
331 window.onload = function() {
332 var timeoutId = setInterval(function() {
333 var ua = document.getElementById('qunit-userAgent');
335 ua.innerHTML = platform;
336 clearInterval(timeoutId);