Skip to content

Commit e36c36b

Browse files
committed
Issue 14 create a basicEmpty class of tests that test no deps
Issue #14 references a situation where an empty dependency array denoted by [] should return no dependencies (as opposed to the normal require/exports/module combination). A define() call that does not contain any dependencies should receive the default require/module/exports combination.
1 parent 1cbc07d commit e36c36b

File tree

7 files changed

+120
-17
lines changed

7 files changed

+120
-17
lines changed

impl/inject/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var config = function(pathObj) {
2222
},
2323
implemented = {
2424
basic: true,
25+
basicEmpty: true,
2526
anon: true,
2627
funcString: true,
2728
namedWrapped: true,

impl/lsjs/config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ localStorage.clear();
99
var config = lsjs,
1010
go = lsjs,
1111
implemented = {
12-
basic: true,
13-
anon: true,
14-
funcString: true,
15-
namedWrapped: true,
16-
require: true,
17-
plugins: true
18-
//pluginDynamic: true
12+
basic: true,
13+
anon: true,
14+
funcString: true,
15+
namedWrapped: true,
16+
require: true,
17+
plugins: true
18+
//pluginDynamic: true
1919
};
2020
require = undefined;

impl/needs/config.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
var go = require,
2-
config = require.config,
3-
implemented = {
4-
basic: true,
5-
anon: true,
6-
require: true,
7-
funcString: true,
8-
namedWrapped: true,
9-
plugins: true,
10-
pluginDynamic: false
11-
};
2+
config = require.config,
3+
implemented = {
4+
basic: true,
5+
basicEmpty: true,
6+
anon: true,
7+
require: true,
8+
funcString: true,
9+
namedWrapped: true,
10+
plugins: true,
11+
pluginDynamic: false
12+
};
1213

1314
require = undefined;

impl/sample.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
These are all the currently supported tests
3+
4+
Use it as a template for your own impl
5+
*/
6+
7+
var config, go, implemented;
8+
9+
// config is a way to set up configuration for AMD tests
10+
config = function () {};
11+
12+
// map this to your loader's entry point
13+
go = function () {};
14+
15+
// comment out the tests you don't need
16+
implemented = {
17+
basic: true,
18+
basicEmpty: true,
19+
anon: true,
20+
funcString: true,
21+
namedWrapped: true,
22+
require: true,
23+
24+
// plugin support
25+
plugins: true,
26+
pluginDynamic: true,
27+
28+
// config proposal
29+
pathsConfig: true,
30+
packagesConfig: true,
31+
mapConfig: true,
32+
moduleConfig: true,
33+
shimConfig: true
34+
};

server/resources/all.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ <h2>Tests <span class="or">for {{FRAMEWORK}}</span></h2>
4747
<li class="basic" id="basic_simple"><a href="/{{FRAMEWORK}}/basic_simple/test.html">
4848
basic_simple: amd simple includes for named AMD modules
4949
</a></li>
50+
<li class="basicEmpty" id="basic_empty_deps"><a href="/{{FRAMEWORK}}/basic_empty_deps/test.html">
51+
basic_empty_defs: [] should imply no dependencies, while an empty "dependencies" variable defaults to require, exports, module
52+
</a></li>
5053
</ul>
5154
</li>
5255

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// _reporter.js
2+
(function() {
3+
var factory = function () {
4+
var exports = {};
5+
6+
exports.print = function () {
7+
// global print
8+
if (typeof amdJSPrint !== "undefined") {
9+
amdJSPrint.apply(undefined, arguments);
10+
}
11+
else {
12+
var stdout = require("system").stdout;
13+
stdout.print.apply(stdout, arguments);
14+
}
15+
};
16+
17+
exports.assert = function (guard, message) {
18+
if (guard) {
19+
exports.print("PASS " + message, "pass");
20+
} else {
21+
exports.print("FAIL " + message, "fail");
22+
}
23+
};
24+
25+
return exports;
26+
};
27+
28+
// define this module
29+
define("_reporter", [], factory);
30+
31+
})();

tests/basic_empty_deps/_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
go(["_reporter", "require"], function(amdJS, require) {
2+
3+
function emptyDeps(then) {
4+
define('emptyDeps', [], function() {
5+
amdJS.assert(arguments.length === 0, 'basic_empty_deps: [] should be treated as no dependencies instead of the default require, exports, module');
6+
then();
7+
});
8+
}
9+
10+
function noDeps(then) {
11+
define('noDeps', function(require, exports, module) {
12+
amdJS.assert(typeof(require) === 'function', 'basic_empty_deps: no dependencies case uses require in first slot. Is a function');
13+
amdJS.assert(typeof(exports) === 'object', 'basic_empty_deps: no dependencies case uses exports in second slot. Is an object.');
14+
amdJS.assert(typeof(module) === 'object', 'basic_empty_deps: no dependencies case uses module in third slot. Is an object.');
15+
then();
16+
});
17+
}
18+
19+
// this nesting structure ensures that the AMD define will resolve
20+
// before we call the next by after the tests are ran in each use
21+
// case. We use named define calls to ensure there are not module
22+
// conflicts or mismatches that can occur using anonymous modules.
23+
emptyDeps(function () {
24+
window.setTimeout(function () {
25+
noDeps(function () {
26+
window.setTimeout(function () {
27+
amdJS.print('DONE', 'done');
28+
});
29+
});
30+
});
31+
});
32+
33+
});

0 commit comments

Comments
 (0)