Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Many changes. See changelog for Apr 14, 2010 for more info.

  • Loading branch information...
commit c29ad4fee012e80ed190c75a5e557da451907e9a 1 parent c97ab2d
@jbrantly authored
Showing with 1,252 additions and 79 deletions.
  1. +50 −19 README
  2. +41 −0 tests/asyncA/index.html
  3. +1 −0  tests/asyncA/tests/absolute/b.js
  4. +9 −0 tests/asyncA/tests/absolute/program.js
  5. +5 −0 tests/asyncA/tests/absolute/submodule/a.js
  6. +15 −0 tests/asyncA/tests/absolute/test.js
  7. +4 −0 tests/asyncA/tests/cyclic/a.js
  8. +4 −0 tests/asyncA/tests/cyclic/b.js
  9. +12 −0 tests/asyncA/tests/cyclic/program.js
  10. +15 −0 tests/asyncA/tests/cyclic/test.js
  11. +10 −0 tests/asyncA/tests/relative/program.js
  12. +5 −0 tests/asyncA/tests/relative/submodule/a.js
  13. +2 −0  tests/asyncA/tests/relative/submodule/b.js
  14. +15 −0 tests/asyncA/tests/relative/test.js
  15. +43 −0 tests/asyncA/wrappedIndex.html
  16. +6 −0 tests/asyncA/wrappedTests/absolute/b.js
  17. +13 −0 tests/asyncA/wrappedTests/absolute/program.js
  18. +10 −0 tests/asyncA/wrappedTests/absolute/submodule/a.js
  19. +20 −0 tests/asyncA/wrappedTests/absolute/test.js
  20. +9 −0 tests/asyncA/wrappedTests/cyclic/a.js
  21. +9 −0 tests/asyncA/wrappedTests/cyclic/b.js
  22. +16 −0 tests/asyncA/wrappedTests/cyclic/program.js
  23. +20 −0 tests/asyncA/wrappedTests/cyclic/test.js
  24. +14 −0 tests/asyncA/wrappedTests/relative/program.js
  25. +9 −0 tests/asyncA/wrappedTests/relative/submodule/a.js
  26. +7 −0 tests/asyncA/wrappedTests/relative/submodule/b.js
  27. +20 −0 tests/asyncA/wrappedTests/relative/test.js
  28. +3 −0  tests/asyncA/yabbler.bat
  29. +3 −1 tests/determineShallowDependencies/modules/knownfailure.js
  30. +29 −0 tests/index.html
  31. +12 −14 tests/modules1.0/index.html
  32. +12 −14 tests/modules1.0/wrappedIndex.html
  33. +40 −0 tests/modules1.1.1/index.html
  34. +3 −0  tests/modules1.1.1/tests/main/a.js
  35. 0  tests/modules1.1.1/tests/main/b.js
  36. +11 −0 tests/modules1.1.1/tests/main/program.js
  37. +15 −0 tests/modules1.1.1/tests/main/test.js
  38. +3 −0  tests/modules1.1.1/tests/module/a.js
  39. +17 −0 tests/modules1.1.1/tests/module/program.js
  40. +3 −0  tests/modules1.1.1/tests/module/submodule/b.js
  41. +15 −0 tests/modules1.1.1/tests/module/test.js
  42. +42 −0 tests/modules1.1.1/wrappedIndex.html
  43. +7 −0 tests/modules1.1.1/wrappedTests/main/a.js
  44. +5 −0 tests/modules1.1.1/wrappedTests/main/b.js
  45. +15 −0 tests/modules1.1.1/wrappedTests/main/program.js
  46. +20 −0 tests/modules1.1.1/wrappedTests/main/test.js
  47. +7 −0 tests/modules1.1.1/wrappedTests/module/a.js
  48. +21 −0 tests/modules1.1.1/wrappedTests/module/program.js
  49. +7 −0 tests/modules1.1.1/wrappedTests/module/submodule/b.js
  50. +20 −0 tests/modules1.1.1/wrappedTests/module/test.js
  51. +2 −0  tests/modules1.1.1/yabbler.bat
  52. +8 −1 tests/print.js
  53. +43 −0 tests/transportC/index.html
  54. +26 −0 tests/transportC/tests/injects/program.js
  55. +20 −0 tests/transportC/tests/injects/test.js
  56. +20 −0 tests/transportC/tests/multipleDefines/program.js
  57. +20 −0 tests/transportC/tests/multipleDefines/test.js
  58. +7 −0 tests/transportC/tests/simple/program.js
  59. +20 −0 tests/transportC/tests/simple/test.js
  60. +45 −0 tests/transportD/index.html
  61. +34 −0 tests/transportD/tests/injects/program.js
  62. +20 −0 tests/transportD/tests/injects/test.js
  63. +21 −0 tests/transportD/tests/mixedDescriptors/program.js
  64. +20 −0 tests/transportD/tests/mixedDescriptors/test.js
  65. +24 −0 tests/transportD/tests/multipleDefines/program.js
  66. +20 −0 tests/transportD/tests/multipleDefines/test.js
  67. +17 −0 tests/transportD/tests/multipleModules/program.js
  68. +20 −0 tests/transportD/tests/multipleModules/test.js
  69. +9 −0 tests/transportD/tests/simple/program.js
  70. +20 −0 tests/transportD/tests/simple/test.js
  71. +142 −30 yabble.js
