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/index.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(objectProto, '_propertyIsEnumerable', propertyIsEnumerable);
86 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
87 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
90 setProperty(window, '_Map', window.Map);
92 setProperty(window, 'Map', (function(Map) {
99 setProperty(window, 'Map', Map);
104 setProperty(Map, 'toString', createToString('Map'));
106 setProperty(Object, '_create', Object.create);
107 setProperty(Object, 'create', noop);
109 setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
110 setProperty(Object, 'getOwnPropertySymbols', undefined);
112 setProperty(window, '_Set', window.Set);
113 setProperty(window, 'Set', noop);
115 setProperty(window, '_Symbol', window.Symbol);
116 setProperty(window, 'Symbol', undefined);
118 setProperty(window, '_WeakMap', window.WeakMap);
119 setProperty(window, 'WeakMap', noop);
121 // Fake `WinRTError`.
122 setProperty(window, 'WinRTError', Error);
124 // Fake free variable `global`.
125 setProperty(window, 'exports', window);
126 setProperty(window, 'global', window);
127 setProperty(window, 'module', {});
130 function removeBizarroMethods() {
131 var funcProto = Function.prototype,
132 objectProto = Object.prototype;
134 if (Object._create) {
135 Object.create = Object._create;
137 delete Object.create;
139 if (Object._getOwnPropertySymbols) {
140 Object.getOwnPropertySymbols = Object._getOwnPropertySymbols;
142 delete Object.getOwnPropertySymbols;
147 setProperty(window, 'Map', undefined);
152 setProperty(window, 'Set', undefined);
160 setProperty(window, 'WeakMap', undefined);
162 setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
164 setProperty(window, '_Map', undefined);
165 setProperty(window, '_Set', undefined);
166 setProperty(window, '_Symbol', undefined);
167 setProperty(window, '_WeakMap', undefined);
169 setProperty(window, 'WinRTError', undefined);
171 setProperty(window, 'exports', document.getElementById('exports'));
172 setProperty(window, 'global', undefined);
173 setProperty(window, 'module', document.getElementById('module'));
175 delete funcProto._method;
176 delete objectProto._propertyIsEnumerable;
177 delete Object._create;
178 delete Object._getOwnPropertySymbols;
181 // Load lodash to expose it to the bad extensions/shims.
182 if (!ui.isModularize) {
184 document.write('<script src="' + ui.buildPath + '"><\/script>');
188 // Store lodash to test for bad extensions/shims.
189 if (!ui.isModularize) {
190 var lodashBizarro = window._;
191 window._ = undefined;
192 removeBizarroMethods();
194 // Load test scripts.
195 document.write((ui.isForeign || ui.urlParams.loader == 'none')
196 ? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
197 : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
207 curl.config({ 'apiName': 'require' });
209 if (ui.isForeign || !window.require) {
212 var reBasename = /[\w.-]+$/,
213 basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
214 modulePath = ui.buildPath.replace(/\.js$/, ''),
215 moduleMain = modulePath.match(reBasename)[0],
216 locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
217 shimmedLocationPath = './abc/../' + locationPath,
218 underscoreLocationPath = './xyz/../' + locationPath,
221 function getConfig() {
224 'urlArgs': 't=' + uid++,
229 'location': basePath + 'test',
232 // Work around no global being exported.
234 'loader': 'curl/loader/legacy'
244 if (ui.isModularize) {
245 result.packages.push({
247 'location': locationPath,
251 'location': shimmedLocationPath,
254 'name': 'underscore',
255 'location': underscoreLocationPath,
259 result.paths.lodash = modulePath;
260 result.paths.shimmed = shimmedLocationPath + '/' + moduleMain;
261 result.paths.underscore = underscoreLocationPath + '/' + moduleMain;
266 function loadTests() {
267 require(getConfig(), ['test'], function() {
272 function loadModulesAndTests() {
273 require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
274 lodashModule = lodash;
275 lodashModule.moduleName = 'lodash';
278 shimmedModule = shimmed.result(shimmed, 'noConflict') || shimmed;
279 shimmedModule.moduleName = 'shimmed';
282 underscoreModule = underscore.result(underscore, 'noConflict') || underscore;
283 underscoreModule.moduleName = 'underscore';
285 if (ui.isModularize) {
288 if (ui.isModularize) {
289 require(getConfig(), [
290 'lodash/internal/baseEach',
291 'lodash/internal/isIndex',
292 'lodash/internal/isIterateeCall'
293 ], function(baseEach, isIndex, isIterateeCall) {
294 lodash._baseEach = baseEach;
295 lodash._isIndex = isIndex;
296 lodash._isIterateeCall = isIterateeCall;
305 QUnit.config.autostart = false;
307 if (window.requirejs) {
309 require(getConfig(), ['lodash'], function(lodash) {
310 lodashBizarro = lodash.result(lodash, 'noConflict') || lodash;
311 delete requirejs.s.contexts._;
313 removeBizarroMethods();
314 loadModulesAndTests();
317 loadModulesAndTests();
321 // Set a more readable browser name.
322 window.onload = function() {
323 var timeoutId = setInterval(function() {
324 var ua = document.getElementById('qunit-userAgent');
326 ua.innerHTML = platform;
327 clearInterval(timeoutId);