Skip to content

Commit 6342d5d

Browse files
committed
Merge pull request #17 from Jakobo/issue_13_14
Spec test update for define without dependencies, correction for anon_relative Fixes #13 #14 #15 #16
2 parents 1cbc07d + 2f06d1a commit 6342d5d

File tree

15 files changed

+185
-29
lines changed

15 files changed

+185
-29
lines changed

impl/inject/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var config = function(pathObj) {
2626
funcString: true,
2727
namedWrapped: true,
2828
require: true,
29-
plugins: true
30-
// pluginDynamic: true
29+
plugins: true,
30+
pathsConfig: true
3131
};
3232
require = undefined;

impl/lsjs/config.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ 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+
// SEE: tests/basic_empty_deps
13+
// basic: true,
14+
anon: true,
15+
funcString: true,
16+
namedWrapped: true,
17+
require: true,
18+
plugins: true
19+
//pluginDynamic: true
1920
};
2021
require = undefined;

impl/needs/config.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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+
anon: true,
6+
require: true,
7+
funcString: true,
8+
namedWrapped: true,
9+
plugins: true,
10+
pluginDynamic: false
11+
};
1212

1313
require = undefined;

impl/requirejs/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var config = require,
88
//Indicate what levels of the API are implemented by this loader,
99
//and therefore which tests to run.
1010
implemented = {
11-
basic: true,
11+
// SEE: tests/basic_empty_deps
12+
// basic: true,
1213
anon: true,
1314
funcString: true,
1415
namedWrapped: true,

impl/sample.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
anon: true,
19+
funcString: true,
20+
namedWrapped: true,
21+
require: true,
22+
23+
// plugin support
24+
plugins: true,
25+
pluginDynamic: true,
26+
27+
// config proposal
28+
pathsConfig: true,
29+
packagesConfig: true,
30+
mapConfig: true,
31+
moduleConfig: true,
32+
shimConfig: true
33+
};

server/resources/all.html

+6
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="basic" 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

@@ -101,6 +104,9 @@ <h2>Tests <span class="or">for {{FRAMEWORK}}</span></h2>
101104
<li class="pathsConfig" id="config_paths"><a href="/{{FRAMEWORK}}/config_paths/test.html">
102105
config_paths: test for the "path" functionality of Common Config
103106
</a></li>
107+
<li class="pathsConfig" id="config_paths"><a href="/{{FRAMEWORK}}/config_paths_relative/test.html">
108+
config_paths_relative: ensure that the relative module ID rules still apply, even when using the path config</a></li>
109+
</a></li>
104110
</ul>
105111
</li>
106112

tests/anon_relative/_test.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
config({
2-
paths: {
3-
"array": "impl/array"
4-
}
5-
});
6-
7-
go( ["_reporter", "require", "array"],
1+
go( ["_reporter", "require", "impl/array"],
82
function (amdJS, require, array) {
93
amdJS.assert('impl/array' === array.name, 'anon_relative: array.name');
10-
amdJS.assert('util' === array.utilName, 'anon_relative: relative to module ID, not URL');
4+
amdJS.assert('impl/util' === array.dotUtilName, 'anon_relative: resolved "./util" to impl/util');
5+
amdJS.assert('util' === array.utilName, 'anon_relative: resolved "util" to impl/util');
116
amdJS.print('DONE', 'done');
127
});

tests/anon_relative/impl/array.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
define(['./util'], function (util) {
1+
define(['./util', 'util'], function (dotUtil, util) {
22
return {
33
name: 'impl/array',
4+
dotUtilName: dotUtil.name,
45
utilName: util.name
56
};
67
});

tests/basic_empty_deps/_reporter.js

+31
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

+33
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+
});
+31
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/config_paths_relative/_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
config({
2+
paths: {
3+
"array": "impl/array"
4+
}
5+
});
6+
7+
go( ["_reporter", "require", "array"],
8+
function (amdJS, require, array) {
9+
amdJS.assert('impl/array' === array.name, 'anon_relative: array.name');
10+
amdJS.assert('util' === array.utilName, 'anon_relative: relative to module ID, not URL');
11+
amdJS.print('DONE', 'done');
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
define(['./util'], function (util) {
2+
return {
3+
name: 'impl/array',
4+
utilName: util.name
5+
};
6+
});
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
name: 'impl/util'
3+
});

tests/config_paths_relative/util.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
name: 'util'
3+
});

0 commit comments

Comments
 (0)