mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Fix test/test-build.js to work with build.js modifications.
Former-commit-id: 9df41ae02627557a21f282f70a73a447497b8984
This commit is contained in:
@@ -468,12 +468,12 @@
|
|||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
|
|
||||||
asyncTest('`lodash`', function() {
|
asyncTest('`lodash`', function() {
|
||||||
build(['-s'], function(source, filePath) {
|
build(['-s'], function(data) {
|
||||||
// used by r.js build optimizer
|
// used by r.js build optimizer
|
||||||
var defineHasRegExp = /typeof\s+define\s*==(=)?\s*['"]function['"]\s*&&\s*typeof\s+define\.amd\s*==(=)?\s*['"]object['"]\s*&&\s*define\.amd/g,
|
var defineHasRegExp = /typeof\s+define\s*==(=)?\s*['"]function['"]\s*&&\s*typeof\s+define\.amd\s*==(=)?\s*['"]object['"]\s*&&\s*define\.amd/g,
|
||||||
basename = path.basename(filePath, '.js');
|
basename = path.basename(data.outputPath, '.js');
|
||||||
|
|
||||||
ok(!!defineHasRegExp.exec(source), basename);
|
ok(!!defineHasRegExp.exec(data.source), basename);
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -489,22 +489,22 @@
|
|||||||
asyncTest('`lodash template=*.jst`', function() {
|
asyncTest('`lodash template=*.jst`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'template=' + templatePath + '/*.jst'], function(source, filePath) {
|
build(['-s', 'template=' + templatePath + '/*.jst'], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
var data = {
|
var object = {
|
||||||
'a': { 'people': ['moe', 'larry', 'curly'] },
|
'a': { 'people': ['moe', 'larry', 'curly'] },
|
||||||
'b': { 'epithet': 'stooge' },
|
'b': { 'epithet': 'stooge' },
|
||||||
'c': { 'name': 'ES6' }
|
'c': { 'name': 'ES6' }
|
||||||
};
|
};
|
||||||
|
|
||||||
context._ = _;
|
context._ = _;
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
|
|
||||||
equal(_.templates.a(data.a).replace(/[\r\n]+/g, ''), '<ul><li>moe</li><li>larry</li><li>curly</li></ul>', basename);
|
equal(_.templates.a(object.a).replace(/[\r\n]+/g, ''), '<ul><li>moe</li><li>larry</li><li>curly</li></ul>', basename);
|
||||||
equal(_.templates.b(data.b), 'Hello stooge.', basename);
|
equal(_.templates.b(object.b), 'Hello stooge.', basename);
|
||||||
equal(_.templates.c(data.c), 'Hello ES6!', basename);
|
equal(_.templates.c(object.c), 'Hello ES6!', basename);
|
||||||
delete _.templates;
|
delete _.templates;
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@@ -519,9 +519,9 @@
|
|||||||
asyncTest('`lodash template=*.jst` exports=amd' + (command ? ' ' + command : ''), function() {
|
asyncTest('`lodash template=*.jst` exports=amd' + (command ? ' ' + command : ''), function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'template=' + templatePath + '/*.jst', 'exports=amd'].concat(command || []), function(source, filePath) {
|
build(['-s', 'template=' + templatePath + '/*.jst', 'exports=amd'].concat(command || []), function(data) {
|
||||||
var moduleId,
|
var moduleId,
|
||||||
basename = path.basename(filePath, '.js'),
|
basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
context.define = function(requires, factory) {
|
context.define = function(requires, factory) {
|
||||||
@@ -530,7 +530,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
context.define.amd = {};
|
context.define.amd = {};
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
|
|
||||||
equal(moduleId, (command ? 'underscore' : 'lodash'), basename);
|
equal(moduleId, (command ? 'underscore' : 'lodash'), basename);
|
||||||
ok('a' in _.templates && 'b' in _.templates, basename);
|
ok('a' in _.templates && 'b' in _.templates, basename);
|
||||||
@@ -542,12 +542,12 @@
|
|||||||
asyncTest('`lodash settings=...`' + (command ? ' ' + command : ''), function() {
|
asyncTest('`lodash settings=...`' + (command ? ' ' + command : ''), function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'].concat(command || []), function(source, filePath) {
|
build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'].concat(command || []), function(data) {
|
||||||
var moduleId,
|
var moduleId,
|
||||||
basename = path.basename(filePath, '.js'),
|
basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
var data = {
|
var object = {
|
||||||
'd': { 'name': 'Mustache' }
|
'd': { 'name': 'Mustache' }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -557,10 +557,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
context.define.amd = {};
|
context.define.amd = {};
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
|
|
||||||
equal(moduleId, (command ? 'underscore' : 'lodash'), basename);
|
equal(moduleId, (command ? 'underscore' : 'lodash'), basename);
|
||||||
equal(_.templates.d(data.d), 'Hello Mustache!', basename);
|
equal(_.templates.d(object.d), 'Hello Mustache!', basename);
|
||||||
delete _.templates;
|
delete _.templates;
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@@ -578,18 +578,18 @@
|
|||||||
|
|
||||||
asyncTest('debug only', function() {
|
asyncTest('debug only', function() {
|
||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
build(['-d', '-s'], function(source, filePath) {
|
build(['-d', '-s'], function(data) {
|
||||||
equal(path.basename(filePath, '.js'), 'lodash');
|
equal(path.basename(data.outputPath, '.js'), 'lodash');
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('debug custom', function() {
|
asyncTest('debug custom', function() {
|
||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
build(['-d', '-s', 'backbone'], function(source, filePath) {
|
build(['-d', '-s', 'backbone'], function(data) {
|
||||||
equal(path.basename(filePath, '.js'), 'lodash.custom');
|
equal(path.basename(data.outputPath, '.js'), 'lodash.custom');
|
||||||
|
|
||||||
var comment = source.match(reLicense);
|
var comment = data.source.match(reLicense);
|
||||||
ok(reCustom.test(comment));
|
ok(reCustom.test(comment));
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@@ -597,18 +597,18 @@
|
|||||||
|
|
||||||
asyncTest('minified only', function() {
|
asyncTest('minified only', function() {
|
||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
build(['-m', '-s'], function(source, filePath) {
|
build(['-m', '-s'], function(data) {
|
||||||
equal(path.basename(filePath, '.js'), 'lodash.min');
|
equal(path.basename(data.outputPath, '.js'), 'lodash.min');
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('minified custom', function() {
|
asyncTest('minified custom', function() {
|
||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
build(['-m', '-s', 'backbone'], function(source, filePath) {
|
build(['-m', '-s', 'backbone'], function(data) {
|
||||||
equal(path.basename(filePath, '.js'), 'lodash.custom.min');
|
equal(path.basename(data.outputPath, '.js'), 'lodash.custom.min');
|
||||||
|
|
||||||
var comment = source.match(reLicense);
|
var comment = data.source.match(reLicense);
|
||||||
ok(reCustom.test(comment));
|
ok(reCustom.test(comment));
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@@ -633,11 +633,11 @@
|
|||||||
if (index) {
|
if (index) {
|
||||||
commands.push('strict');
|
commands.push('strict');
|
||||||
}
|
}
|
||||||
build(commands, function(source, filePath) {
|
build(commands, function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
var lodash = context._;
|
var lodash = context._;
|
||||||
|
|
||||||
var actual = _.every([
|
var actual = _.every([
|
||||||
@@ -675,11 +675,11 @@
|
|||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', command], function(source, filePath) {
|
build(['-s', command], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
var lodash = context._;
|
var lodash = context._;
|
||||||
|
|
||||||
ok(lodash.chain(1) instanceof lodash, '_.chain: ' + basename);
|
ok(lodash.chain(1) instanceof lodash, '_.chain: ' + basename);
|
||||||
@@ -713,13 +713,13 @@
|
|||||||
asyncTest('modified methods should work correctly', function() {
|
asyncTest('modified methods should work correctly', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'underscore'], function(source, filePath) {
|
build(['-s', 'underscore'], function(data) {
|
||||||
var last,
|
var last,
|
||||||
array = [{ 'a': 1, 'b': 2 }, { 'a': 2, 'b': 2 }],
|
array = [{ 'a': 1, 'b': 2 }, { 'a': 2, 'b': 2 }],
|
||||||
basename = path.basename(filePath, '.js'),
|
basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
var lodash = context._;
|
var lodash = context._;
|
||||||
|
|
||||||
var object = { 'fn': lodash.bind(function(foo) { return foo + this.bar; }, { 'bar': 1 }, 1) };
|
var object = { 'fn': lodash.bind(function(foo) { return foo + this.bar; }, { 'bar': 1 }, 1) };
|
||||||
@@ -779,11 +779,11 @@
|
|||||||
asyncTest('should not have any Lo-Dash-only methods', function() {
|
asyncTest('should not have any Lo-Dash-only methods', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'underscore'], function(source, filePath) {
|
build(['-s', 'underscore'], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
var lodash = context._;
|
var lodash = context._;
|
||||||
|
|
||||||
_.each([
|
_.each([
|
||||||
@@ -806,11 +806,11 @@
|
|||||||
asyncTest('`lodash underscore include=partial`', function() {
|
asyncTest('`lodash underscore include=partial`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'underscore', 'include=partial'], function(source, filePath) {
|
build(['-s', 'underscore', 'include=partial'], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
var lodash = context._;
|
var lodash = context._;
|
||||||
|
|
||||||
equal(lodash.partial(_.identity, 2)(), 2, '_.partial: ' + basename);
|
equal(lodash.partial(_.identity, 2)(), 2, '_.partial: ' + basename);
|
||||||
@@ -821,12 +821,12 @@
|
|||||||
asyncTest('`lodash underscore plus=clone`', function() {
|
asyncTest('`lodash underscore plus=clone`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'underscore', 'plus=clone'], function(source, filePath) {
|
build(['-s', 'underscore', 'plus=clone'], function(data) {
|
||||||
var array = [{ 'value': 1 }],
|
var array = [{ 'value': 1 }],
|
||||||
basename = path.basename(filePath, '.js'),
|
basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
var lodash = context._,
|
var lodash = context._,
|
||||||
clone = lodash.clone(array, true);
|
clone = lodash.clone(array, true);
|
||||||
|
|
||||||
@@ -854,10 +854,11 @@
|
|||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', command], function(source, filePath) {
|
build(['-s', command], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext(),
|
context = createContext(),
|
||||||
pass = false;
|
pass = false,
|
||||||
|
source = data.source;
|
||||||
|
|
||||||
switch(index) {
|
switch(index) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -914,8 +915,8 @@
|
|||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'exports=none', command], function(source, filePath) {
|
build(['-s', 'exports=none', command], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
context.define = function(func) {
|
context.define = function(func) {
|
||||||
@@ -923,7 +924,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@@ -950,8 +951,8 @@
|
|||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
|
|
||||||
build(['-s'].concat(command.split(' ')), function(source, filePath) {
|
build(['-s'].concat(command.split(' ')), function(data) {
|
||||||
equal(path.basename(filePath, '.js'), 'a', command);
|
equal(path.basename(data.outputPath, '.js'), 'a', command);
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -978,9 +979,9 @@
|
|||||||
written = string;
|
written = string;
|
||||||
};
|
};
|
||||||
|
|
||||||
build([command, 'exports=', 'include='], function(source) {
|
build([command, 'exports=', 'include='], function(data) {
|
||||||
process.stdout.write = write;
|
process.stdout.write = write;
|
||||||
equal(written, source);
|
equal(written, data.source);
|
||||||
equal(arguments.length, 1);
|
equal(arguments.length, 1);
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@@ -996,12 +997,12 @@
|
|||||||
asyncTest('`lodash mobile`', function() {
|
asyncTest('`lodash mobile`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'mobile'], function(source, filePath) {
|
build(['-s', 'mobile'], function(data) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext();
|
context = createContext();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@@ -1065,15 +1066,15 @@
|
|||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['--silent'].concat(command.split(' ')), function(source, filePath) {
|
build(['--silent'].concat(command.split(' ')), function(data) {
|
||||||
var methodNames,
|
var methodNames,
|
||||||
basename = path.basename(filePath, '.js'),
|
basename = path.basename(data.outputPath, '.js'),
|
||||||
context = createContext(),
|
context = createContext(),
|
||||||
isUnderscore = /underscore/.test(command),
|
isUnderscore = /underscore/.test(command),
|
||||||
exposeAssign = !isUnderscore;
|
exposeAssign = !isUnderscore;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(data.source, context);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user