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 "sorted indexOf doesn't uses binary search",
64 'returns all but the last n elements',
65 'returns an empty array when n > length',
66 'works on an arguments object'
69 'can perform an OO-style intersection'
72 'returns an empty array when n <= 0 (0 case)',
73 'returns an empty array when n <= 0 (negative case)',
74 'can fetch the last n elements',
75 'returns the whole array if n > length'
78 'should treat falsey `fromIndex` values, except `0` and `NaN`, as `array.length`',
79 'should treat non-number `fromIndex` values as `array.length`',
83 'an array of pairs zipped together into an object',
84 'an object converted to pairs and back to an object'
87 'returns the whole array when index is 0',
88 'returns elements starting at the given index',
89 'works on an arguments object'
96 'is an alias for rest'
99 'is an alias for first'
102 'uses the result of `iterator` for uniqueness comparisons (unsorted case)',
103 '`sorted` argument defaults to false when omitted',
104 'when `iterator` is a string, uses that key for comparisons (unsorted case)',
105 'uses the result of `iterator` for uniqueness comparisons (sorted case)',
106 'when `iterator` is a string, uses that key for comparisons (sorted case)',
107 'can use falsey pluck like iterator'
110 'can perform an OO-style union'
117 'reverse/concat/unshift/pop/map': [
118 'can chain together array functions.'
122 'lookupIterator with contexts': true,
123 'Iterating objects with sketchy length properties': true,
124 'Resistant to collection length and properties changing while iterating': true,
130 'context object property accessed'
133 'Can be called with object',
142 'called with context'
145 'checks properties given function'
152 "doesn't delegate to binary search"
155 'handles null & undefined'
158 'tripled numbers with context',
159 'OO-style doubled numbers'
162 'can handle null/undefined',
163 'can perform a computation-based max',
164 'Maximum value of an empty object',
165 'Maximum value of an empty array',
166 'Maximum value of a non-numeric collection',
167 'Finds correct max in array starting with num and containing a NaN',
168 'Finds correct max in array starting with NaN',
169 'Respects iterator return value of -Infinity',
170 'String keys use property iterator',
172 'Lookup falsy iterator'
175 'can handle null/undefined',
176 'can perform a computation-based min',
177 'Minimum value of an empty object',
178 'Minimum value of an empty array',
179 'Minimum value of a non-numeric collection',
180 'Finds correct min in array starting with NaN',
181 'Respects iterator return value of Infinity',
182 'String keys use property iterator',
184 'Lookup falsy iterator'
187 'can reference the array index',
189 'partition takes a context argument'
195 'can reduce with a context object'
198 'Returns empty list given empty array'
201 'behaves correctly on negative n',
205 'Can be called with object',
210 'checks properties given function'
212 'Can use various collection methods on NodeLists': [
213 '<span id="id2"></span>'
217 'debounce asap': true,
218 'debounce asap cancel': true,
219 'debounce asap recursively': true,
220 'debounce after system time is set backwards': true,
221 'debounce re-entrant': true,
222 'throttle repeatedly with results': true,
223 'more throttle does not trigger leading call when leading is set to false': true,
224 'throttle does not trigger trailing call when trailing is set to false': true,
230 'throws an error for bindAll with no functions named'
241 '{"bar":"BAR","foo":"FOO"}',
246 '#1929 Typed Array constructors are functions': true,
248 'is not fooled by sparse arrays; see issue #95',
249 'is not fooled by sparse arrays with additional properties',
253 'extending null results in null',
254 'extending undefined results in undefined'
257 'extending non-objects results in returning the non-object value',
258 'extending undefined results in undefined'
261 'also looks up functions on the prototype'
264 '`0` is not equal to `-0`',
265 'Commutative equality is implemented for `0` and `-0`',
266 '`new Number(0)` and `-0` are not equal',
267 'Commutative equality is implemented for `new Number(0)` and `-0`',
268 'Invalid dates are not equal',
272 'Numeric strings are numbers',
273 'Number instances can be finite'
279 'called with context'
282 'is not fooled by sparse arrays; see issue #95',
287 'called with context',
291 'can accept a predicate',
292 'function is given context'
295 'can accept a predicate and context',
296 'function is given context'
300 '_.escape & unescape': [
302 '` can be unescaped',
303 'can escape multiple occurances of `',
304 'multiple occurrences of ` can be unescaped'
307 'Produces the correct time in milliseconds'
315 var mixinPrereqs = (function() {
321 'compose': 'flowRight',
322 'contains': 'includes',
324 'extendOwn': 'assign',
327 'foldr': 'reduceRight',
328 'include': 'includes',
331 'invoke': 'invokeMap',
332 'mapObject': 'mapValues',
333 'matcher': 'matches',
334 'methods': 'functions',
335 'object': 'zipObject',
338 'restParam': 'restArgs',
349 var lodash = _.noConflict();
353 .defaultsDeep({ 'templateSettings': lodash.templateSettings })
354 .mixin(lodash.pick(lodash, lodash.difference(lodash.functions(lodash), lodash.functions(_))))
357 lodash.forOwn(keyMap, function(realName, otherName) {
358 _[otherName] = lodash[realName];
359 _.prototype[otherName] = lodash.prototype[realName];
361 lodash.forOwn(aliasToReal, function(realName, alias) {
362 _[alias] = _[realName];
363 _.prototype[alias] = _.prototype[realName];
369 // Only excuse in Sauce Labs.
370 if (!ui.isSauceLabs) {
371 delete QUnit.config.excused.Functions['throttle does not trigger trailing call when trailing is set to false'];
372 delete QUnit.config.excused.Utility.now;
374 // Load prerequisite scripts.
375 document.write(ui.urlParams.loader == 'none'
376 ? '<script src="' + ui.buildPath + '"><\/script>'
377 : '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
381 if (ui.urlParams.loader == 'none') {
384 '<script src="../vendor/underscore/test/collections.js"><\/script>',
385 '<script src="../vendor/underscore/test/arrays.js"><\/script>',
386 '<script src="../vendor/underscore/test/functions.js"><\/script>',
387 '<script src="../vendor/underscore/test/objects.js"><\/script>',
388 '<script src="../vendor/underscore/test/cross-document.js"><\/script>',
389 '<script src="../vendor/underscore/test/utility.js"><\/script>',
390 '<script src="../vendor/underscore/test/chaining.js"><\/script>'
397 curl.config({ 'apiName': 'require' });
399 if (!window.require) {
402 // Wrap to work around tests assuming Node `require` use.
403 require = (function(func) {
405 return arguments[0] === '..' ? window._ : func.apply(null, arguments);
409 var reBasename = /[\w.-]+$/,
410 basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
411 modulePath = ui.buildPath.replace(/\.js$/, ''),
412 locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
413 moduleId = /\bunderscore\b/i.test(ui.buildPath) ? 'underscore' : 'lodash',
414 moduleMain = modulePath.match(reBasename)[0],
417 function getConfig() {
420 'urlArgs': 't=' + uid++,
425 'location': '../vendor/underscore/test',
427 // Work around no global being exported.
429 'loader': 'curl/loader/legacy'
434 if (ui.isModularize) {
435 result.packages.push({
437 'location': locationPath,
441 result.paths[moduleId] = modulePath;
446 QUnit.config.autostart = false;
447 QUnit.config.excused.Functions.iteratee = true;
448 QUnit.config.excused.Utility.noConflict = true;
449 QUnit.config.excused.Utility['noConflict (node vm)'] = true;
451 require(getConfig(), [moduleId], function(lodash) {
452 _ = mixinPrereqs(lodash);
453 require(getConfig(), [
458 'test/cross-document',