From dd8b78f934e32994e3f8160c477064d801e8d1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Sun, 28 Apr 2019 20:55:27 +0200 Subject: [PATCH] Integrate unused CommonJS tests where applicable (#195) There has been an unused copy of [The Official Specs for CommonJS][1] lying around in our repository for who knows how long. They needed to be built using a python script and then manually executed in a browser. This commit integrates all of those tests that also apply to our module system into our existing test suite for `require` & `define`. Adds adapted versions of the following CommonJs tests to our `test.require.js`: absolute, transitive, determinism, method, nested, hasOwnProperty The hasOwnProperty test actually uncovered a bug in our module system implementation and thus is deactivated right now. The following CommonJS tests were not applicable to Cordova's module system since it does not support cyclic dependencies at all: cyclic, monkeys The following CommonJS tests were already covered by tests in `test.require.js`: - missing: covered by Test#005 - relative: covered by Test#012 - exactExports: covered by multiple tests [1]: https://github.com/commonjs/commonjs --- .eslintignore | 1 - .ratignore | 2 - tasks/vendor/commonjs-tests/README.txt | 9 - .../commonjs-tests/modules/1.0/absolute/b.js | 1 - .../modules/1.0/absolute/program.js | 5 - .../modules/1.0/absolute/submodule/a.js | 3 - .../modules/1.0/absolute/test.js | 15 -- .../commonjs-tests/modules/1.0/cyclic/a.js | 4 - .../commonjs-tests/modules/1.0/cyclic/b.js | 4 - .../modules/1.0/cyclic/program.js | 10 - .../commonjs-tests/modules/1.0/cyclic/test.js | 15 -- .../modules/1.0/determinism/program.js | 3 - .../modules/1.0/determinism/submodule/a.js | 9 - .../modules/1.0/determinism/submodule/b.js | 2 - .../modules/1.0/determinism/test.js | 15 -- .../modules/1.0/exactExports/a.js | 3 - .../modules/1.0/exactExports/program.js | 4 - .../modules/1.0/exactExports/test.js | 15 -- .../1.0/hasOwnProperty/hasOwnProperty.js | 0 .../modules/1.0/hasOwnProperty/program.js | 4 - .../modules/1.0/hasOwnProperty/test.js | 15 -- .../modules/1.0/hasOwnProperty/toString.js | 0 .../commonjs-tests/modules/1.0/method/a.js | 12 -- .../modules/1.0/method/program.js | 8 - .../commonjs-tests/modules/1.0/method/test.js | 15 -- .../modules/1.0/missing/program.js | 8 - .../modules/1.0/missing/test.js | 15 -- .../commonjs-tests/modules/1.0/monkeys/a.js | 1 - .../modules/1.0/monkeys/program.js | 4 - .../modules/1.0/monkeys/test.js | 15 -- .../modules/1.0/nested/a/b/c/d.js | 3 - .../modules/1.0/nested/program.js | 3 - .../commonjs-tests/modules/1.0/nested/test.js | 15 -- .../modules/1.0/relative/program.js | 5 - .../modules/1.0/relative/submodule/a.js | 1 - .../modules/1.0/relative/submodule/b.js | 2 - .../modules/1.0/relative/test.js | 15 -- .../modules/1.0/transitive/a.js | 1 - .../modules/1.0/transitive/b.js | 1 - .../modules/1.0/transitive/c.js | 3 - .../modules/1.0/transitive/program.js | 3 - .../modules/1.0/transitive/test.js | 15 -- test/commonjs/.gitignore | 1 - test/commonjs/README.txt | 11 - test/commonjs/build-tests.py | 196 ------------------ .../commonjs/launcher-in-iframe.template.html | 73 ------- test/commonjs/launcher-main.template.html | 74 ------- test/commonjs/test.css | 43 ---- test/test.require.js | 86 ++++++++ 49 files changed, 86 insertions(+), 682 deletions(-) delete mode 100644 tasks/vendor/commonjs-tests/README.txt delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/absolute/b.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/absolute/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/absolute/submodule/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/absolute/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/cyclic/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/cyclic/b.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/cyclic/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/cyclic/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/determinism/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/b.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/determinism/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/exactExports/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/exactExports/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/exactExports/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/hasOwnProperty.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/toString.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/method/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/method/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/method/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/missing/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/missing/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/monkeys/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/monkeys/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/monkeys/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/nested/a/b/c/d.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/nested/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/nested/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/relative/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/b.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/relative/test.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/transitive/a.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/transitive/b.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/transitive/c.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/transitive/program.js delete mode 100644 tasks/vendor/commonjs-tests/modules/1.0/transitive/test.js delete mode 100644 test/commonjs/.gitignore delete mode 100644 test/commonjs/README.txt delete mode 100755 test/commonjs/build-tests.py delete mode 100644 test/commonjs/launcher-in-iframe.template.html delete mode 100644 test/commonjs/launcher-main.template.html delete mode 100644 test/commonjs/test.css diff --git a/.eslintignore b/.eslintignore index f76b6653a..6fe33ed72 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1 @@ pkg/** -tasks/vendor diff --git a/.ratignore b/.ratignore index d7f3a4925..9e4c1e1b5 100644 --- a/.ratignore +++ b/.ratignore @@ -1,3 +1 @@ -tasks/vendor -vendor appveyor.yml diff --git a/tasks/vendor/commonjs-tests/README.txt b/tasks/vendor/commonjs-tests/README.txt deleted file mode 100644 index 21ce79830..000000000 --- a/tasks/vendor/commonjs-tests/README.txt +++ /dev/null @@ -1,9 +0,0 @@ -The test cases contained in this directory were obtained from the -commonjs project at GitHub: - - https://github.com/commonjs/commonjs - -Specifically, the directories in the 'tests' subdirectory. - -See the file test/commonjs/README.txt off the root directory of this -project for more information. \ No newline at end of file diff --git a/tasks/vendor/commonjs-tests/modules/1.0/absolute/b.js b/tasks/vendor/commonjs-tests/modules/1.0/absolute/b.js deleted file mode 100644 index da5bf4fd1..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/absolute/b.js +++ /dev/null @@ -1 +0,0 @@ -exports.foo = function() {}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/absolute/program.js b/tasks/vendor/commonjs-tests/modules/1.0/absolute/program.js deleted file mode 100644 index 7980ecf14..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/absolute/program.js +++ /dev/null @@ -1,5 +0,0 @@ -var test = require('test'); -var a = require('submodule/a'); -var b = require('b'); -test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/absolute/submodule/a.js b/tasks/vendor/commonjs-tests/modules/1.0/absolute/submodule/a.js deleted file mode 100644 index bc138b87d..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/absolute/submodule/a.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.foo = function () { - return require('b'); -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/absolute/test.js b/tasks/vendor/commonjs-tests/modules/1.0/absolute/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/absolute/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/a.js b/tasks/vendor/commonjs-tests/modules/1.0/cyclic/a.js deleted file mode 100644 index e0188fa08..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/a.js +++ /dev/null @@ -1,4 +0,0 @@ -exports.a = function () { - return b; -}; -var b = require('b'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/b.js b/tasks/vendor/commonjs-tests/modules/1.0/cyclic/b.js deleted file mode 100644 index 873a30577..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/b.js +++ /dev/null @@ -1,4 +0,0 @@ -var a = require('a'); -exports.b = function () { - return a; -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/program.js b/tasks/vendor/commonjs-tests/modules/1.0/cyclic/program.js deleted file mode 100644 index 2ee4758db..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/program.js +++ /dev/null @@ -1,10 +0,0 @@ -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'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/test.js b/tasks/vendor/commonjs-tests/modules/1.0/cyclic/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/cyclic/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/determinism/program.js b/tasks/vendor/commonjs-tests/modules/1.0/determinism/program.js deleted file mode 100644 index 7c0e50b0b..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/determinism/program.js +++ /dev/null @@ -1,3 +0,0 @@ -var test = require('test'); -require('submodule/a'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/a.js b/tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/a.js deleted file mode 100644 index 215ea1d9a..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/a.js +++ /dev/null @@ -1,9 +0,0 @@ -var test = require('test'); -var pass = false; -var test = require('test'); -try { - require('a'); -} catch (exception) { - pass = true; -} -test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.') diff --git a/tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/b.js b/tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/b.js deleted file mode 100644 index 139597f9c..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/determinism/submodule/b.js +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/determinism/test.js b/tasks/vendor/commonjs-tests/modules/1.0/determinism/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/determinism/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/exactExports/a.js b/tasks/vendor/commonjs-tests/modules/1.0/exactExports/a.js deleted file mode 100644 index 99c929e44..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/exactExports/a.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.program = function () { - return require('program'); -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/exactExports/program.js b/tasks/vendor/commonjs-tests/modules/1.0/exactExports/program.js deleted file mode 100644 index e82bd6db2..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/exactExports/program.js +++ /dev/null @@ -1,4 +0,0 @@ -var test = require('test'); -var a = require('a'); -test.assert(a.program() === exports, 'exact exports'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/exactExports/test.js b/tasks/vendor/commonjs-tests/modules/1.0/exactExports/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/exactExports/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/hasOwnProperty.js b/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/hasOwnProperty.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/program.js b/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/program.js deleted file mode 100644 index 1653f1b86..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/program.js +++ /dev/null @@ -1,4 +0,0 @@ -var hasOwnProperty = require('hasOwnProperty'); -var toString = require('toString'); -var test = require('test'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/test.js b/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/toString.js b/tasks/vendor/commonjs-tests/modules/1.0/hasOwnProperty/toString.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/tasks/vendor/commonjs-tests/modules/1.0/method/a.js b/tasks/vendor/commonjs-tests/modules/1.0/method/a.js deleted file mode 100644 index 69c48af67..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/method/a.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.foo = function () { - return this; -}; -exports.set = function (x) { - this.x = x; -}; -exports.get = function () { - return this.x; -}; -exports.getClosed = function () { - return exports.x; -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/method/program.js b/tasks/vendor/commonjs-tests/modules/1.0/method/program.js deleted file mode 100644 index 192811c5a..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/method/program.js +++ /dev/null @@ -1,8 +0,0 @@ -var test = require('test'); -var a = require('a'); -var foo = a.foo; -test.assert(a.foo() == a, 'calling a module member'); -test.assert(foo() == (function (){return this})(), 'members not implicitly bound'); -a.set(10); -test.assert(a.get() == 10, 'get and set') -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/method/test.js b/tasks/vendor/commonjs-tests/modules/1.0/method/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/method/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/missing/program.js b/tasks/vendor/commonjs-tests/modules/1.0/missing/program.js deleted file mode 100644 index c6b03aa28..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/missing/program.js +++ /dev/null @@ -1,8 +0,0 @@ -var test = require('test'); -try { - require('bogus'); - test.print('FAIL require throws error when module missing', 'fail'); -} catch (exception) { - test.print('PASS require throws error when module missing', 'pass'); -} -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/missing/test.js b/tasks/vendor/commonjs-tests/modules/1.0/missing/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/missing/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/monkeys/a.js b/tasks/vendor/commonjs-tests/modules/1.0/monkeys/a.js deleted file mode 100644 index a949e1dcf..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/monkeys/a.js +++ /dev/null @@ -1 +0,0 @@ -require('program').monkey = 10; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/monkeys/program.js b/tasks/vendor/commonjs-tests/modules/1.0/monkeys/program.js deleted file mode 100644 index 42d67112e..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/monkeys/program.js +++ /dev/null @@ -1,4 +0,0 @@ -var a = require('a'); -var test = require('test'); -test.assert(exports.monkey == 10, 'monkeys permitted'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/monkeys/test.js b/tasks/vendor/commonjs-tests/modules/1.0/monkeys/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/monkeys/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/nested/a/b/c/d.js b/tasks/vendor/commonjs-tests/modules/1.0/nested/a/b/c/d.js deleted file mode 100644 index 69fd28228..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/nested/a/b/c/d.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.foo = function () { - return 1; -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/nested/program.js b/tasks/vendor/commonjs-tests/modules/1.0/nested/program.js deleted file mode 100644 index c014b5727..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/nested/program.js +++ /dev/null @@ -1,3 +0,0 @@ -var test = require('test'); -test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/nested/test.js b/tasks/vendor/commonjs-tests/modules/1.0/nested/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/nested/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/relative/program.js b/tasks/vendor/commonjs-tests/modules/1.0/relative/program.js deleted file mode 100644 index b3e4b6ed7..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/relative/program.js +++ /dev/null @@ -1,5 +0,0 @@ -var test = require('test'); -var a = require('submodule/a'); -var b = require('submodule/b'); -test.assert(a.foo == b.foo, 'a and b share foo through a relative require'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/a.js b/tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/a.js deleted file mode 100644 index 42e4ca086..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/a.js +++ /dev/null @@ -1 +0,0 @@ -exports.foo = require('./b').foo; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/b.js b/tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/b.js deleted file mode 100644 index 9042c16b5..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/relative/submodule/b.js +++ /dev/null @@ -1,2 +0,0 @@ -exports.foo = function () { -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/relative/test.js b/tasks/vendor/commonjs-tests/modules/1.0/relative/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/relative/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/tasks/vendor/commonjs-tests/modules/1.0/transitive/a.js b/tasks/vendor/commonjs-tests/modules/1.0/transitive/a.js deleted file mode 100644 index 4df7bb8d2..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/transitive/a.js +++ /dev/null @@ -1 +0,0 @@ -exports.foo = require('b').foo; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/transitive/b.js b/tasks/vendor/commonjs-tests/modules/1.0/transitive/b.js deleted file mode 100644 index 30ea70dd1..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/transitive/b.js +++ /dev/null @@ -1 +0,0 @@ -exports.foo = require('c').foo; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/transitive/c.js b/tasks/vendor/commonjs-tests/modules/1.0/transitive/c.js deleted file mode 100644 index 69fd28228..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/transitive/c.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.foo = function () { - return 1; -}; diff --git a/tasks/vendor/commonjs-tests/modules/1.0/transitive/program.js b/tasks/vendor/commonjs-tests/modules/1.0/transitive/program.js deleted file mode 100644 index 98bb99644..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/transitive/program.js +++ /dev/null @@ -1,3 +0,0 @@ -var test = require('test'); -test.assert(require('a').foo() == 1, 'transitive'); -test.print('DONE', 'info'); diff --git a/tasks/vendor/commonjs-tests/modules/1.0/transitive/test.js b/tasks/vendor/commonjs-tests/modules/1.0/transitive/test.js deleted file mode 100644 index 5d0984eec..000000000 --- a/tasks/vendor/commonjs-tests/modules/1.0/transitive/test.js +++ /dev/null @@ -1,15 +0,0 @@ - -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'); - } -}; - diff --git a/test/commonjs/.gitignore b/test/commonjs/.gitignore deleted file mode 100644 index c585e1938..000000000 --- a/test/commonjs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -out \ No newline at end of file diff --git a/test/commonjs/README.txt b/test/commonjs/README.txt deleted file mode 100644 index 16cb81f12..000000000 --- a/test/commonjs/README.txt +++ /dev/null @@ -1,11 +0,0 @@ -This directory contains tests for the CommonJS functionality in Cordova. - -The tests come from the GitHub project https://github.com/commonjs/commonjs - -To run the tests, first you need to build them. - -Open a shell, cd into this directory, and run `python build-tests.py`. - -This will generate a set of HTML files which will run the tests within -a browser. More instructions on how to run the tests are printed -after the tests are built. \ No newline at end of file diff --git a/test/commonjs/build-tests.py b/test/commonjs/build-tests.py deleted file mode 100755 index e94744e9e..000000000 --- a/test/commonjs/build-tests.py +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/env python - -# --- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# --- - -import os -import re -import sys -import shutil -import datetime -import subprocess - -PROGRAM = sys.argv[0] - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def main(): - - # all work done in directory of this program - baseDir = os.path.dirname(PROGRAM) - os.chdir(baseDir) - - testsDir = os.path.abspath("../../thirdparty/commonjs-tests") - outDir = os.path.abspath("out") - - # validate testsDir - if not os.path.exists(testsDir): - error("tests dir does not exist: %s" % testsDir) - - if not os.path.isdir(testsDir): - error("tests dir is not a directory: %s" % testsDir) - - # validate and reset outDir - if os.path.exists(outDir): - if not os.path.isdir(outDir): - error("out dir is not a directory: %s" % outDir) - - shutil.rmtree(outDir) - - os.makedirs(outDir) - - tests = getTests(testsDir) - - # now all work done in outDir - os.chdir("out") - - # build the individual tests - iframes = [] - for test in tests: - testName = test.replace('/', '-') - htmlFile = buildTest(os.path.join(testsDir, test), testName) - iframes.append("" % htmlFile) - - iframesLines = "\n".join(iframes) - - # build the browser launcher - html = fileContents("../launcher-main.template.html") - - html = html.replace("@iframes@", iframesLines) - html = html.replace("@date@", getDate()) - - oFileName = "launcher-all.html" - oFile = file(oFileName, "w") - oFile.write(html) - oFile.close() - - print - print "Generated browser test: %s" % os.path.abspath(oFileName) - print - print "You can run the test as a local file under Safari but not Chrome." - print "To test under Chrome, access the files via http://" - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def buildTest(testDir, testName): - - log("generating tests for %s" % (testName)) - - html = fileContents("../launcher-in-iframe.template.html") - - # get the list of modules - modules = getModules(testDir) - - modulesSource = [] - - modulesSource.append("try {") - - for module in modules: - source = fileContents("%s.js" % os.path.join(testDir, module)) - - modulesSource.append("//----------------------------------------------") - modulesSource.append("define('%s', function(require,exports,module) {" % module) - modulesSource.append(source.strip()) - modulesSource.append("});") - modulesSource.append("") - - modulesSource.append("}") - modulesSource.append("catch(e) {") - modulesSource.append(" console.log('exception thrown loading modules: ' + e)") - modulesSource.append("}") - - modulesLines = "\n".join(modulesSource) - - html = html.replace("@modules@", modulesLines) - html = html.replace("@title@", testName) - html = html.replace("@date@", getDate()) - - # build HTML launcher for iframe - oFileName = "%s.html" % testName - oFile = file(oFileName, "w") - oFile.write(html) - oFile.close() - - return oFileName - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def getModules(testDir): - modules = [] - for root, dirs, files in os.walk(testDir): - for file in files: - if not file.endswith(".js"): continue - - moduleSource = os.path.relpath(os.path.join(root, file), testDir) - moduleName = os.path.splitext(moduleSource)[0] - modules.append(moduleName) - - return modules - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def getTests(testDir): - tests = [] - for root, dirs, files in os.walk(testDir): - if "program.js" in files: - tests.append(os.path.relpath(root, testDir)) - - return tests - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def run(cmdArgs): - result = subprocess.Popen(cmdArgs, stdout=subprocess.PIPE).communicate()[0] - if not re.match(r"\s*", result): - print result - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def fileContents(iFileName): - iFile = file(iFileName) - contents = iFile.read() - iFile.close() - - return contents - -def getDate(): - return datetime.datetime.today().isoformat(" ") -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def log(message): - print "%s: %s" % (PROGRAM, message) - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -def error(message): - log(message) - exit(1) - -#------------------------------------------------------------------------------- -# -#------------------------------------------------------------------------------- -main() \ No newline at end of file diff --git a/test/commonjs/launcher-in-iframe.template.html b/test/commonjs/launcher-in-iframe.template.html deleted file mode 100644 index 62d5ea8e7..000000000 --- a/test/commonjs/launcher-in-iframe.template.html +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - -@title@ - - - - -

Tests generated on @date@ -


-
-
diff --git a/test/commonjs/launcher-main.template.html b/test/commonjs/launcher-main.template.html
deleted file mode 100644
index 56014c7d5..000000000
--- a/test/commonjs/launcher-main.template.html
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-

Tests generated on @date@ -

- - - diff --git a/test/commonjs/test.css b/test/commonjs/test.css deleted file mode 100644 index 4b118a14e..000000000 --- a/test/commonjs/test.css +++ /dev/null @@ -1,43 +0,0 @@ -/* -# --- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# --- -*/ - -.pass, .fail, .info { - font-family: monospace; - margin-left: 1em; -} - -.pass { - background-color: #DFD; -} - -.fail { - background-color: #F88; -} - -.info { - background-color: #DDF; -} - -.test { - margin-top: 1em; - font-weight: bold; - font-size: 120%; -} diff --git a/test/test.require.js b/test/test.require.js index 63de79990..b66e9abde 100644 --- a/test/test.require.js +++ b/test/test.require.js @@ -154,5 +154,91 @@ describe('require + define', function () { }); expect(require('plugin.ios.foo')).toEqual(4); }); + + // Adapted version of CommonJS test `determinism` + it('Test#013 : does not fall back to relative modules when absolutes are not available', () => { + define('submodule.a', function (require, exports, module) { + expect(() => { + require('a'); + }).toThrow('module a not found'); + }); + + require('submodule.a'); + }); + + // Adapted version of CommonJS test `absolute` + it('Test#014 : correctly handles non-trivial dependecy graphs', () => { + define('submodule/a', function (require, exports, module) { + exports.foo = () => require('b'); + }); + define('b', function (require, exports, module) { + exports.foo = () => {}; + }); + + const a = require('submodule/a'); + const b = require('b'); + expect(a.foo().foo).toBe(b.foo); + }); + + // Adapted version of CommonJS test `transitive` + it('Test#015 : correctly handles transitive dependecies', () => { + define('a', function (require, exports, module) { + exports.foo = require('b').foo; + }); + define('b', function (require, exports, module) { + exports.foo = require('c').foo; + }); + define('c', function (require, exports, module) { + exports.foo = () => 1; + }); + + expect(require('a').foo()).toBe(1); + }); + + // Adapted version of CommonJS test `method` + it('Test#016 : does not bind members of `exports` implicitly', () => { + define('a', function (require, exports, module) { + module.exports = { + foo () { return this; }, + set (x) { this.x = x; }, + get () { return this.x; }, + getClosed () { return module.exports.x; } + }; + }); + + const a = require('a'); + const { foo, getClosed } = a; + + expect(a.foo()).toBe(a); + expect(foo()).toBe((function () { return this; })()); + + a.set(10); + expect(a.get()).toBe(10); + expect(getClosed()).toBe(10); + }); + + // Adapted version of CommonJS test `nested` + it('Test#017 : allows any strings as module names', () => { + define('a/b/c/d', function (require, exports, module) { + exports.foo = () => 1; + }); + define('ラーメン', function (require, exports, module) { + exports.foo = () => 2; + }); + + expect(require('a/b/c/d').foo()).toBe(1); + expect(require('ラーメン').foo()).toBe(2); + }); + + // Adapted version of CommonJS test `hasOwnProperty` + xit('Test#018 : allows properties of Object.prototype as module names', () => { + expect(() => { + define('hasOwnProperty', jasmine.createSpy()); + }).not.toThrow(); + + expect(() => { + define('toString', jasmine.createSpy()); + }).not.toThrow(); + }); }); });