mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +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',
|
||||
'csp',
|
||||
'legacy',
|
||||
'lodash',
|
||||
'mobile',
|
||||
'strict',
|
||||
'underscore',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
;(function() {
|
||||
;(function(undefined) {
|
||||
'use strict';
|
||||
|
||||
/** Load modules */
|
||||
@@ -17,12 +17,6 @@
|
||||
/** The `build` module */
|
||||
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 */
|
||||
var aliasToRealMap = {
|
||||
'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.
|
||||
*
|
||||
@@ -435,7 +442,7 @@
|
||||
'category=collections,functions',
|
||||
'underscore backbone',
|
||||
'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(
|
||||
allMethods.map(function(methodName) {
|
||||
@@ -448,15 +455,14 @@
|
||||
|
||||
asyncTest('`lodash ' + command +'`', function() {
|
||||
build(['--silent'].concat(command.split(' ')), function(filepath, source) {
|
||||
var basename = path.basename(filepath, '.js'),
|
||||
context = createContext(),
|
||||
methodNames = [];
|
||||
|
||||
try {
|
||||
delete context._;
|
||||
vm.runInContext(source, context);
|
||||
} catch(e) { }
|
||||
|
||||
var basename = path.basename(filepath, '.js'),
|
||||
lodash = context._ || {},
|
||||
methodNames = [];
|
||||
|
||||
if (/underscore/.test(command)) {
|
||||
methodNames = underscoreMethods;
|
||||
}
|
||||
@@ -497,6 +503,7 @@
|
||||
methodNames = expandMethodNames(methodNames);
|
||||
}
|
||||
|
||||
var lodash = context._ || {};
|
||||
methodNames = _.unique(methodNames);
|
||||
|
||||
methodNames.forEach(function(methodName) {
|
||||
@@ -529,12 +536,13 @@
|
||||
}
|
||||
|
||||
build(commands, function(filepath, source) {
|
||||
vm.runInContext(source, context);
|
||||
|
||||
var basename = path.basename(filepath, '.js'),
|
||||
lodash = context._,
|
||||
context = createContext(),
|
||||
pass = !index;
|
||||
|
||||
vm.runInContext(source, context);
|
||||
var lodash = context._;
|
||||
|
||||
try {
|
||||
lodash.bindAll(object);
|
||||
lodash.extend(object, { 'a': 1 });
|
||||
@@ -558,11 +566,12 @@
|
||||
|
||||
asyncTest('should not have deep clone', function() {
|
||||
build(['-s', 'underscore'], function(filepath, source) {
|
||||
vm.runInContext(source, context);
|
||||
|
||||
var array = [{ 'a': 1 }],
|
||||
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);
|
||||
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