5 <title>Underscore Test Suite</title>
6 <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
11 // Avoid reporting tests to Sauce Labs when script errors occur.
12 if (location.port == '9001') {
13 window.onerror = function(message) {
15 QUnit.config.done.length = 0;
17 global_test_results = { 'message': message };
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>
28 QUnit.config.asyncRetries = 10;
29 QUnit.config.hidepassed = true;
30 QUnit.config.excused = {
33 'defaults to empty array (chunk size 0)'
36 'can perform an OO-style difference'
39 'is an alias for rest'
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'
54 'supports empty arrays',
55 'can flatten nested arrays',
56 'works on an arguments object',
57 'can handle very deep arrays'
60 'is an alias for first'
63 "sorted indexOf doesn't uses binary search",
67 'returns all but the last n elements',
68 'returns an empty array when n > length',
69 'works on an arguments object'
72 'can perform an OO-style intersection'
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'
81 'should treat falsey `fromIndex` values, except `0` and `NaN`, as `array.length`',
82 'should treat non-number `fromIndex` values as `array.length`',
86 'an array of pairs zipped together into an object',
87 'an object converted to pairs and back to an object'
90 'range with two arguments a & b, b<a generates an empty array'
93 'returns the whole array when index is 0',
94 'returns elements starting at the given index',
95 'works on an arguments object'
102 'is an alias for rest'
105 'is an alias for first'
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'
116 'can perform an OO-style union'
123 'reverse/concat/unshift/pop/map': [
124 'can chain together array functions.'
128 'lookupIterator with contexts': true,
129 'Iterating objects with sketchy length properties': true,
130 'Resistant to collection length and properties changing while iterating': true,
135 'context object property accessed'
138 'Can be called with object',
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',
151 'undefined when not found',
152 'undefined when searching empty list',
155 'called with context'
158 'checks properties given function'
164 "doesn't delegate to binary search"
167 'handles null & undefined'
170 'tripled numbers with context',
171 'OO-style doubled numbers'
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',
184 'Lookup falsy iterator'
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',
196 'Lookup falsy iterator'
199 'can reference the array index',
201 'partition takes a context argument',
202 'function(a){[code]}'
208 'can reduce with a context object'
211 'Returns empty list given empty array'
214 'behaves correctly on negative n',
218 'Can be called with object',
223 'checks properties given function'
225 'Can use various collection methods on NodeLists': [
226 '<span id="id2"></span>',
227 '<span id="id1"></span>'
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,
239 'stores a memo to the last value',
246 'throws an error for bindAll with no functions named'
249 '{"bar":"BAR","foo":"FOO"}',
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',
258 'allows the placeholder to be swapped out'
262 '#1929 Typed Array constructors are functions': true,
264 'is not fooled by sparse arrays; see issue #95',
265 'is not fooled by sparse arrays with additional properties',
269 'defaults skips nulls',
270 'defaults skips undefined'
273 'extending null results in null',
274 'extending undefined results in undefined'
277 'extending non-objects results in returning the non-object value',
278 'extending undefined results in undefined'
281 'also looks up functions on the prototype'
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`',
291 'Numeric strings are numbers',
292 'Number instances can be finite'
295 'doesnt falsey match constructor on undefined/null'
301 'called with context'
304 'is not fooled by sparse arrays; see issue #95',
309 'called with context',
314 'treats primitives as empty'
317 'can accept a predicate',
318 'function is given context'
321 'can accept a predicate and context',
322 'function is given context'
326 'noConflict (node vm)': true,
328 'Produces the correct time in milliseconds'
336 var mixinPrereqs = (function() {
342 'compose': 'flowRight',
343 'contains': 'includes',
345 'extendOwn': 'assign',
348 'foldr': 'reduceRight',
349 'include': 'includes',
352 'invoke': 'invokeMap',
353 'mapObject': 'mapValues',
354 'matcher': 'matches',
355 'methods': 'functions',
356 'object': 'zipObject',
359 'restParam': 'restArgs',
370 var lodash = _.noConflict();
373 lodash.defaultsDeep(_, { 'templateSettings': lodash.templateSettings });
374 lodash.mixin(_, lodash.pick(lodash, lodash.difference(lodash.functions(lodash), lodash.functions(_))));
376 lodash.forOwn(keyMap, function(realName, otherName) {
377 _[otherName] = lodash[realName];
378 _.prototype[otherName] = lodash.prototype[realName];
381 lodash.forOwn(aliasToReal, function(realName, alias) {
382 _[alias] = _[realName];
383 _.prototype[alias] = _.prototype[realName];
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;
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>'
400 if (ui.urlParams.loader == 'none') {
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>'
416 curl.config({ 'apiName': 'require' });
418 if (!window.require) {
421 // Wrap to work around tests assuming Node `require` use.
422 require = (function(func) {
424 return arguments[0] === '..' ? window._ : func.apply(null, arguments);
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],
436 function getConfig() {
439 'urlArgs': 't=' + uid++,
444 'location': '../vendor/underscore/test',
446 // Work around no global being exported.
448 'loader': 'curl/loader/legacy'
453 if (ui.isModularize) {
454 result.packages.push({
456 'location': locationPath,
460 result.paths[moduleId] = modulePath;
465 QUnit.config.autostart = false;
467 require(getConfig(), [moduleId], function(lodash) {
468 mixinPrereqs(lodash);
469 require(getConfig(), [
474 'test/cross-document',