blob: a3e56e81907e92de113353f45bb0ecfdede937aa [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>Underscore Test Suite</title>
6 <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
7 </head>
8 <body>
9 <div id="qunit"></div>
10 <script>
11 // Avoid reporting tests to Sauce Labs when script errors occur.
12 if (location.port == '9001') {
13 window.onerror = function(message) {
14 if (window.QUnit) {
15 QUnit.config.done.length = 0;
16 }
17 global_test_results = { 'message': message };
18 };
19 }
20 </script>
21 <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
22 <script src="../node_modules/qunit-extras/qunit-extras.js"></script>
23 <script src="../node_modules/jquery/dist/jquery.js"></script>
24 <script src="../node_modules/platform/platform.js"></script>
25 <script src="./asset/test-ui.js"></script>
26 <script src="../lodash.js"></script>
27 <script>
28 QUnit.config.asyncRetries = 10;
29 QUnit.config.hidepassed = true;
30 QUnit.config.excused = {
31 'Arrays': {
32 'chunk': [
33 'defaults to empty array (chunk size 0)'
34 ],
35 'difference': [
36 'can perform an OO-style difference'
37 ],
38 'drop': [
39 'is an alias for rest'
40 ],
41 'first': [
42 'returns an empty array when n <= 0 (0 case)',
43 'returns an empty array when n <= 0 (negative case)',
44 'can fetch the first n elements',
45 'returns the whole array if n > length'
46 ],
47 'findIndex': [
48 'called with context'
49 ],
50 'findLastIndex': [
51 'called with context'
52 ],
53 'flatten': [
54 'supports empty arrays',
55 'can flatten nested arrays',
56 'works on an arguments object',
57 'can handle very deep arrays'
58 ],
59 'head': [
60 'is an alias for first'
61 ],
62 'indexOf': [
63 "sorted indexOf doesn't uses binary search",
64 '0'
65 ],
66 'initial': [
67 'returns all but the last n elements',
68 'returns an empty array when n > length',
69 'works on an arguments object'
70 ],
71 'intersection': [
72 'can perform an OO-style intersection'
73 ],
74 'last': [
75 'returns an empty array when n <= 0 (0 case)',
76 'returns an empty array when n <= 0 (negative case)',
77 'can fetch the last n elements',
78 'returns the whole array if n > length'
79 ],
80 'lastIndexOf': [
81 'should treat falsey `fromIndex` values, except `0` and `NaN`, as `array.length`',
82 'should treat non-number `fromIndex` values as `array.length`',
83 '[0,-1,-1]'
84 ],
85 'object': [
86 'an array of pairs zipped together into an object',
87 'an object converted to pairs and back to an object'
88 ],
89 'range': [
90 'range with two arguments a &amp; b, b&lt;a generates an empty array'
91 ],
92 'rest': [
93 'returns the whole array when index is 0',
94 'returns elements starting at the given index',
95 'works on an arguments object'
96 ],
97 'sortedIndex': [
98 '2',
99 '3'
100 ],
101 'tail': [
102 'is an alias for rest'
103 ],
104 'take': [
105 'is an alias for first'
106 ],
107 'uniq': [
108 'uses the result of `iterator` for uniqueness comparisons (unsorted case)',
109 '`sorted` argument defaults to false when omitted',
110 'when `iterator` is a string, uses that key for comparisons (unsorted case)',
111 'uses the result of `iterator` for uniqueness comparisons (sorted case)',
112 'when `iterator` is a string, uses that key for comparisons (sorted case)',
113 'can use falsey pluck like iterator'
114 ],
115 'union': [
116 'can perform an OO-style union'
117 ]
118 },
119 'Chaining': {
120 'pop': true,
121 'shift': true,
122 'splice': true,
123 'reverse/concat/unshift/pop/map': [
124 'can chain together array functions.'
125 ]
126 },
127 'Collections': {
128 'lookupIterator with contexts': true,
129 'Iterating objects with sketchy length properties': true,
130 'Resistant to collection length and properties changing while iterating': true,
131 'countBy': [
132 'true'
133 ],
134 'each': [
135 'context object property accessed'
136 ],
137 'every': [
138 'Can be called with object',
139 'Died on test #15',
140 'context works'
141 ],
142 'filter': [
143 'given context',
144 '[{"a":1,"b":2},{"a":1,"b":3},{"a":1,"b":4}]',
145 '[{"a":1,"b":2},{"a":2,"b":2}]',
146 'Empty object accepts all items',
147 'OO-filter'
148 ],
149 'find': [
150 '{"a":1,"b":4}',
151 'undefined when not found',
152 'undefined when searching empty list',
153 'works on objects',
154 'undefined',
155 'called with context'
156 ],
157 'findWhere': [
158 'checks properties given function'
159 ],
160 'groupBy': [
161 'true'
162 ],
163 'includes': [
164 "doesn't delegate to binary search"
165 ],
166 'invoke': [
167 'handles null & undefined'
168 ],
169 'map': [
170 'tripled numbers with context',
171 'OO-style doubled numbers'
172 ],
173 'max': [
174 'can handle null/undefined',
175 'can perform a computation-based max',
176 'Maximum value of an empty object',
177 'Maximum value of an empty array',
178 'Maximum value of a non-numeric collection',
179 'Finds correct max in array starting with num and containing a NaN',
180 'Finds correct max in array starting with NaN',
181 'Respects iterator return value of -Infinity',
182 'String keys use property iterator',
183 'Iterator context',
184 'Lookup falsy iterator'
185 ],
186 'min': [
187 'can handle null/undefined',
188 'can perform a computation-based min',
189 'Minimum value of an empty object',
190 'Minimum value of an empty array',
191 'Minimum value of a non-numeric collection',
192 'Finds correct min in array starting with NaN',
193 'Respects iterator return value of Infinity',
194 'String keys use property iterator',
195 'Iterator context',
196 'Lookup falsy iterator'
197 ],
198 'partition': [
199 'can reference the array index',
200 'Died on test #8',
201 'partition takes a context argument',
202 'function(a){[code]}'
203 ],
204 'pluck': [
205 '[1]'
206 ],
207 'reduce': [
208 'can reduce with a context object'
209 ],
210 'reject': [
211 'Returns empty list given empty array'
212 ],
213 'sample': [
214 'behaves correctly on negative n',
215 'Died on test #3'
216 ],
217 'some': [
218 'Can be called with object',
219 'Died on test #17',
220 'context works'
221 ],
222 'where': [
223 'checks properties given function'
224 ],
225 'Can use various collection methods on NodeLists': [
226 '<span id="id2"></span>',
227 '<span id="id1"></span>'
228 ]
229 },
230 'Functions': {
231 'debounce asap': true,
232 'debounce asap cancel': true,
233 'debounce after system time is set backwards': true,
234 'debounce asap recursively': true,
235 'throttle repeatedly with results': true,
236 'more throttle does not trigger leading call when leading is set to false': true,
237 'throttle does not trigger trailing call when trailing is set to false': true,
238 'before': [
239 'stores a memo to the last value',
240 'provides context'
241 ],
242 'bind': [
243 'Died on test #2'
244 ],
245 'bindAll': [
246 'throws an error for bindAll with no functions named'
247 ],
248 'memoize': [
249 '{"bar":"BAR","foo":"FOO"}',
250 'Died on test #8'
251 ],
252 'partial':[
253 'can partially apply with placeholders',
254 'accepts more arguments than the number of placeholders',
255 'accepts fewer arguments than the number of placeholders',
256 'unfilled placeholders are undefined',
257 'keeps prototype',
258 'allows the placeholder to be swapped out'
259 ]
260 },
261 'Objects': {
262 '#1929 Typed Array constructors are functions': true,
263 'allKeys': [
264 'is not fooled by sparse arrays; see issue #95',
265 'is not fooled by sparse arrays with additional properties',
266 '[]'
267 ],
268 'defaults': [
269 'defaults skips nulls',
270 'defaults skips undefined'
271 ],
272 'extend': [
273 'extending null results in null',
274 'extending undefined results in undefined'
275 ],
276 'extendOwn': [
277 'extending non-objects results in returning the non-object value',
278 'extending undefined results in undefined'
279 ],
280 'functions': [
281 'also looks up functions on the prototype'
282 ],
283 'isEqual': [
284 '`0` is not equal to `-0`',
285 'Commutative equality is implemented for `0` and `-0`',
286 '`new Number(0)` and `-0` are not equal',
287 'Commutative equality is implemented for `new Number(0)` and `-0`',
288 'false'
289 ],
290 'isFinite': [
291 'Numeric strings are numbers',
292 'Number instances can be finite'
293 ],
294 'isMatch': [
295 'doesnt falsey match constructor on undefined/null'
296 ],
297 'isSet': [
298 'Died on test #9'
299 ],
300 'findKey': [
301 'called with context'
302 ],
303 'keys': [
304 'is not fooled by sparse arrays; see issue #95',
305 '[]'
306 ],
307 'mapObject': [
308 'keep context',
309 'called with context',
310 'mapValue identity'
311 ],
312 'matcher': [
313 'null matches null',
314 'treats primitives as empty'
315 ],
316 'omit': [
317 'can accept a predicate',
318 'function is given context'
319 ],
320 'pick': [
321 'can accept a predicate and context',
322 'function is given context'
323 ]
324 },
325 'Utility': {
326 'noConflict (node vm)': true,
327 'now': [
328 'Produces the correct time in milliseconds'
329 ],
330 'times': [
331 'works as a wrapper'
332 ]
333 }
334 };
335
336 var mixinPrereqs = (function() {
337 var aliasToReal = {
338 'all': 'every',
339 'allKeys': 'keysIn',
340 'any': 'some',
341 'collect': 'map',
342 'compose': 'flowRight',
343 'contains': 'includes',
344 'detect': 'find',
345 'extendOwn': 'assign',
346 'findWhere': 'find',
347 'foldl': 'reduce',
348 'foldr': 'reduceRight',
349 'include': 'includes',
350 'indexBy': 'keyBy',
351 'inject': 'reduce',
352 'invoke': 'invokeMap',
353 'mapObject': 'mapValues',
354 'matcher': 'matches',
355 'methods': 'functions',
356 'object': 'zipObject',
357 'pairs': 'toPairs',
358 'pluck': 'map',
359 'restParam': 'restArgs',
360 'select': 'filter',
361 'unique': 'uniq',
362 'where': 'filter'
363 };
364
365 var keyMap = {
366 'rest': 'tail',
367 'restArgs': 'rest'
368 };
369
370 var lodash = _.noConflict();
371
372 return function(_) {
373 lodash.defaultsDeep(_, { 'templateSettings': lodash.templateSettings });
374 lodash.mixin(_, lodash.pick(lodash, lodash.difference(lodash.functions(lodash), lodash.functions(_))));
375
376 lodash.forOwn(keyMap, function(realName, otherName) {
377 _[otherName] = lodash[realName];
378 _.prototype[otherName] = lodash.prototype[realName];
379 });
380
381 lodash.forOwn(aliasToReal, function(realName, alias) {
382 _[alias] = _[realName];
383 _.prototype[alias] = _.prototype[realName];
384 });
385 };
386 }());
387
388 // Only excuse in Sauce Labs.
389 if (!ui.isSauceLabs) {
390 delete QUnit.config.excused.Functions['throttle does not trigger trailing call when trailing is set to false'];
391 delete QUnit.config.excused.Utility.now;
392 }
393 // Load prerequisite scripts.
394 document.write(ui.urlParams.loader == 'none'
395 ? '<script src="' + ui.buildPath + '"><\/script>'
396 : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
397 );
398 </script>
399 <script>
400 if (ui.urlParams.loader == 'none') {
401 mixinPrereqs(_);
402 document.write([
403 '<script src="../vendor/underscore/test/collections.js"><\/script>',
404 '<script src="../vendor/underscore/test/arrays.js"><\/script>',
405 '<script src="../vendor/underscore/test/functions.js"><\/script>',
406 '<script src="../vendor/underscore/test/objects.js"><\/script>',
407 '<script src="../vendor/underscore/test/cross-document.js"><\/script>',
408 '<script src="../vendor/underscore/test/utility.js"><\/script>',
409 '<script src="../vendor/underscore/test/chaining.js"><\/script>'
410 ].join('\n'));
411 }
412 </script>
413 <script>
414 (function() {
415 if (window.curl) {
416 curl.config({ 'apiName': 'require' });
417 }
418 if (!window.require) {
419 return;
420 }
421 // Wrap to work around tests assuming Node `require` use.
422 require = (function(func) {
423 return function() {
424 return arguments[0] === '..' ? window._ : func.apply(null, arguments);
425 };
426 }(require));
427
428 var reBasename = /[\w.-]+$/,
429 basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
430 modulePath = ui.buildPath.replace(/\.js$/, ''),
431 locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
432 moduleId = /\bunderscore\b/i.test(ui.buildPath) ? 'underscore' : 'lodash',
433 moduleMain = modulePath.match(reBasename)[0],
434 uid = +new Date;
435
436 function getConfig() {
437 var result = {
438 'baseUrl': './',
439 'urlArgs': 't=' + uid++,
440 'waitSeconds': 0,
441 'paths': {},
442 'packages': [{
443 'name': 'test',
444 'location': '../vendor/underscore/test',
445 'config': {
446 // Work around no global being exported.
447 'exports': 'QUnit',
448 'loader': 'curl/loader/legacy'
449 }
450 }]
451 };
452
453 if (ui.isModularize) {
454 result.packages.push({
455 'name': moduleId,
456 'location': locationPath,
457 'main': moduleMain
458 });
459 } else {
460 result.paths[moduleId] = modulePath;
461 }
462 return result;
463 }
464
465 QUnit.config.autostart = false;
466
467 require(getConfig(), [moduleId], function(lodash) {
468 mixinPrereqs(lodash);
469 require(getConfig(), [
470 'test/collections',
471 'test/arrays',
472 'test/functions',
473 'test/objects',
474 'test/cross-document',
475 'test/utility',
476 'test/chaining'
477 ], function() {
478 QUnit.start();
479 });
480 });
481 }());
482 </script>
483 </body>
484</html>