Make fp tests browser runnable.

This commit is contained in:
John-David Dalton
2015-12-05 23:36:02 -08:00
parent 769f78a2b7
commit 42c077de02
7 changed files with 1020 additions and 654 deletions

View File

@@ -53,6 +53,7 @@ script:
- "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || [ $TRAVIS_SECURE_ENV_VARS == false ] || $BIN $OPTION ./test.js ../lodash.min.js" - "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || [ $TRAVIS_SECURE_ENV_VARS == false ] || $BIN $OPTION ./test.js ../lodash.min.js"
- "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"lodash tests\" runner=\"test/index.html?build=../lodash.js&noglobals=true\" tags=\"development\"" - "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"lodash tests\" runner=\"test/index.html?build=../lodash.js&noglobals=true\" tags=\"development\""
- "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"lodash tests\" runner=\"test/index.html?build=../lodash.min.js&noglobals=true\" tags=\"production\"" - "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"lodash tests\" runner=\"test/index.html?build=../lodash.min.js&noglobals=true\" tags=\"production\""
- "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"lodash-fp tests\" runner=\"test/fp.html?noglobals=true\" tags=\"development\""
- "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"underscore tests\" runner=\"test/underscore.html?build=../lodash.js\" tags=\"development,underscore\"" - "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"underscore tests\" runner=\"test/underscore.html?build=../lodash.js\" tags=\"development,underscore\""
- "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"underscore tests\" runner=\"test/underscore.html?build=../lodash.min.js\" tags=\"production,underscore\"" - "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"underscore tests\" runner=\"test/underscore.html?build=../lodash.min.js\" tags=\"production,underscore\""
- "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"backbone tests\" runner=\"test/backbone.html?build=../lodash.js\" tags=\"development,backbone\"" - "[ $SAUCE_LABS == false ] || $BIN ./test/saucelabs.js name=\"backbone tests\" runner=\"test/backbone.html?build=../lodash.js\" tags=\"development,backbone\""

92
dist/lodash.fp.js vendored
View File

