blob: aee39424991c17a1b2a0d8487699bdd96d516ee7 [file] [log] [blame]
Matteo Scandolo280dcd32016-05-16 09:59:38 -07001<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>lodash Test Suite</title>
6 <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
7 <style>
8 #exports, #module {
9 display: none;
10 }
11 </style>
12 </head>
13 <body>
14 <script>
15 // Avoid reporting tests to Sauce Labs when script errors occur.
16 if (location.port == '9001') {
17 window.onerror = function(message) {
18 if (window.QUnit) {
19 QUnit.config.done.length = 0;
20 }
21 global_test_results = { 'message': message };
22 };
23 }
24 </script>
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>
34 <script>
35 function setProperty(object, key, value) {
36 try {
37 Object.defineProperty(object, key, {
38 'configurable': true,
39 'enumerable': false,
40 'writable': true,
41 'value': value
42 });
43 } catch (e) {
44 object[key] = value;
45 }
46 return object;
47 }
48
49 function addBizarroMethods() {
50 var funcProto = Function.prototype,
51 objectProto = Object.prototype;
52
53 var hasOwnProperty = objectProto.hasOwnProperty,
54 fnToString = funcProto.toString,
55 nativeString = fnToString.call(objectProto.toString),
56 noop = function() {},
57 propertyIsEnumerable = objectProto.propertyIsEnumerable,
58 reToString = /toString/g;
59
60 function constant(value) {
61 return function() {
62 return value;
63 };
64 }
65
66 function createToString(funcName) {
67 return constant(nativeString.replace(reToString, funcName));
68 }
69
70 // Allow bypassing native checks.
71 setProperty(funcProto, 'toString', (function() {
72 function wrapper() {
73 setProperty(funcProto, 'toString', fnToString);
74 var result = hasOwnProperty.call(this, 'toString') ? this.toString() : fnToString.call(this);
75 setProperty(funcProto, 'toString', wrapper);
76 return result;
77 }
78 return wrapper;
79 }()));
80
81 // Add prototype extensions.
82 funcProto._method = noop;
83
84 // Set bad shims.
85 setProperty(Object, '_create', Object.create);
86 setProperty(Object, 'create', (function() {
87 function object() {}
88 return function(prototype) {
89 if (prototype === Object(prototype)) {
90 object.prototype = prototype;
91 var result = new object;
92 object.prototype = undefined;
93 }
94 return result || {};
95 };
96 }()));
97
98 setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
99 setProperty(Object, 'getOwnPropertySymbols', undefined);
100
101 setProperty(objectProto, '_propertyIsEnumerable', propertyIsEnumerable);
102 setProperty(objectProto, 'propertyIsEnumerable', function(key) {
103 return !(key == 'valueOf' && this && this.valueOf === 1) && _propertyIsEnumerable.call(this, key);
104 });
105
106 setProperty(window, '_Map', window.Map);
107 if (_Map) {
108 setProperty(window, 'Map', (function(Map) {
109 var count = 0;
110 return function() {
111 if (count++) {
112 return new Map;
113 }
114 var result = {};
115 setProperty(window, 'Map', Map);
116 return result;
117 };
118 }(_Map)));
119
120 setProperty(Map, 'toString', createToString('Map'));
121 }
122 setProperty(window, '_Promise', window.Promise);
123 setProperty(window, 'Promise', noop);
124
125 setProperty(window, '_Set', window.Set);
126 setProperty(window, 'Set', noop);
127
128 setProperty(window, '_Symbol', window.Symbol);
129 setProperty(window, 'Symbol', undefined);
130
131 setProperty(window, '_WeakMap', window.WeakMap);
132 setProperty(window, 'WeakMap', noop);
133
134 // Fake `WinRTError`.
135 setProperty(window, 'WinRTError', Error);
136
137 // Fake free variable `global`.
138 setProperty(window, 'exports', window);
139 setProperty(window, 'global', window);
140 setProperty(window, 'module', {});
141 }
142
143 function removeBizarroMethods() {
144 var funcProto = Function.prototype,
145 objectProto = Object.prototype;
146
147 setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
148
149 if (Object._create) {
150 Object.create = Object._create;
151 } else {
152 delete Object.create;
153 }
154 if (Object._getOwnPropertySymbols) {
155 Object.getOwnPropertySymbols = Object._getOwnPropertySymbols;
156 } else {
157 delete Object.getOwnPropertySymbols;
158 }
159 if (_Map) {
160 Map = _Map;
161 } else {
162 setProperty(window, 'Map', undefined);
163 }
164 if (_Promise) {
165 Promise = _Promise;
166 } else {
167 setProperty(window, 'Promise', undefined);
168 }
169 if (_Set) {
170 Set = _Set;
171 } else {
172 setProperty(window, 'Set', undefined);
173 }
174 if (_Symbol) {
175 Symbol = _Symbol;
176 }
177 if (_WeakMap) {
178 WeakMap = _WeakMap;
179 } else {
180 setProperty(window, 'WeakMap', undefined);
181 }
182 setProperty(window, '_Map', undefined);
183 setProperty(window, '_Promise', undefined);
184 setProperty(window, '_Set', undefined);
185 setProperty(window, '_Symbol', undefined);
186 setProperty(window, '_WeakMap', undefined);
187
188 setProperty(window, 'WinRTError', undefined);
189
190 setProperty(window, 'exports', document.getElementById('exports'));
191 setProperty(window, 'global', undefined);
192 setProperty(window, 'module', document.getElementById('module'));
193
194 delete funcProto._method;
195 delete Object._create;
196 delete Object._getOwnPropertySymbols;
197 delete objectProto._propertyIsEnumerable;
198 }
199
200 // Load lodash to expose it to the bad extensions/shims.
201 if (!ui.isModularize) {
202 addBizarroMethods();
203 document.write('<script src="' + ui.buildPath + '"><\/script>');
204 }
205 </script>
206 <script>
207 // Store lodash to test for bad extensions/shims.
208 if (!ui.isModularize) {
209 var lodashBizarro = window._;
210 window._ = undefined;
211 removeBizarroMethods();
212 }
213 // Load test scripts.
214 document.write((ui.isForeign || ui.urlParams.loader == 'none')
215 ? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
216 : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
217 );
218 </script>
219 <script>
220 var lodashModule,
221 shimmedModule,
222 underscoreModule;
223
224 (function() {
225 if (window.curl) {
226 curl.config({ 'apiName': 'require' });
227 }
228 if (ui.isForeign || !window.require) {
229 return;
230 }
231 var reBasename = /[\w.-]+$/,
232 basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
233 modulePath = ui.buildPath.replace(/\.js$/, ''),
234 moduleMain = modulePath.match(reBasename)[0],
235 locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
236 shimmedLocationPath = './abc/../' + locationPath,
237 underscoreLocationPath = './xyz/../' + locationPath,
238 uid = +new Date;
239
240 function getConfig() {
241 var result = {
242 'baseUrl': './',
243 'urlArgs': 't=' + uid++,
244 'waitSeconds': 0,
245 'paths': {},
246 'packages': [{
247 'name': 'test',
248 'location': basePath + 'test',
249 'main': 'test',
250 'config': {
251 // Work around no global being exported.
252 'exports': 'QUnit',
253 'loader': 'curl/loader/legacy'
254 }
255 }],
256 'shim': {
257 'shimmed': {
258 'exports': '_'
259 }
260 }
261 };
262
263 if (ui.isModularize) {
264 result.packages.push({
265 'name': 'lodash',
266 'location': locationPath,
267 'main': moduleMain
268 }, {
269 'name': 'shimmed',
270 'location': shimmedLocationPath,
271 'main': moduleMain
272 }, {
273 'name': 'underscore',
274 'location': underscoreLocationPath,
275 'main': moduleMain
276 });
277 } else {
278 result.paths.lodash = modulePath;
279 result.paths.shimmed = shimmedLocationPath + '/' + moduleMain;
280 result.paths.underscore = underscoreLocationPath + '/' + moduleMain;
281 }
282 return result;
283 }
284
285 function loadTests() {
286 require(getConfig(), ['test'], function() {
287 QUnit.start();
288 });
289 }
290
291 function loadModulesAndTests() {
292 require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
293 lodashModule = lodash;
294 lodashModule.moduleName = 'lodash';
295
296 if (shimmed) {
297 shimmedModule = shimmed.result(shimmed, 'noConflict') || shimmed;
298 shimmedModule.moduleName = 'shimmed';
299 }
300 if (underscore) {
301 underscoreModule = underscore.result(underscore, 'noConflict') || underscore;
302 underscoreModule.moduleName = 'underscore';
303 }
304 window._ = lodash;
305
306 if (ui.isModularize) {
307 require(getConfig(), [
308 'lodash/_baseEach',
309 'lodash/_isIndex',
310 'lodash/_isIterateeCall'
311 ], function(baseEach, isIndex, isIterateeCall) {
312 lodash._baseEach = baseEach;
313 lodash._isIndex = isIndex;
314 lodash._isIterateeCall = isIterateeCall;
315 loadTests();
316 });
317 } else {
318 loadTests();
319 }
320 });
321 }
322
323 QUnit.config.autostart = false;
324
325 if (window.requirejs) {
326 addBizarroMethods();
327 require(getConfig(), ['lodash'], function(lodash) {
328 lodashBizarro = lodash.result(lodash, 'noConflict') || lodash;
329 delete requirejs.s.contexts._;
330
331 removeBizarroMethods();
332 loadModulesAndTests();
333 });
334 } else {
335 loadModulesAndTests();
336 }
337 }());
338
339 // Set a more readable browser name.
340 window.onload = function() {
341 var timeoutId = setInterval(function() {
342 var ua = document.getElementById('qunit-userAgent');
343 if (ua) {
344 ua.innerHTML = platform;
345 clearInterval(timeoutId);
346 }
347 }, 16);
348 };
349 </script>
350 </body>
351</html>