mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Add build "exports" unit tests.
Former-commit-id: afe0fe59933d272bfa597be835011b3c81b28dda
This commit is contained in:
1
build.js
1
build.js
@@ -751,7 +751,6 @@
|
|||||||
'backbone',
|
'backbone',
|
||||||
'csp',
|
'csp',
|
||||||
'legacy',
|
'legacy',
|
||||||
'lodash',
|
|
||||||
'mobile',
|
'mobile',
|
||||||
'strict',
|
'strict',
|
||||||
'underscore',
|
'underscore',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
;(function() {
|
;(function(undefined) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** Load modules */
|
/** Load modules */
|
||||||
@@ -17,12 +17,6 @@
|
|||||||
/** The `build` module */
|
/** The `build` module */
|
||||||
var build = require('../build.js');
|
var build = require('../build.js');
|
||||||
|
|
||||||
/** Used to access the built Lo-Dash object */
|
|
||||||
var context = vm.createContext({
|
|
||||||
'clearTimeout': clearTimeout,
|
|
||||||
'setTimeout': setTimeout
|
|
||||||
});
|
|
||||||
|
|
||||||
/** Used to associate aliases with their real names */
|
/** Used to associate aliases with their real names */
|
||||||
var aliasToRealMap = {
|
var aliasToRealMap = {
|
||||||
'all': 'every',
|
'all': 'every',
|
||||||
@@ -262,6 +256,19 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a context object to use with `vm.runInContext`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @returns {Object} Returns a new context object.
|
||||||
|
*/
|
||||||
|
function createContext() {
|
||||||
|
return vm.createContext({
|
||||||
|
'clearTimeout': clearTimeout,
|
||||||
|
'setTimeout': setTimeout
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expands a list of method names to include real and alias names.
|
* Expands a list of method names to include real and alias names.
|
||||||
*
|
*
|
||||||
@@ -435,7 +442,7 @@
|
|||||||
'category=collections,functions',
|
'category=collections,functions',
|
||||||
'underscore backbone',
|
'underscore backbone',
|
||||||
'backbone legacy category=utilities exclude=first,last',
|
'backbone legacy category=utilities exclude=first,last',
|
||||||
'underscore mobile strict category=functions include=pick,uniq',
|
'underscore mobile strict category=functions exports=amd,global include=pick,uniq',
|
||||||
]
|
]
|
||||||
.concat(
|
.concat(
|
||||||
allMethods.map(function(methodName) {
|
allMethods.map(function(methodName) {
|
||||||
@@ -448,15 +455,14 @@
|
|||||||
|
|
||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
build(['--silent'].concat(command.split(' ')), function(filepath, source) {
|
build(['--silent'].concat(command.split(' ')), function(filepath, source) {
|
||||||
|
var basename = path.basename(filepath, '.js'),
|
||||||
|
context = createContext(),
|
||||||
|
methodNames = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
delete context._;
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(source, context);
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
|
|
||||||
var basename = path.basename(filepath, '.js'),
|
|
||||||
lodash = context._ || {},
|
|
||||||
methodNames = [];
|
|
||||||
|
|
||||||
if (/underscore/.test(command)) {
|
if (/underscore/.test(command)) {
|
||||||
methodNames = underscoreMethods;
|
methodNames = underscoreMethods;
|
||||||
}
|
}
|
||||||
@@ -497,6 +503,7 @@
|
|||||||
methodNames = expandMethodNames(methodNames);
|
methodNames = expandMethodNames(methodNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lodash = context._ || {};
|
||||||
methodNames = _.unique(methodNames);
|
methodNames = _.unique(methodNames);
|
||||||
|
|
||||||
methodNames.forEach(function(methodName) {
|
methodNames.forEach(function(methodName) {
|
||||||
@@ -529,12 +536,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
build(commands, function(filepath, source) {
|
build(commands, function(filepath, source) {
|
||||||
vm.runInContext(source, context);
|
|
||||||
|
|
||||||
var basename = path.basename(filepath, '.js'),
|
var basename = path.basename(filepath, '.js'),
|
||||||
lodash = context._,
|
context = createContext(),
|
||||||
pass = !index;
|
pass = !index;
|
||||||
|
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
var lodash = context._;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lodash.bindAll(object);
|
lodash.bindAll(object);
|
||||||
lodash.extend(object, { 'a': 1 });
|
lodash.extend(object, { 'a': 1 });
|
||||||
@@ -558,11 +566,12 @@
|
|||||||
|
|
||||||
asyncTest('should not have deep clone', function() {
|
asyncTest('should not have deep clone', function() {
|
||||||
build(['-s', 'underscore'], function(filepath, source) {
|
build(['-s', 'underscore'], function(filepath, source) {
|
||||||
vm.runInContext(source, context);
|
|
||||||
|
|
||||||
var array = [{ 'a': 1 }],
|
var array = [{ 'a': 1 }],
|
||||||
basename = path.basename(filepath, '.js'),
|
basename = path.basename(filepath, '.js'),
|
||||||
lodash = context._;
|
context = createContext();
|
||||||
|
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
var lodash = context._;
|
||||||
|
|
||||||
ok(lodash.clone(array, true)[0] === array[0], basename);
|
ok(lodash.clone(array, true)[0] === array[0], basename);
|
||||||
start();
|
start();
|
||||||
@@ -570,4 +579,66 @@
|
|||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('exports command');
|
||||||
|
var exportsAll = [
|
||||||
|
'amd',
|
||||||
|
'commonjs',
|
||||||
|
'global',
|
||||||
|
'node'
|
||||||
|
];
|
||||||
|
(function() {
|
||||||
|
var commands = [
|
||||||
|
'exports=amd',
|
||||||
|
'exports=commonjs',
|
||||||
|
'exports=global',
|
||||||
|
'exports=node'
|
||||||
|
];
|
||||||
|
|
||||||
|
commands.forEach(function(command, index) {
|
||||||
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
|
build(['-s', command], function(filepath, source) {
|
||||||
|
var basename = path.basename(filepath, '.js'),
|
||||||
|
context = createContext(),
|
||||||
|
pass = false;
|
||||||
|
|
||||||
|
switch(index) {
|
||||||
|
case 0:
|
||||||
|
context.define = function(fn) {
|
||||||
|
pass = true;
|
||||||
|
context._ = fn();
|
||||||
|
};
|
||||||
|
context.define.amd = {};
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
ok(pass, basename);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
context.exports = {};
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
ok(context._ === undefined, basename);
|
||||||
|
ok(_.isFunction(context.exports._), basename)
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
ok(_.isFunction(context._), basename);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
context.exports = {};
|
||||||
|
context.module = { 'exports': context.exports };
|
||||||
|
vm.runInContext(source, context);
|
||||||
|
ok(context._ === undefined, basename);
|
||||||
|
ok(_.isFunction(context.module.exports), basename);
|
||||||
|
}
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user