@@ -86,14 +86,14 @@ return /******/ (function(modules) { // webpackBootstrap
* @returns {Function|Object} Returns the converted function or object. * @returns {Function|Object} Returns the converted function or object.
*/ */
function baseConvert(util, name, func) { function baseConvert(util, name, func) {
if (!func) { if (typeof func != 'function') {
func = name; func = name;
name = null; name = undefined;
} }
if (func == null) { if (func == null) {
throw new TypeError; throw new TypeError;
} }
var isLib = name == null && typeof func.VERSION == 'string'; var isLib = name === undefined && typeof func.VERSION == 'string';
var _ = isLib ? func : { var _ = isLib ? func : {
'ary': util.ary, 'ary': util.ary,
@@ -264,19 +264,26 @@ return /******/ (function(modules) { // webpackBootstrap
// Iterate over methods for the current ary cap. // Iterate over methods for the current ary cap.
var pairs = []; var pairs = [];
each(mapping.caps, function(cap) { each(mapping.caps, function(cap) {
each(mapping.aryMethodMap[cap], function(name) { each(mapping.aryMethodMap[cap], function(key) {
var func = _[mapping.keyMap[name] || name]; var func = _[mapping.keyMap[key] || key];
if (func) { if (func) {
// Wrap the lodash method and its aliases. pairs.push([key, wrap(key, func)]);
var wrapped = wrap(name, func);
pairs.push([name, wrapped]);
each(mapping.aliasMap[name] || [], function(alias) { pairs.push([alias, wrapped]); });
} }
}); });
}); });
// Assign to `_` leaving `_.prototype` unchanged to allow chaining. // Assign to `_` leaving `_.prototype` unchanged to allow chaining.
each(pairs, function(pair) { _[pair[0]] = pair[1]; }); each(pairs, function(pair) {
_[pair[0]] = pair[1];
});
// Wrap the lodash method and its aliases.
each(keys(_), function(key) {
each(mapping.aliasMap[key] || [], function(alias) {
_[alias] = _[key];
});
});
return _; return _;
} }
@@ -291,9 +298,33 @@ return /******/ (function(modules) { // webpackBootstrap
/** Used to map method names to their aliases. */ /** Used to map method names to their aliases. */
'aliasMap': { 'aliasMap': {
'ary': ['nAry'],
'conj': ['allPass'],
'disj': ['somePass'],
'filter': ['whereEq'],
'flatten': ['unnest'],
'flow': ['pipe'],
'flowRight': ['compose'],
'forEach': ['each'], 'forEach': ['each'],
'forEachRight': ['eachRight'], 'forEachRight': ['eachRight'],
'head': ['first'] 'get': ['path'],
'getOr': ['pathOr'],
'head': ['first'],
'includes': ['contains'],
'initial': ['init'],
'isEqual': ['equals'],
'mapValues': ['mapObj'],
'matchesProperty': ['pathEq'],
'modArgs': ['useWith'],
'modArgsSet': ['converge'],
'omit': ['dissoc', 'omitAll'],
'pick': ['pickAll'],
'property': ['prop'],
'propertyOf': ['propOf'],
'rest': ['unapply'],
'some': ['all'],
'spread': ['apply'],
'zipObject': ['zipObj']
}, },
/** Used to map method names to their iteratee ary. */ /** Used to map method names to their iteratee ary. */
@@ -312,6 +343,7 @@ return /******/ (function(modules) { // webpackBootstrap
'findLast': 1, 'findLast': 1,
'findLastIndex': 1, 'findLastIndex': 1,
'findLastKey': 1, 'findLastKey': 1,
'flatMap': 1,
'forEach': 1, 'forEach': 1,
'forEachRight': 1, 'forEachRight': 1,
'forIn': 1, 'forIn': 1,
@@ -338,24 +370,26 @@ return /******/ (function(modules) { // webpackBootstrap
/** Used to map ary to method names. */ /** Used to map ary to method names. */
'aryMethodMap': { 'aryMethodMap': {
1: ( 1: (
'attempt,ceil,create,curry,floor,iteratee,invert,memoize,method,methodOf,' + 'attempt,ceil,create,curry,floor,fromPairs,iteratee,invert,over,overEvery,' +
'mixin,rest,reverse,round,runInContext,template,trim,trimLeft,trimRight,' + 'overSome,memoize,method,methodOf,mixin,rest,reverse,round,runInContext,template,' +
'words,zipObject').split(','), 'trim,trimLeft,trimRight,uniqueId,words').split(','),
2: ( 2: (
'ary,assign,at,bind,bindKey,cloneDeepWith,cloneWith,countBy,curryN,debounce,' + 'add,ary,assign,at,bind,bindKey,cloneDeepWith,cloneWith,concat,countBy,curryN,' +
'defaults,defaultsDeep,delay,difference,drop,dropRight,dropRightWhile,' + 'debounce,defaults,defaultsDeep,delay,difference,drop,dropRight,dropRightWhile,' +
'dropWhile,endsWith,every,extend,filter,find,find,findIndex,findKey,findLast,' + 'dropWhile,endsWith,every,extend,filter,find,find,findIndex,findKey,findLast,' +
'findLastIndex,findLastKey,forEach,forEachRight,forIn,forInRight,forOwn,' + 'findLastIndex,findLastKey,flatMap,forEach,forEachRight,forIn,forInRight,' +
'forOwnRight,get,groupBy,includes,indexBy,indexOf,intersection,invoke,' + 'forOwn,forOwnRight,get,groupBy,includes,indexBy,indexOf,intersection,' +
'isMatch,lastIndexOf,map,mapKeys,mapValues,maxBy,minBy,merge,omit,pad,padLeft,' + 'invoke,invokeMap,isMatch,lastIndexOf,map,mapKeys,mapValues,matchesProperty,' +
'padRight,parseInt,partition,pick,pull,pullAll,pullAt,random,range,rearg,reject,' + 'maxBy,mean,minBy,merge,modArgs,modArgsSet,omit,pad,padLeft,padRight,parseInt,' +
'partition,pick,pull,pullAll,pullAt,random,range,rangeRight,rearg,reject,' +
'remove,repeat,result,sampleSize,set,some,sortBy,sortByOrder,sortedIndexBy,' + 'remove,repeat,result,sampleSize,set,some,sortBy,sortByOrder,sortedIndexBy,' +
'sortedLastIndexBy,sortedUniqBy,startsWith,sumBy,take,takeRight,takeRightWhile,' + 'sortedLastIndexBy,sortedUniqBy,startsWith,subtract,sumBy,take,takeRight,' +
'takeWhile,throttle,times,trunc,union,uniqBy,uniqueId,without,wrap,xor,zip').split(','), 'takeRightWhile,takeWhile,throttle,times,truncate,union,uniqBy,without,wrap,' +
'xor,zip,zipObject').split(','),
3: ( 3: (
'assignWith,clamp,differenceBy,extendWith,inRange,intersectionBy,isEqualWith,' + 'assignWith,clamp,differenceBy,extendWith,getOr,inRange,intersectionBy,' +
'isMatchWith,mergeWith,omitBy,pickBy,pullAllBy,reduce,reduceRight,slice,' + 'isEqualWith,isMatchWith,mergeWith,omitBy,pickBy,pullAllBy,reduce,' +
'transform,unionBy,xorBy,zipWith').split(','), 'reduceRight,slice,transform,unionBy,xorBy,zipWith').split(','),
4: 4:
['fill'] ['fill']
}, },
@@ -377,14 +411,13 @@ return /******/ (function(modules) { // webpackBootstrap
}, },
/** Used to iterate `mapping.aryMethodMap` keys. */ /** Used to iterate `mapping.aryMethodMap` keys. */
'caps': ['1', '2', '3', '4'], 'caps': [1, 2, 3, 4],
/** Used to map keys to other keys. */ /** Used to map keys to other keys. */
'keyMap': { 'keyMap': {
'curryN': 'curry', 'curryN': 'curry',
'curryRightN': 'curryRight', 'curryRightN': 'curryRight',
'debounceOpt': 'debounce', 'getOr': 'get'
'throttleOpt': 'throttle'
}, },
/** Used to identify methods which mutate arrays or objects. */ /** Used to identify methods which mutate arrays or objects. */
@@ -413,8 +446,11 @@ return /******/ (function(modules) { // webpackBootstrap
/** Used to track methods that skip `_.rearg`. */ /** Used to track methods that skip `_.rearg`. */
'skipReargMap': { 'skipReargMap': {
'difference': true, 'difference': true,
'matchesProperty': true,
'random': true, 'random': true,
'range': true, 'range': true,
'rangeRight': true,
'zip': true,
'zipObject': true 'zipObject': true
} }
}; };

File diff suppressed because one or more lines are too long

222
dist/mapping.fp.js vendored Normal file
View File

@@ -0,0 +1,222 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["mapping"] = factory();
else
root["mapping"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {
module.exports = {
/** Used to map method names to their aliases. */
'aliasMap': {
'ary': ['nAry'],
'conj': ['allPass'],
'disj': ['somePass'],
'filter': ['whereEq'],
'flatten': ['unnest'],
'flow': ['pipe'],
'flowRight': ['compose'],
'forEach': ['each'],
'forEachRight': ['eachRight'],
'get': ['path'],
'getOr': ['pathOr'],
'head': ['first'],
'includes': ['contains'],
'initial': ['init'],
'isEqual': ['equals'],
'mapValues': ['mapObj'],
'matchesProperty': ['pathEq'],
'modArgs': ['useWith'],
'modArgsSet': ['converge'],
'omit': ['dissoc', 'omitAll'],
'pick': ['pickAll'],
'property': ['prop'],
'propertyOf': ['propOf'],
'rest': ['unapply'],
'some': ['all'],
'spread': ['apply'],
'zipObject': ['zipObj']
},
/** Used to map method names to their iteratee ary. */
'aryIterateeMap': {
'assignWith': 2,
'cloneDeepWith': 1,
'cloneWith': 1,
'dropRightWhile': 1,
'dropWhile': 1,
'every': 1,
'extendWith': 2,
'filter': 1,
'find': 1,
'findIndex': 1,
'findKey': 1,
'findLast': 1,
'findLastIndex': 1,
'findLastKey': 1,
'flatMap': 1,
'forEach': 1,
'forEachRight': 1,
'forIn': 1,
'forInRight': 1,
'forOwn': 1,
'forOwnRight': 1,
'isEqualWith': 2,
'isMatchWith': 2,
'map': 1,
'mapKeys': 1,
'mapValues': 1,
'partition': 1,
'reduce': 2,
'reduceRight': 2,
'reject': 1,
'remove': 1,
'some': 1,
'takeRightWhile': 1,
'takeWhile': 1,
'times': 1,
'transform': 2
},
/** Used to map ary to method names. */
'aryMethodMap': {
1: (
'attempt,ceil,create,curry,floor,fromPairs,iteratee,invert,over,overEvery,' +
'overSome,memoize,method,methodOf,mixin,rest,reverse,round,runInContext,template,' +
'trim,trimLeft,trimRight,uniqueId,words').split(','),
2: (
'add,ary,assign,at,bind,bindKey,cloneDeepWith,cloneWith,concat,countBy,curryN,' +
'debounce,defaults,defaultsDeep,delay,difference,drop,dropRight,dropRightWhile,' +
'dropWhile,endsWith,every,extend,filter,find,find,findIndex,findKey,findLast,' +
'findLastIndex,findLastKey,flatMap,forEach,forEachRight,forIn,forInRight,' +
'forOwn,forOwnRight,get,groupBy,includes,indexBy,indexOf,intersection,' +
'invoke,invokeMap,isMatch,lastIndexOf,map,mapKeys,mapValues,matchesProperty,' +
'maxBy,mean,minBy,merge,modArgs,modArgsSet,omit,pad,padLeft,padRight,parseInt,' +
'partition,pick,pull,pullAll,pullAt,random,range,rangeRight,rearg,reject,' +
'remove,repeat,result,sampleSize,set,some,sortBy,sortByOrder,sortedIndexBy,' +
'sortedLastIndexBy,sortedUniqBy,startsWith,subtract,sumBy,take,takeRight,' +
'takeRightWhile,takeWhile,throttle,times,truncate,union,uniqBy,without,wrap,' +
'xor,zip,zipObject').split(','),
3: (
'assignWith,clamp,differenceBy,extendWith,getOr,inRange,intersectionBy,' +
'isEqualWith,isMatchWith,mergeWith,omitBy,pickBy,pullAllBy,reduce,' +
'reduceRight,slice,transform,unionBy,xorBy,zipWith').split(','),
4:
['fill']
},
/** Used to map ary to rearg configs by method ary. */
'aryReargMap': {
2: [1, 0],
3: [2, 1, 0],
4: [3, 2, 0, 1]
},
/** Used to map ary to rearg configs by method names. */
'methodReargMap': {
'clamp': [2, 0, 1],
'reduce': [2, 0, 1],
'reduceRight': [2, 0, 1],
'slice': [2, 0, 1],
'transform': [2, 0, 1]
},
/** Used to iterate `mapping.aryMethodMap` keys. */
'caps': [1, 2, 3, 4],
/** Used to map keys to other keys. */
'keyMap': {
'curryN': 'curry',
'curryRightN': 'curryRight',
'getOr': 'get'
},
/** Used to identify methods which mutate arrays or objects. */
'mutateMap': {
'array': {
'fill': true,
'pull': true,
'pullAll': true,
'pullAllBy': true,
'pullAt': true,
'remove': true,
'reverse': true
},
'object': {
'assign': true,
'assignWith': true,
'defaults': true,
'defaultsDeep': true,
'extend': true,
'extendWith': true,
'merge': true,
'mergeWith': true
}
},
/** Used to track methods that skip `_.rearg`. */
'skipReargMap': {
'difference': true,
'matchesProperty': true,
'random': true,
'range': true,
'rangeRight': true,
'zip': true,
'zipObject': true
}
};
/***/ }
/******/ ])
});
;

View File

@@ -30,7 +30,7 @@ var mappingConfig = {
'entry': path.join(__dirname, 'mapping.js'), 'entry': path.join(__dirname, 'mapping.js'),
'output': { 'output': {
'path': distPath, 'path': distPath,
'filename': 'fp-mapping.js', 'filename': 'mapping.fp.js',
'library': 'mapping', 'library': 'mapping',
'libraryTarget': 'umd' 'libraryTarget': 'umd'
} }

42
test/fp.html Normal file
View File

@@ -0,0 +1,42 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>lodash-fp Test Suite</title>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
</head>
<body>
<script>
// Avoid reporting tests to Sauce Labs when script errors occur.
if (location.port == '9001') {
window.onerror = function(message) {
if (window.QUnit) {
QUnit.config.done.length = 0;
}
global_test_results = { 'message': message };
};
}
</script>
<script src="../lodash.js"></script>
<script src="../dist/lodash.fp.js"></script>
<script src="../dist/mapping.fp.js"></script>
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../node_modules/qunit-extras/qunit-extras.js"></script>
<script src="../node_modules/platform/platform.js"></script>
<script src="./asset/test-ui.js"></script>
<script src="./test-fp.js"></script>
<div id="qunit"></div>
<script>
// Set a more readable browser name.
window.onload = function() {
var timeoutId = setInterval(function() {
var ua = document.getElementById('qunit-userAgent');
if (ua) {
ua.innerHTML = platform;
clearInterval(timeoutId);
}
}, 16);
};
</script>
</body>
</html>

View File

@@ -1,36 +1,72 @@
'use strict'; ;(function() {
var _ = require('lodash'), /** Used as a safe reference for `undefined` in pre-ES5 environments. */
path = require('path'); var undefined;
var basePath = path.join(__dirname, '..'), /** Used as the size to cover large array optimizations. */
libPath = path.join(basePath, 'lib'), var LARGE_ARRAY_SIZE = 200;
fpPath = path.join(libPath, 'fp');
var convert = require(path.join(fpPath, 'fp.js')), /** Used as a reference to the global object. */
mapping = require(path.join(fpPath, 'mapping.js')); var root = (typeof global == 'object' && global) || this;
var fp = convert(_.runInContext()); /** Used for native method references. */
var arrayProto = Array.prototype;
global.QUnit = require('qunitjs'); /** Method and object shortcuts. */
require('qunit-extras').runInContext(global); var phantom = root.phantom,
amd = root.define && define.amd,
document = !phantom && root.document,
noop = function() {},
slice = arrayProto.slice;
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/** Used as the size to cover large array optimizations. */ /** Use a single "load" function. */
var LARGE_ARRAY_SIZE = 200; var load = (!amd && typeof require == 'function')
? require
: noop;
/** Used for native method references. */ /** The unit testing framework. */
var arrayProto = Array.prototype; var QUnit = root.QUnit || (root.QUnit = (
QUnit = load('../node_modules/qunitjs/qunit/qunit.js') || root.QUnit,
QUnit = QUnit.QUnit || QUnit
));
/** Method and object shortcuts. */ /** Load stable Lodash and QUnit Extras. */
var slice = arrayProto.slice; var _ = root._ || load('../lodash.js');
if (_) {
_ = _.runInContext(root);
}
var QUnitExtras = load('../node_modules/qunit-extras/qunit-extras.js');
if (QUnitExtras) {
QUnitExtras.runInContext(root);
}
/*----------------------------------------------------------------------------*/ var convert = root.fp || load('../dist/lodash.fp.js'),
mapping = root.mapping || load('../lib/fp/mapping.js'),
fp = convert(_.runInContext());
QUnit.module('method aliases'); /*--------------------------------------------------------------------------*/
(function() { /**
* Skips a given number of tests with a passing result.
*
* @private
* @param {Object} assert The QUnit assert object.
* @param {number} [count=1] The number of tests to skip.
*/
function skipTest(assert, count) {
count || (count = 1);
while (count--) {
assert.ok(true, 'test skipped');
}
}
/*--------------------------------------------------------------------------*/
QUnit.module('method aliases');
(function() {
QUnit.test('should have correct aliases', function(assert) { QUnit.test('should have correct aliases', function(assert) {
assert.expect(1); assert.expect(1);
@@ -43,13 +79,13 @@ QUnit.module('method aliases');
assert.deepEqual(_.reject(actual, 1), []); assert.deepEqual(_.reject(actual, 1), []);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('method ary caps'); QUnit.module('method ary caps');
(function() { (function() {
QUnit.test('should have a cap of 1', function(assert) { QUnit.test('should have a cap of 1', function(assert) {
assert.expect(1); assert.expect(1);
@@ -130,13 +166,13 @@ QUnit.module('method ary caps');
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('methods that use `indexOf`'); QUnit.module('methods that use `indexOf`');
(function() { (function() {
QUnit.test('should work with `fp.indexOf`', function(assert) { QUnit.test('should work with `fp.indexOf`', function(assert) {
assert.expect(10); assert.expect(10);
@@ -174,16 +210,17 @@ QUnit.module('methods that use `indexOf`');
actual = fp.pull('b', array); actual = fp.pull('b', array);
assert.deepEqual(actual, ['a', 'c'], 'fp.pull'); assert.deepEqual(actual, ['a', 'c'], 'fp.pull');
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('cherry-picked methods'); QUnit.module('cherry-picked methods');
(function() { (function() {
QUnit.test('should provide the correct `iteratee` arguments', function(assert) { QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
assert.expect(1); assert.expect(1);
if (!document) {
var args, var args,
array = [1, 2, 3], array = [1, 2, 3],
map = convert('map', _.map); map = convert('map', _.map);
@@ -193,11 +230,16 @@ QUnit.module('cherry-picked methods');
})(array); })(array);
assert.deepEqual(args, [1]); assert.deepEqual(args, [1]);
}
else {
skipTest(assert);
}
}); });
QUnit.test('should not support shortcut fusion', function(assert) { QUnit.test('should not support shortcut fusion', function(assert) {
assert.expect(3); assert.expect(3);
if (!document) {
var array = fp.range(0, LARGE_ARRAY_SIZE), var array = fp.range(0, LARGE_ARRAY_SIZE),
filterCount = 0, filterCount = 0,
mapCount = 0; mapCount = 0;
@@ -225,64 +267,68 @@ QUnit.module('cherry-picked methods');
assert.deepEqual(combined(array), [4, 16]); assert.deepEqual(combined(array), [4, 16]);
assert.strictEqual(filterCount, 200, 'filterCount'); assert.strictEqual(filterCount, 200, 'filterCount');
assert.strictEqual(mapCount, 200, 'mapCount'); assert.strictEqual(mapCount, 200, 'mapCount');
}
else {
skipTest(assert, 3);
}
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.curry'); QUnit.module('fp.curry');
(function() { (function() {
QUnit.test('should accept only a `func` param', function(assert) { QUnit.test('should accept only a `func` param', function(assert) {
assert.expect(1); assert.expect(1);
assert.raises(function() { fp.curry(1, _.noop); }, TypeError); assert.raises(function() { fp.curry(1, _.noop); }, TypeError);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.curryN'); QUnit.module('fp.curryN');
(function() { (function() {
QUnit.test('should accept an `arity` param', function(assert) { QUnit.test('should accept an `arity` param', function(assert) {
assert.expect(1); assert.expect(1);
var actual = fp.curryN(1, function(a, b) { return [a, b]; })('a'); var actual = fp.curryN(1, function(a, b) { return [a, b]; })('a');
assert.deepEqual(actual, ['a', undefined]); assert.deepEqual(actual, ['a', undefined]);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.difference'); QUnit.module('fp.difference');
(function() { (function() {
QUnit.test('should return the elements of the first array not included in the second array', function(assert) { QUnit.test('should return the elements of the first array not included in the second array', function(assert) {
assert.expect(1); assert.expect(1);
assert.deepEqual(fp.difference([1, 2])([2, 3]), [1]); assert.deepEqual(fp.difference([1, 2])([2, 3]), [1]);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.fill'); QUnit.module('fp.fill');
(function() { (function() {
QUnit.test('should have an argument order of `start`, `end`, then `value`', function(assert) { QUnit.test('should have an argument order of `start`, `end`, then `value`', function(assert) {
assert.expect(1); assert.expect(1);
var array = [1, 2, 3]; var array = [1, 2, 3];
assert.deepEqual(fp.fill(1)(2)('*')(array), [1, '*', 3]); assert.deepEqual(fp.fill(1)(2)('*')(array), [1, '*', 3]);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.flow and fp.flowRight'); QUnit.module('fp.flow and fp.flowRight');
_.each(['flow', 'flowRight'], function(methodName, index) { _.each(['flow', 'flowRight'], function(methodName, index) {
var func = fp[methodName], var func = fp[methodName],
isFlow = methodName == 'flow'; isFlow = methodName == 'flow';
@@ -319,25 +365,25 @@ _.each(['flow', 'flowRight'], function(methodName, index) {
assert.strictEqual(mapCount, 5, 'mapCount'); assert.strictEqual(mapCount, 5, 'mapCount');
}); });
}); });
}); });
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.inRange'); QUnit.module('fp.inRange');
(function() { (function() {
QUnit.test('should have an argument order of `start`, `end`, then `value`', function(assert) { QUnit.test('should have an argument order of `start`, `end`, then `value`', function(assert) {
assert.expect(1); assert.expect(1);
assert.strictEqual(fp.inRange(2)(4)(3), true); assert.strictEqual(fp.inRange(2)(4)(3), true);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.iteratee'); QUnit.module('fp.iteratee');
(function() { (function() {
QUnit.test('should return a iteratee with capped params', function(assert) { QUnit.test('should return a iteratee with capped params', function(assert) {
assert.expect(1); assert.expect(1);
@@ -348,18 +394,23 @@ QUnit.module('fp.iteratee');
QUnit.test('should convert by name', function(assert) { QUnit.test('should convert by name', function(assert) {
assert.expect(1); assert.expect(1);
if (!document) {
var iteratee = convert('iteratee', _.iteratee), var iteratee = convert('iteratee', _.iteratee),
func = iteratee(function(a, b, c) { return [a, b, c]; }, undefined, 3); func = iteratee(function(a, b, c) { return [a, b, c]; }, undefined, 3);
assert.deepEqual(func(1, 2, 3), [1, undefined, undefined]); assert.deepEqual(func(1, 2, 3), [1, undefined, undefined]);
}
else {
skipTest(assert);
}
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.maxBy and fp.minBy'); QUnit.module('fp.maxBy and fp.minBy');
_.each(['maxBy', 'minBy'], function(methodName, index) { _.each(['maxBy', 'minBy'], function(methodName, index) {
var array = [1, 2, 3], var array = [1, 2, 3],
func = fp[methodName], func = fp[methodName],
isMax = !index; isMax = !index;
@@ -385,13 +436,13 @@ _.each(['maxBy', 'minBy'], function(methodName, index) {
assert.deepEqual(args, [1]); assert.deepEqual(args, [1]);
}); });
}); });
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.mixin'); QUnit.module('fp.mixin');
(function() { (function() {
var source = { 'a': _.noop }; var source = { 'a': _.noop };
QUnit.test('should mixin static methods but not prototype methods', function(assert) { QUnit.test('should mixin static methods but not prototype methods', function(assert) {
@@ -444,11 +495,11 @@ QUnit.module('fp.mixin');
fp.mixin.apply(fp, index ? [1] : []); fp.mixin.apply(fp, index ? [1] : []);
assert.ok(_.every(props, function(key) { assert.ok(_.every(props, function(key) {
return global[key] !== fp[key]; return root[key] !== fp[key];
})); }));
_.each(props, function(key) { _.each(props, function(key) {
delete global[key]; delete root[key];
}); });
}); });
}); });
@@ -456,6 +507,7 @@ QUnit.module('fp.mixin');
QUnit.test('should convert by name', function(assert) { QUnit.test('should convert by name', function(assert) {
assert.expect(3); assert.expect(3);
if (!document) {
var object = { 'mixin': convert('mixin', _.mixin) }; var object = { 'mixin': convert('mixin', _.mixin) };
function Foo() {} function Foo() {}
@@ -467,14 +519,18 @@ QUnit.module('fp.mixin');
object.mixin(source); object.mixin(source);
assert.strictEqual(typeof object.a, 'function'); assert.strictEqual(typeof object.a, 'function');
}
else {
skipTest(assert, 3);
}
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.random'); QUnit.module('fp.random');
(function() { (function() {
var array = Array(1000); var array = Array(1000);
QUnit.test('should support a `min` and `max` argument', function(assert) { QUnit.test('should support a `min` and `max` argument', function(assert) {
@@ -488,25 +544,25 @@ QUnit.module('fp.random');
return result >= min && result <= max; return result >= min && result <= max;
})); }));
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.range'); QUnit.module('fp.range');
(function() { (function() {
QUnit.test('should have an argument order of `start` then `end`', function(assert) { QUnit.test('should have an argument order of `start` then `end`', function(assert) {
assert.expect(1); assert.expect(1);
assert.deepEqual(fp.range(1)(4), [1, 2, 3]); assert.deepEqual(fp.range(1)(4), [1, 2, 3]);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.runInContext'); QUnit.module('fp.runInContext');
(function() { (function() {
QUnit.test('should return a converted lodash instance', function(assert) { QUnit.test('should return a converted lodash instance', function(assert) {
assert.expect(1); assert.expect(1);
@@ -516,16 +572,21 @@ QUnit.module('fp.runInContext');
QUnit.test('should convert by name', function(assert) { QUnit.test('should convert by name', function(assert) {
assert.expect(1); assert.expect(1);
if (!document) {
var runInContext = convert('runInContext', _.runInContext); var runInContext = convert('runInContext', _.runInContext);
assert.strictEqual(typeof runInContext({}).curryN, 'function'); assert.strictEqual(typeof runInContext({}).curryN, 'function');
}
else {
skipTest(assert);
}
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.uniqBy'); QUnit.module('fp.uniqBy');
(function() { (function() {
var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }]; var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }, { 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
QUnit.test('should work with an `iteratee` argument', function(assert) { QUnit.test('should work with an `iteratee` argument', function(assert) {
@@ -551,37 +612,37 @@ QUnit.module('fp.uniqBy');
assert.deepEqual(args, [objects[0]]); assert.deepEqual(args, [objects[0]]);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.zip'); QUnit.module('fp.zip');
(function() { (function() {
QUnit.test('should zip together two arrays', function(assert) { QUnit.test('should zip together two arrays', function(assert) {
assert.expect(1); assert.expect(1);
assert.deepEqual(fp.zip([1, 2], [3, 4]), [[1, 3], [2, 4]]); assert.deepEqual(fp.zip([1, 2], [3, 4]), [[1, 3], [2, 4]]);
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('fp.zipObject'); QUnit.module('fp.zipObject');
(function() { (function() {
QUnit.test('should zip together key/value arrays into an object', function(assert) { QUnit.test('should zip together key/value arrays into an object', function(assert) {
assert.expect(1); assert.expect(1);
assert.deepEqual(fp.zipObject(['a', 'b'], [1, 2]), { 'a': 1, 'b': 2 }); assert.deepEqual(fp.zipObject(['a', 'b'], [1, 2]), { 'a': 1, 'b': 2 });
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('mutation methods'); QUnit.module('mutation methods');
(function() { (function() {
var array = [1, 2, 3], var array = [1, 2, 3],
object = { 'a': 1 }; object = { 'a': 1 };
@@ -686,13 +747,13 @@ QUnit.module('mutation methods');
assert.deepEqual(value, array, 'fp.reverse'); assert.deepEqual(value, array, 'fp.reverse');
assert.deepEqual(actual, [3, 2, 1], 'fp.reverse'); assert.deepEqual(actual, [3, 2, 1], 'fp.reverse');
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('with methods'); QUnit.module('with methods');
(function() { (function() {
var array = [1, 2, 3], var array = [1, 2, 3],
object = { 'a': 1 }; object = { 'a': 1 };
@@ -734,11 +795,15 @@ QUnit.module('with methods');
assert.deepEqual(args, expected, 'fp.mergeWith'); assert.deepEqual(args, expected, 'fp.mergeWith');
}); });
}()); }());
/*----------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.config.asyncRetries = 10; QUnit.config.asyncRetries = 10;
QUnit.config.hidepassed = true; QUnit.config.hidepassed = true;
QUnit.config.noglobals = true;
QUnit.load(); if (!document) {
QUnit.config.noglobals = true;
QUnit.load();
}
}.call(this));