View
69 README
@@ -2,41 +2,72 @@ A general purpose browser-side CommonJS module loader
Yabble is a general purpose browser-side CommonJS module loader. Other similar module loaders are available, but Yabble strives to be a flexible loader in a small package.
-** NOTE: This is an early release. See below for more information **
+To see live unit tests, visit:
+http://jbrantly.github.com/yabble/tests/index.html
+
+To see an overview of the goals, visit:
+http://blog.jbrantly.com/2010/04/introducing-yabble.html
Features:
- * Compliant with Modules 1.0
+ * Compliant with Modules 1.1.1
* Supports async XHR/eval()
- Allows the use of non-transport-wrapped module code for quick development
* Supports script tags with a Transport format
- Easier debugging, potential for file concatenation
- * Includes a tool for automatically wrapping modules in a Transport format
+ - Supports Transport/D and Transport/C
* Supports require.ensure() for lazy-loading modules
- * Small size (<500 lines, ~13kb raw, ~4kb minified, and <2kb when minified/gzipped)
+ * Passes unit tests on YUI's A-grade browsers
+ * Includes a tool for automatically wrapping modules in a Transport format
+ * Small size (<600 lines, ~15kb raw, ~5kb minified, and ~2kb when minified/gzipped)
Roadmap:
* Stability
- - Better cross-browser compliance
- - More unit tests
- - Better unit testing framework
+ - Even more cross-browser testing
+ - More unit tests for Async/A
* Features
- - Implement support for Modules 1.1(.1)
- - Complete support for Transport/D
- - Implement support for Transport/C
- - Explicit support for concatenated Transport files in loader and tooling
- * Loader
+ - Async/A error handling once its decided (maybe before)
+ - Tested support for loading from another domain (it may work now..)
+ * Documentation
+ * Tooling
+ - Currently under-developed. Not recommended to use.
- Use loader code in tooling (no copy/paste code)
+ - Explicit support for concatenated Transport files tooling (loader should already support)
- Expand supported engines for tooling (node.js)
- Better consideration for platform (line endings, encoding, etc)
-Notes on the current release:
+Usage:
+
+require.setModuleRoot(path)
+
+ Use this to configure the root path to find modules. Think of this as a
+ single entry in require.paths.
+
+require.useScriptTags()
+
+ The default behavior is to use XHR+eval() and expects unwrapped modules. Call this method
+ to configure Yabble to use script tags and expect wrapped modules.
+
+require.run(programId)
+
+ This kicks off an application using the specified module ID.
+
+require.ensure(dependencies, callback)
+
+ See Async/A for more details. Can be used to retrieve modules and run code without using
+ require.run().
+
+See unit tests for example usage.
-This is the first release and is currently unsuitable for any sort of production work. The loader has passed the Module 1.0 unit tests on IE 6/7 and FF 3. While complete cross-browser support is a short-term goal, this release does not offer it.
+Changelog:
-The tooling (yabbler.js) currently supports the Rhino javascript engine and is very under-developed. It is offered as a preview of what is to come.
+04-14-2010
+ - Now using QUnit for unit tests
+ - Added support for Modules 1.1.1 plus unit tests
+ - Finished support for Transport/D plus unit tests
+ - Added support for Transport/C plus unit tests
+ - Added unit tests for Async/A and fixed bugs
+ - Added unit tests for resolveModuleId and determineShallowDependencies
-For example usage for both the loader and the tooling, please see the Modules 1.0 unit tests.
+04-12-2010
+ - Initial commit
-To see the unit tests live, visit:
-XHR/eval - http://jbrantly.github.com/yabble/tests/modules1.0/index.html
-<script>/wrapped - http://jbrantly.github.com/yabble/tests/modules1.0/wrappedIndex.html
View
41 tests/asyncA/index.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
+ <script type="text/javascript">
+ var tests = [
+ ['absolute', 1],
+ ['cyclic', 4],
+ ['relative', 1]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
+ require.reset();
+ require.setModuleRoot('tests/' + testName);
+ require.run('program');
+ };
+ })(testName));
+
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Async/A Unit Tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
1  tests/asyncA/tests/absolute/b.js
@@ -0,0 +1 @@
+exports.foo = function() {};
View
9 tests/asyncA/tests/absolute/program.js
@@ -0,0 +1,9 @@
+require.ensure(['test', 'submodule/a', 'b'], function(require) {
+ var test = require('test');
+ var a = require('submodule/a');
+ var b = require('b');
+ a.foo(function(bThruA) {
+ test.assert(bThruA.foo === b.foo, 'require.ensure works with absolute identifiers');
+ test.print('DONE', 'info');
+ });
+});
View
5 tests/asyncA/tests/absolute/submodule/a.js
@@ -0,0 +1,5 @@
+exports.foo = function (cb) {
+ require.ensure(['b'], function(require) {
+ cb(require('b'));
+ });
+};
View
15 tests/asyncA/tests/absolute/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
4 tests/asyncA/tests/cyclic/a.js
@@ -0,0 +1,4 @@
+exports.a = function () {
+ return b;
+};
+var b = require('b');
View
4 tests/asyncA/tests/cyclic/b.js
@@ -0,0 +1,4 @@
+var a = require('a');
+exports.b = function () {
+ return a;
+};
View
12 tests/asyncA/tests/cyclic/program.js
@@ -0,0 +1,12 @@
+require.ensure(['test', 'a', 'b'], function(require) {
+ var test = require('test');
+ var a = require('a');
+ var b = require('b');
+
+ test.assert(a.a, 'a exists');
+ test.assert(b.b, 'b exists')
+ test.assert(a.a().b === b.b, 'a gets b');
+ test.assert(b.b().a === a.a, 'b gets a');
+
+ test.print('DONE', 'info');
+});
View
15 tests/asyncA/tests/cyclic/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
10 tests/asyncA/tests/relative/program.js
@@ -0,0 +1,10 @@
+require.ensure(['test', 'submodule/a', 'submodule/b'], function(require) {
+ var test = require('test');
+ var a = require('submodule/a');
+ var b = require('submodule/b');
+
+ a.foo(function(bfoo) {
+ test.assert(bfoo == b.foo, 'a and b share foo through a relative require');
+ test.print('DONE', 'info');
+ });
+});
View
5 tests/asyncA/tests/relative/submodule/a.js
@@ -0,0 +1,5 @@
+exports.foo = function(cb) {
+ require.ensure(['./b'], function(require) {
+ cb(require('./b').foo);
+ });
+};
View
2  tests/asyncA/tests/relative/submodule/b.js
@@ -0,0 +1,2 @@
+exports.foo = function () {
+};
View
15 tests/asyncA/tests/relative/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
43 tests/asyncA/wrappedIndex.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
+ <script type="text/javascript">
+ require.useScriptTags();
+
+ var tests = [
+ ['absolute', 1],
+ ['cyclic', 4],
+ ['relative', 1]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
+ require.reset();
+ require.setModuleRoot('wrappedTests/' + testName);
+ require.run('program');
+ };
+ })(testName));
+
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Async/A Unit Tests (Wrapped Modules)</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
6 tests/asyncA/wrappedTests/absolute/b.js
@@ -0,0 +1,6 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"b": function(require, exports, module) {
+exports.foo = function() {};
+
+}}, []);
View
13 tests/asyncA/wrappedTests/absolute/program.js
@@ -0,0 +1,13 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"program": function(require, exports, module) {
+require.ensure(['test', 'submodule/a', 'b'], function(require) {
+ var test = require('test');
+ var a = require('submodule/a');
+ var b = require('b');
+ a.foo(function(bThruA) {
+ test.assert(bThruA.foo === b.foo, 'require.ensure works with absolute identifiers');
+ test.print('DONE', 'info');
+ });
+});
+}}, []);
View
10 tests/asyncA/wrappedTests/absolute/submodule/a.js
@@ -0,0 +1,10 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"submodule/a": function(require, exports, module) {
+exports.foo = function (cb) {
+ require.ensure(['b'], function(require) {
+ cb(require('b'));
+ });
+};
+
+}}, []);
View
20 tests/asyncA/wrappedTests/absolute/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
9 tests/asyncA/wrappedTests/cyclic/a.js
@@ -0,0 +1,9 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"a": function(require, exports, module) {
+exports.a = function () {
+ return b;
+};
+var b = require('b');
+
+}}, ["b"]);
View
9 tests/asyncA/wrappedTests/cyclic/b.js
@@ -0,0 +1,9 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"b": function(require, exports, module) {
+var a = require('a');
+exports.b = function () {
+ return a;
+};
+
+}}, ["a"]);
View
16 tests/asyncA/wrappedTests/cyclic/program.js
@@ -0,0 +1,16 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"program": function(require, exports, module) {
+require.ensure(['test', 'a', 'b'], function(require) {
+ var test = require('test');
+ var a = require('a');
+ var b = require('b');
+
+ test.assert(a.a, 'a exists');
+ test.assert(b.b, 'b exists')
+ test.assert(a.a().b === b.b, 'a gets b');
+ test.assert(b.b().a === a.a, 'b gets a');
+
+ test.print('DONE', 'info');
+});
+}}, []);
View
20 tests/asyncA/wrappedTests/cyclic/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
14 tests/asyncA/wrappedTests/relative/program.js
@@ -0,0 +1,14 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"program": function(require, exports, module) {
+require.ensure(['test', 'submodule/a', 'submodule/b'], function(require) {
+ var test = require('test');
+ var a = require('submodule/a');
+ var b = require('submodule/b');
+
+ a.foo(function(bfoo) {
+ test.assert(bfoo == b.foo, 'a and b share foo through a relative require');
+ test.print('DONE', 'info');
+ });
+});
+}}, []);
View
9 tests/asyncA/wrappedTests/relative/submodule/a.js
@@ -0,0 +1,9 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"submodule/a": function(require, exports, module) {
+exports.foo = function(cb) {
+ require.ensure(['./b'], function(require) {
+ cb(require('./b').foo);
+ });
+};
+}}, []);
View
7 tests/asyncA/wrappedTests/relative/submodule/b.js
@@ -0,0 +1,7 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"submodule/b": function(require, exports, module) {
+exports.foo = function () {
+};
+
+}}, []);
View
20 tests/asyncA/wrappedTests/relative/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
3  tests/asyncA/yabbler.bat
@@ -0,0 +1,3 @@
+java -jar ../../js.jar ../../yabbler.js -i "tests/absolute" -o "wrappedTests/absolute"
+java -jar ../../js.jar ../../yabbler.js -i "tests/cyclic" -o "wrappedTests/cyclic"
+java -jar ../../js.jar ../../yabbler.js -i "tests/relative" -o "wrappedTests/relative"
View
4 tests/determineShallowDependencies/modules/knownfailure.js
@@ -1,4 +1,6 @@
require('moduleA');
require.ensure(['moduleA'], function(require) {
require('moduleA');
-});
+});
+/* require('moduleB') */
+// require('moduleB')
View
29 tests/index.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
+
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Unit Tests</h1>
+ <h2 id="qunit-banner" class="qunit-pass"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests">
+ <li class="pass"><a href="modules1.0/index.html">Modules/1.0</a></li>
+ <li class="pass"><a href="modules1.0/wrappedIndex.html">Modules/1.0 Wrapped</a></li>
+ <li class="pass"><a href="modules1.1.1/index.html">Modules/1.1.1</a></li>
+ <li class="pass"><a href="modules1.1.1/wrappedIndex.html">Modules/1.1.1 Wrapped</a></li>
+ <li class="pass"><a href="transportC/index.html">Transport/C</a></li>
+ <li class="pass"><a href="transportD/index.html">Transport/D</a></li>
+ <li class="pass"><a href="asyncA/index.html">Async/A</a></li>
+ <li class="pass"><a href="asyncA/wrappedIndex.html">Async/A Wrapped</a></li>
+ <li class="pass"><a href="determineShallowDependencies/index.html">determineShallowDependencies()</a></li>
+ <li class="pass"><a href="resolveModuleId/index.html">resolveModuleId()</a></li>
+ </ol>
+ <p id="qunit-testresult" class="result">
+ </p>
+ </body>
+</html>
View
26 tests/modules1.0/index.html
@@ -12,17 +12,17 @@
<script type="text/javascript">
var tests = [
- ['absolute', 2],
- ['cyclic', 5],
- ['determinism', 2],
- ['exactExports', 2],
- ['hasOwnProperty', 1],
- ['method', 4],
- ['missing', 2],
- ['monkeys', 2],
- ['nested', 2],
- ['relative', 2],
- ['transitive', 2]
+ ['absolute', 1],
+ ['cyclic', 4],
+ ['determinism', 1],
+ ['exactExports', 1],
+ ['hasOwnProperty', 0],
+ ['method', 3],
+ ['missing', 1],
+ ['monkeys', 1],
+ ['nested', 1],
+ ['relative', 1],
+ ['transitive', 1]
];
for (var i = 0, n = tests.length; i<n; i++) {
@@ -33,9 +33,7 @@
stop();
require.reset();
require.setModuleRoot('tests/' + testName);
- require.run('program', function() {
- start();
- });
+ require.run('program');
};
})(testName));
View
26 tests/modules1.0/wrappedIndex.html
@@ -14,17 +14,17 @@
require.useScriptTags();
var tests = [
- ['absolute', 2],
- ['cyclic', 5],
- ['determinism', 2],
- ['exactExports', 2],
- ['hasOwnProperty', 1],
- ['method', 4],
- ['missing', 2],
- ['monkeys', 2],
- ['nested', 2],
- ['relative', 2],
- ['transitive', 2]
+ ['absolute', 1],
+ ['cyclic', 4],
+ ['determinism', 1],
+ ['exactExports', 1],
+ ['hasOwnProperty', 0],
+ ['method', 3],
+ ['missing', 1],
+ ['monkeys', 1],
+ ['nested', 1],
+ ['relative', 1],
+ ['transitive', 1]
];
for (var i = 0, n = tests.length; i<n; i++) {
@@ -35,9 +35,7 @@
stop();
require.reset();
require.setModuleRoot('wrappedTests/' + testName);
- require.run('program', function() {
- start();
- });
+ require.run('program');
};
})(testName));
View
40 tests/modules1.1.1/index.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
+ <script type="text/javascript">
+ var tests = [
+ ['module', 9],
+ ['main', 3]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
+ require.reset();
+ require.setModuleRoot('tests/' + testName);
+ require.run('program');
+ };
+ })(testName));
+
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Modules/1.1.1 Unit Tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
3  tests/modules1.1.1/tests/main/a.js
@@ -0,0 +1,3 @@
+exports.main = function() {
+ return require.main;
+};
View
0  tests/modules1.1.1/tests/main/b.js
No changes.
View
11 tests/modules1.1.1/tests/main/program.js
@@ -0,0 +1,11 @@
+var test = require('test');
+
+test.assert(require.main != null && require.main === module, 'main module has require.main');
+
+var aMain = require('a').main();
+test.assert(aMain != null && aMain === module, 'submodule has require.main');
+
+require.ensure(['b'], function(require) {
+ test.assert(require.main != null && require.main === module, 'require.ensure has require.main');
+ test.print('DONE', 'info');
+});
View
15 tests/modules1.1.1/tests/main/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
3  tests/modules1.1.1/tests/module/a.js
@@ -0,0 +1,3 @@
+exports.module = function() {
+ return module;
+};
View
17 tests/modules1.1.1/tests/module/program.js
@@ -0,0 +1,17 @@
+var test = require('test');
+
+test.assert(module != null, 'program has module');
+test.assert(module.id == 'program', 'module.id set to program');
+test.assert(/^http(s?):\/\//.test(module.uri) && module.uri.substring(module.uri.length-10) == 'program.js', 'module.uri is absolute and ends with program.js');
+
+var aModule = require('a').module();
+var bModule = require('submodule/b').module();
+
+test.assert(aModule != null, 'a has module');
+test.assert(aModule.id == 'a', 'module.id set to a');
+test.assert(/^http(s?):\/\//.test(aModule.uri) && aModule.uri.substring(aModule.uri.length-4) == 'a.js', 'module.uri is absolute and ends with a.js');
+
+test.assert(bModule != null, 'submodule/b has module');
+test.assert(bModule.id == 'submodule/b', 'module.id set to submodule/b');
+test.assert(/^http(s?):\/\//.test(bModule.uri) && bModule.uri.substring(bModule.uri.length-14) == 'submodule/b.js', 'module.uri is absolute and ends with submodule/b.js');
+test.print('DONE', 'info');
View
3  tests/modules1.1.1/tests/module/submodule/b.js
@@ -0,0 +1,3 @@
+exports.module = function() {
+ return module;
+};
View
15 tests/modules1.1.1/tests/module/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
42 tests/modules1.1.1/wrappedIndex.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
+ <script type="text/javascript">
+ require.useScriptTags();
+
+ var tests = [
+ ['module', 9],
+ ['main', 3]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
+ require.reset();
+ require.setModuleRoot('wrappedTests/' + testName);
+ require.run('program');
+ };
+ })(testName));
+
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Modules/1.1.1 Unit Tests (Wrapped Modules)</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
7 tests/modules1.1.1/wrappedTests/main/a.js
@@ -0,0 +1,7 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"a": function(require, exports, module) {
+exports.main = function() {
+ return require.main;
+};
+}}, []);
View
5 tests/modules1.1.1/wrappedTests/main/b.js
@@ -0,0 +1,5 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"b": function(require, exports, module) {
+
+}}, []);
View
15 tests/modules1.1.1/wrappedTests/main/program.js
@@ -0,0 +1,15 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"program": function(require, exports, module) {
+var test = require('test');
+
+test.assert(require.main != null && require.main === module, 'main module has require.main');
+
+var aMain = require('a').main();
+test.assert(aMain != null && aMain === module, 'submodule has require.main');
+
+require.ensure(['b'], function(require) {
+ test.assert(require.main != null && require.main === module, 'require.ensure has require.main');
+ test.print('DONE', 'info');
+});
+}}, ["test", "a"]);
View
20 tests/modules1.1.1/wrappedTests/main/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
7 tests/modules1.1.1/wrappedTests/module/a.js
@@ -0,0 +1,7 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"a": function(require, exports, module) {
+exports.module = function() {
+ return module;
+};
+}}, []);
View
21 tests/modules1.1.1/wrappedTests/module/program.js
@@ -0,0 +1,21 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"program": function(require, exports, module) {
+var test = require('test');
+
+test.assert(module != null, 'program has module');
+test.assert(module.id == 'program', 'module.id set to program');
+test.assert(/^http(s?):\/\//.test(module.uri) && module.uri.substring(module.uri.length-10) == 'program.js', 'module.uri is absolute and ends with program.js');
+
+var aModule = require('a').module();
+var bModule = require('submodule/b').module();
+
+test.assert(aModule != null, 'a has module');
+test.assert(aModule.id == 'a', 'module.id set to a');
+test.assert(/^http(s?):\/\//.test(aModule.uri) && aModule.uri.substring(aModule.uri.length-4) == 'a.js', 'module.uri is absolute and ends with a.js');
+
+test.assert(bModule != null, 'submodule/b has module');
+test.assert(bModule.id == 'submodule/b', 'module.id set to submodule/b');
+test.assert(/^http(s?):\/\//.test(bModule.uri) && bModule.uri.substring(bModule.uri.length-14) == 'submodule/b.js', 'module.uri is absolute and ends with submodule/b.js');
+test.print('DONE', 'info');
+}}, ["test", "a", "submodule/b"]);
View
7 tests/modules1.1.1/wrappedTests/module/submodule/b.js
@@ -0,0 +1,7 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"submodule/b": function(require, exports, module) {
+exports.module = function() {
+ return module;
+};
+}}, []);
View
20 tests/modules1.1.1/wrappedTests/module/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
2  tests/modules1.1.1/yabbler.bat
@@ -0,0 +1,2 @@
+java -jar ../../js.jar ../../yabbler.js -i "tests/main" -o "wrappedTests/main"
+java -jar ../../js.jar ../../yabbler.js -i "tests/module" -o "wrappedTests/module"
View
9 tests/print.js
@@ -1,3 +1,10 @@
window.print = function(message, type) {
- ok(type == 'info' || type == 'pass', message);
+ if (type == 'info') {
+ if (message == 'DONE') {
+ start();
+ }
+ }
+ else {
+ ok(type == 'pass', message);
+ }
}
View
43 tests/transportC/index.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
+ <script type="text/javascript">
+ require.useScriptTags();
+
+ var tests = [
+ ['simple', 3],
+ ['multipleDefines', 8],
+ ['injects', 9]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
+ require.reset();
+ require.setModuleRoot('tests/' + testName);
+ require.run('program');
+ };
+ })(testName));
+
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Transport/C Unit Tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
26 tests/transportC/tests/injects/program.js
@@ -0,0 +1,26 @@
+require.def('program', ['require', 'exports', 'module', 'test', 'a', 'b'], function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+
+ require('a');
+ require('b');
+
+ test.print('DONE', 'info');
+});
+
+
+require.def('a', ['require', 'test'], function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'undefined', 'exports is undefined');
+ test.assert(typeof modules == 'undefined', 'module is undefined');
+});
+
+require.def('b', ['module', 'require', 'exports', 'test'], function(module, require, exports) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'b', 'module.id is b');
+});
View
20 tests/transportC/tests/injects/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
20 tests/transportC/tests/multipleDefines/program.js
@@ -0,0 +1,20 @@
+require.def('program', ['require', 'exports', 'module', 'test', 'a'], function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+ test.assert(require('a').foo == 'bar', 'module a is available');
+ test.print('DONE', 'info');
+});
+
+// This part could use some cleaning up
+var aIsKnown = require.isKnown('a');
+print((aIsKnown ? 'FAIL ' : 'PASS ') + 'a is not yet known', (aIsKnown ? 'fail' : 'pass'));
+
+require.def('a', ['require', 'exports', 'module', 'test'], function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'a', 'module.id is a');
+ exports.foo = 'bar';
+});
View
20 tests/transportC/tests/multipleDefines/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
7 tests/transportC/tests/simple/program.js
@@ -0,0 +1,7 @@
+require.def('program', ['require', 'exports', 'module', 'test'], function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+ test.print('DONE', 'info');
+});
View
20 tests/transportC/tests/simple/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
45 tests/transportD/index.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
+ <script type="text/javascript">
+ require.useScriptTags();
+
+ var tests = [
+ ['simple', 3],
+ ['multipleModules', 7],
+ ['multipleDefines', 8],
+ ['injects', 9],
+ ['mixedDescriptors', 6]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
+ require.reset();
+ require.setModuleRoot('tests/' + testName);
+ require.run('program');
+ };
+ })(testName));
+
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble Transport/D Unit Tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
View
34 tests/transportD/tests/injects/program.js
@@ -0,0 +1,34 @@
+require.define({
+ "program": {
+ injects: ['require', 'exports', 'module'],
+ factory: function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+
+ require('a');
+ require('b');
+
+ test.print('DONE', 'info');
+ }
+ },
+ "a": {
+ injects: ['require'],
+ factory: function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'undefined', 'exports is undefined');
+ test.assert(typeof modules == 'undefined', 'module is undefined');
+ }
+ },
+ "b": {
+ injects: ['module', 'require', 'exports'],
+ factory: function(module, require, exports) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'b', 'module.id is b');
+ }
+ }
+}, ['test']);
View
20 tests/transportD/tests/injects/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
21 tests/transportD/tests/mixedDescriptors/program.js
@@ -0,0 +1,21 @@
+require.define({
+ "program": function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+
+ require('a');
+
+ test.print('DONE', 'info');
+ },
+ "a": {
+ injects: ['require'],
+ factory: function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'undefined', 'exports is undefined');
+ test.assert(typeof modules == 'undefined', 'module is undefined');
+ }
+ }
+}, ['test']);
View
20 tests/transportD/tests/mixedDescriptors/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
24 tests/transportD/tests/multipleDefines/program.js
@@ -0,0 +1,24 @@
+require.define({
+ "program": function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+ test.assert(require('a').foo == 'bar', 'module a is available');
+ test.print('DONE', 'info');
+ }
+}, ['test', 'a']);
+
+// This part could use some cleaning up
+var aIsKnown = require.isKnown('a');
+print((aIsKnown ? 'FAIL ' : 'PASS ') + 'a is not yet known', (aIsKnown ? 'fail' : 'pass'));
+
+require.define({
+ "a": function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'a', 'module.id is a');
+ exports.foo = 'bar';
+ }
+}, ['test']);
View
20 tests/transportD/tests/multipleDefines/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
17 tests/transportD/tests/multipleModules/program.js
@@ -0,0 +1,17 @@
+require.define({
+ "program": function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+ test.assert(require('a').foo == 'bar', 'module a is available');
+ test.print('DONE', 'info');
+ },
+ "a": function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'a', 'module.id is a');
+ exports.foo = 'bar';
+ }
+}, ['test']);
View
20 tests/transportD/tests/multipleModules/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
9 tests/transportD/tests/simple/program.js
@@ -0,0 +1,9 @@
+require.define({
+ "program": function(require, exports, module) {
+ var test = require('test');
+ test.assert(typeof require == 'function', 'require is a function');
+ test.assert(typeof exports == 'object', 'exports is an object');
+ test.assert(module.id == 'program', 'module.id is program');
+ test.print('DONE', 'info');
+ }
+}, ['test']);
View
20 tests/transportD/tests/simple/test.js
@@ -0,0 +1,20 @@
+/* This file has been generated by yabbler.js */
+require.define({
+"test": function(require, exports, module) {
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
+
+}}, ["system"]);
View
172 yabble.js
@@ -35,7 +35,8 @@
_modules,
_callbacks,
_fetchFunc,
- _timeoutLength = 20000;
+ _timeoutLength = 20000,
+ _mainProgram;
var head = document.getElementsByTagName('head')[0];
@@ -78,28 +79,52 @@
};
}
+ // Array convenience functions
+ var indexOf = function(arr, val) {
+ for (var i = arr.length; i--;) {
+ if (arr[i] == val) { return i; }
+ }
+ return -1;
+ };
+
+ var removeWhere = function(arr, func) {
+ var i = 0;
+ while (i < arr.length) {
+ if (func.call(null, arr[i], i) === true) {
+ arr.splice(i, 1);
+ }
+ else {
+ i++;
+ }
+ }
+ };
+
+ var combinePaths = function(relPath, refPath) {
+ var relPathParts = relPath.split('/');
+ refPath = refPath || '';
+ if (refPath.length && refPath.charAt(refPath.length-1) != '/') {
+ refPath += '/';
+ }
+ var refPathParts = refPath.split('/');
+ refPathParts.pop();
+ var part;
+ while (part = relPathParts.shift()) {
+ if (part == '.') { continue; }
+ else if (part == '..'
+ && refPathParts.length
+ && refPathParts[refPathParts.length-1] != '..') { refPathParts.pop(); }
+ else { refPathParts.push(part); }
+ }
+ return refPathParts.join('/');
+ };
+
// Takes a relative path to a module and resolves it according to the reference path
var resolveModuleId = Yabble.unit.resolveModuleId = function(relModuleId, refPath) {
if (relModuleId.charAt(0) != '.') {
return relModuleId;
}
else {
- var relativeIdParts = relModuleId.split('/');
- refPath = refPath || '';
- if (refPath.length && refPath.charAt(refPath.length-1) != '/') {
- refPath += '/';
- }
- var refPathParts = refPath.split('/');
- refPathParts.pop();
- var part;
- while (part = relativeIdParts.shift()) {
- if (part == '.') { continue; }
- else if (part == '..'
- && refPathParts.length
- && refPathParts[refPathParts.length-1] != '..') { refPathParts.pop(); }
- else { refPathParts.push(part); }
- }
- return refPathParts.join('/');
+ return combinePaths(relModuleId, refPath);
}
};
@@ -135,11 +160,11 @@
var moduleId = resolveModuleId(deps[i], refPath),
module = getModule(moduleId);
- if (!areDeepDepsDefined(module)) {
+ if (!areDeepDepsDefined(moduleId)) {
unreadyModules.push(moduleId);
}
}
-
+
if (unreadyModules.length) {
addCallback(unreadyModules, function() {
cb(createRequireFunc(refPath));
@@ -147,7 +172,9 @@
queueModules(unreadyModules);
}
else {
- setTimeout(cb, 0);
+ setTimeout(function() {
+ cb(createRequireFunc(refPath));
+ }, 0);
}
};
@@ -168,8 +195,23 @@
if (!module.exports) {
module.exports = {};
- var moduleDir = moduleId.substring(0, moduleId.lastIndexOf('/')+1);
- module.factory(createRequireFunc(moduleDir), module.exports);
+ var moduleDir = moduleId.substring(0, moduleId.lastIndexOf('/')+1),
+ injects = module.injects,
+ args = [];
+
+ for (var i = 0, n = injects.length; i<n; i++) {
+ if (injects[i] == 'require') {
+ args.push(createRequireFunc(moduleDir));
+ }
+ else if (injects[i] == 'exports') {
+ args.push(module.exports);
+ }
+ else if (injects[i] == 'module') {
+ args.push(module.module);
+ }
+ }
+
+ module.factory.apply(null, args);
}
return module.exports;
};
@@ -177,6 +219,10 @@
require.ensure = function(deps, cb) {
ensureImpl(deps, cb, refPath);
};
+
+ if (_mainProgram != null) {
+ require.main = getModule(_mainProgram).module;
+ }
return require;
};
@@ -198,7 +244,6 @@
// can more or less safely run the module factory function)
var areDeepDepsDefined = function(moduleId) {
var visitedModules = {};
- var self = this;
var recurse = function(moduleId) {
if (visitedModules[moduleId] == true) { return true; }
visitedModules[moduleId] = true;
@@ -368,11 +413,55 @@
head.appendChild(scriptEl);
};
+ var normalizeTransport = function() {
+ var transport = {modules: []};
+ var standardInjects = ['require', 'exports', 'module'];
+ if (typeof arguments[0] == 'object') { // Transport/D
+ transport.deps = arguments[1] || [];
+ var moduleDefs = arguments[0];
+ forIn(moduleDefs, function(moduleId) {
+ var module = {
+ id: moduleId
+ };
+
+ if (typeof moduleDefs[moduleId] == 'function') {
+ module.factory = moduleDefs[moduleId];
+ module.injects = standardInjects;
+ }
+ else {
+ module.factory = moduleDefs[moduleId].factory;
+ module.injects = moduleDefs[moduleId].injects || standardInjects;
+ }
+ transport.modules.push(module);
+ });
+ }
+ else { // Transport/C
+ transport.deps = arguments[1].slice(0);
+ removeWhere(transport.deps, function(dep) {
+ return indexOf(standardInjects, dep) >= 0;
+ });
+
+ transport.modules.push({
+ id: arguments[0],
+ factory: arguments[2],
+ injects: arguments[1]
+ });
+ }
+ return transport;
+ };
+
// Set the uri which forms the conceptual module namespace root
Yabble.setModuleRoot = function(path) {
+ if (!(/^http(s?):\/\//.test(path))) {
+ var href = window.location.href;
+ href = href.substr(0, href.lastIndexOf('/')+1);
+ path = combinePaths(path, href);
+ }
+
if (path.length && path.charAt(path.length-1) != '/') {
path += '/';
}
+
_moduleRoot = path;
};
@@ -387,23 +476,33 @@
};
// Define a module per various transport specifications
- Yabble.define = function(moduleDefs, deps) {
+ Yabble.def = Yabble.define = function() {
+ var transport = normalizeTransport.apply(null, arguments);
var unreadyModules = [],
definedModules = [];
- deps = deps || [];
+ var deps = transport.deps;
- forIn(moduleDefs, function(moduleId) {
- var module = getModule(moduleId);
+ for (var i = transport.modules.length; i--;) {
+ var moduleDef = transport.modules[i],
+ moduleId = moduleDef.id,
+ module = getModule(moduleId);
+
if (!module) {
module = _modules[moduleId] = {};
}
+ module.module = {
+ id: moduleId,
+ uri: resolveModuleUri(moduleId)
+ };
+
module.defined = true;
module.deps = deps.slice(0);
- module.factory = moduleDefs[moduleId];
+ module.injects = moduleDef.injects;
+ module.factory = moduleDef.factory;
definedModules.push(module);
- }, this);
+ }
for (var i = deps.length; i--;) {
var moduleId = deps[i],
@@ -415,12 +514,23 @@
}
if (unreadyModules.length) {
- queueModules(unreadyModules);
+ setTimeout(function() {
+ queueModules(unreadyModules);
+ }, 0);
}
fireCallbacks();
};
+ Yabble.isKnown = function(moduleId) {
+ return getModule(moduleId) != null;
+ };
+
+ Yabble.isDefined = function(moduleId) {
+ var module = getModule(moduleId);
+ return !!(module && module.defined);
+ };
+
// Do an async lazy-load of modules
Yabble.ensure = function(deps, cb) {
ensureImpl(deps, cb, '');
@@ -428,6 +538,7 @@
// Start an application via a main program module
Yabble.run = function(program, cb) {
+ program = _mainProgram = resolveModuleId(program, '');
Yabble.ensure([program], function(require) {
require(program);
if (cb != null) { cb(); }
@@ -436,6 +547,7 @@
// Reset internal state. Used mostly for unit tests.
Yabble.reset = function() {
+ _mainProgram = null;
_modules = {};
_callbacks = [];
Please sign in to comment.
Something went wrong with that request. Please try again.