Add RequireJS "shim" test and a build test to ensure the AMD snippet is maintained for r.js.

Former-commit-id: 708c07877cfca0022d6d56c16c36d8bae79e4796
This commit is contained in:
John-David Dalton
2012-09-13 19:11:48 -07:00
parent 827091e522
commit 08249d78ea
3 changed files with 38 additions and 2 deletions

View File

@@ -44,6 +44,7 @@
<script>
// load Lo-Dash as a module
var lodashModule,
shimmedModule,
underscoreModule;
window.require && require({
@@ -51,14 +52,24 @@
'urlArgs': 't=' + (+new Date),
'paths': {
'lodash': '../../' + QUnit.config.lodashFilename,
'underscore': './../../' + QUnit.config.lodashFilename
'shimmed': './../../' + QUnit.config.lodashFilename,
'underscore': '../underscore/../../' + QUnit.config.lodashFilename
},
'shim': {
'shimmed': {
'exports': '_'
}
}
},
['lodash', 'underscore'], function(lodash, underscore) {
['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
if (lodash.noConflict) {
lodashModule = lodash.noConflict();
lodashModule.moduleName = 'lodash';
}
if (shimmed.noConflict) {
shimmedModule = shimmed.noConflict();
shimmedModule.moduleName = 'shimmed';
}
if (underscore.noConflict) {
underscoreModule = underscore.noConflict();
underscoreModule.moduleName = 'underscore';

View File

@@ -422,6 +422,23 @@
/*--------------------------------------------------------------------------*/
QUnit.module('minified AMD snippet');
(function() {
var start = _.once(QUnit.start);
asyncTest('`lodash`', function() {
build(['-s'], function(source, filepath) {
// 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;
ok(!!defineHasRegExp.exec(source));
start();
});
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('strict modifier');
(function() {

View File

@@ -123,6 +123,14 @@
}
});
test('supports loading lodash.js with the Require.js "shim" configuration option', function() {
if (window.document && window.require) {
equal((shimmedModule || {}).moduleName, 'shimmed');
} else {
skipTest();
}
});
test('supports loading lodash.js as the "underscore" module', function() {
if (window.document && window.require) {
equal((underscoreModule || {}).moduleName, 'underscore');