|
33 | 33 | global.QUnit
|
34 | 34 | );
|
35 | 35 |
|
| 36 | + /** Shortcut used to push arrays of values to an array */ |
| 37 | + var push = Array.prototype.push; |
| 38 | + |
36 | 39 | /** The time limit for the tests to run (milliseconds) */
|
37 | 40 | var timeLimit = process.argv.reduce(function(result, value, index) {
|
38 | 41 | if (/--time-limit/.test(value)) {
|
|
308 | 311 |
|
309 | 312 | /*--------------------------------------------------------------------------*/
|
310 | 313 |
|
| 314 | + /** |
| 315 | + * Capitalizes a given string. |
| 316 | + * |
| 317 | + * @private |
| 318 | + * @param {String} string The string to capitalize. |
| 319 | + * @returns {String} Returns the capitalized string. |
| 320 | + */ |
| 321 | + function capitalize(string) { |
| 322 | + return string[0].toUpperCase() + string.toLowerCase().slice(1); |
| 323 | + } |
| 324 | + |
311 | 325 | /**
|
312 | 326 | * Creates a context object to use with `vm.runInContext`.
|
313 | 327 | *
|
|
331 | 345 | function expandMethodNames(methodNames) {
|
332 | 346 | return methodNames.reduce(function(result, methodName) {
|
333 | 347 | var realName = getRealName(methodName);
|
334 |
| - result.push.apply(result, [realName].concat(getAliases(realName))); |
| 348 | + push.apply(result, [realName].concat(getAliases(realName))); |
335 | 349 | return result;
|
336 | 350 | }, []);
|
337 | 351 | }
|
|
1365 | 1379 | var methodNames,
|
1366 | 1380 | basename = path.basename(data.outputPath, '.js'),
|
1367 | 1381 | context = createContext(),
|
1368 |
| - isUnderscore = /backbone|underscore/.test(command), |
| 1382 | + isBackbone = /backbone/.test(command), |
| 1383 | + isUnderscore = isBackbone || /underscore/.test(command), |
1369 | 1384 | exposeAssign = !isUnderscore,
|
1370 |
| - exposeCreateCallback = !isUnderscore, |
1371 |
| - exposeForIn = !isUnderscore, |
1372 |
| - exposeForOwn = !isUnderscore, |
1373 |
| - exposeIsPlainObject = !isUnderscore, |
1374 | 1385 | exposeZipObject = !isUnderscore;
|
1375 | 1386 |
|
1376 | 1387 | try {
|
|
1389 | 1400 | if (isUnderscore) {
|
1390 | 1401 | if (methodNames) {
|
1391 | 1402 | exposeAssign = methodNames.indexOf('assign') > -1;
|
1392 |
| - exposeCreateCallback = methodNames.indexOf('createCallback') > -1; |
1393 | 1403 | exposeZipObject = methodNames.indexOf('zipObject') > -1;
|
1394 | 1404 | } else {
|
1395 | 1405 | methodNames = underscoreMethods.slice();
|
1396 | 1406 | }
|
1397 | 1407 | }
|
1398 |
| - // add method names explicitly by category |
1399 | 1408 | if (/category/.test(command)) {
|
1400 |
| - // resolve method names belonging to each category (case-insensitive) |
1401 |
| - methodNames = command.match(/category=(\S*)/)[1].split(/, */).reduce(function(result, category) { |
1402 |
| - var capitalized = category[0].toUpperCase() + category.toLowerCase().slice(1); |
1403 |
| - return result.concat(getMethodsByCategory(capitalized)); |
1404 |
| - }, methodNames || []); |
| 1409 | + methodNames = (methodNames || []).concat(command.match(/category=(\S*)/)[1].split(/, */).map(capitalize)); |
1405 | 1410 | }
|
1406 |
| - // init `methodNames` if it hasn't been inited |
1407 | 1411 | if (!methodNames) {
|
1408 | 1412 | methodNames = allMethods.slice();
|
1409 | 1413 | }
|
1410 | 1414 | if (/plus/.test(command)) {
|
1411 | 1415 | methodNames = methodNames.concat(command.match(/plus=(\S*)/)[1].split(/, */));
|
1412 | 1416 | }
|
1413 | 1417 | if (/minus/.test(command)) {
|
1414 |
| - methodNames = _.without.apply(_, [methodNames] |
1415 |
| - .concat(expandMethodNames(command.match(/minus=(\S*)/)[1].split(/, */)))); |
| 1418 | + methodNames = _.without.apply(_, [methodNames].concat(expandMethodNames(command.match(/minus=(\S*)/)[1].split(/, */)))); |
1416 | 1419 | }
|
1417 | 1420 | if (/exclude/.test(command)) {
|
1418 |
| - methodNames = _.without.apply(_, [methodNames] |
1419 |
| - .concat(expandMethodNames(command.match(/exclude=(\S*)/)[1].split(/, */)))); |
| 1421 | + methodNames = _.without.apply(_, [methodNames].concat(expandMethodNames(command.match(/exclude=(\S*)/)[1].split(/, */)))); |
1420 | 1422 | }
|
1421 | 1423 |
|
1422 |
| - // expand aliases and categories to real method names |
1423 |
| - methodNames = expandMethodNames(methodNames).reduce(function(result, methodName) { |
1424 |
| - return result.concat(methodName, getMethodsByCategory(methodName)); |
1425 |
| - }, []); |
| 1424 | + // expand categories to real method names |
| 1425 | + methodNames.slice().forEach(function(category) { |
| 1426 | + var result = getMethodsByCategory(category); |
| 1427 | + |
| 1428 | + // limit category methods to those available for specific builds |
| 1429 | + if (isBackbone) { |
| 1430 | + result = result.filter(function(methodName) { |
| 1431 | + return _.contains(backboneDependencies, methodName); |
| 1432 | + }); |
| 1433 | + } |
| 1434 | + else if (isUnderscore) { |
| 1435 | + result = result.filter(function(methodName) { |
| 1436 | + return _.contains(underscoreMethods, methodName); |
| 1437 | + }); |
| 1438 | + } |
| 1439 | + if (result.length) { |
| 1440 | + methodNames = _.without(methodNames, category); |
| 1441 | + push.apply(methodNames, result); |
| 1442 | + } |
| 1443 | + }); |
1426 | 1444 |
|
1427 |
| - // remove nonexistent and duplicate method names |
| 1445 | + // expand aliases and remove nonexistent and duplicate method names |
1428 | 1446 | methodNames = _.uniq(_.intersection(allMethods, expandMethodNames(methodNames)));
|
1429 | 1447 |
|
1430 |
| - if (isUnderscore) { |
1431 |
| - methodNames = _.without.apply(_, [methodNames].concat(['findIndex', 'findKey'])); |
1432 |
| - } |
1433 | 1448 | if (!exposeAssign) {
|
1434 | 1449 | methodNames = _.without(methodNames, 'assign');
|
1435 | 1450 | }
|
1436 |
| - if (!exposeCreateCallback) { |
1437 |
| - methodNames = _.without(methodNames, 'createCallback'); |
1438 |
| - } |
1439 |
| - if (!exposeForIn) { |
1440 |
| - methodNames = _.without(methodNames, 'forIn'); |
1441 |
| - } |
1442 |
| - if (!exposeForOwn) { |
1443 |
| - methodNames = _.without(methodNames, 'forOwn'); |
1444 |
| - } |
1445 |
| - if (!exposeIsPlainObject) { |
1446 |
| - methodNames = _.without(methodNames, 'isPlainobject'); |
1447 |
| - } |
1448 | 1451 | if (!exposeZipObject) {
|
1449 | 1452 | methodNames = _.without(methodNames, 'zipObject');
|
1450 | 1453 | }
|
|
0 commit comments