├── .gitignore
├── tests
├── basic_require
│ ├── c
│ │ └── templates
│ │ │ └── first.txt
│ ├── a.js
│ ├── b.js
│ ├── c.js
│ ├── _test.js
│ └── _reporter.js
├── anon_simple
│ ├── a.js
│ ├── sub
│ │ └── c.js
│ ├── b.js
│ ├── _test.js
│ └── _reporter.js
├── config_map
│ ├── c.js
│ ├── c1.js
│ ├── c2.js
│ ├── c
│ │ └── sub.js
│ ├── c1
│ │ └── sub.js
│ ├── c2
│ │ └── sub.js
│ ├── a1.js
│ ├── b.js
│ ├── a1
│ │ └── sub
│ │ │ └── one.js
│ ├── _reporter.js
│ └── _test.js
├── basic_simple
│ ├── a.js
│ ├── sub
│ │ └── c.js
│ ├── b.js
│ ├── _test.js
│ └── _reporter.js
├── config_map_star
│ ├── c.js
│ ├── c1.js
│ ├── c2.js
│ ├── c
│ │ └── sub.js
│ ├── c1
│ │ └── sub.js
│ ├── c2
│ │ └── sub.js
│ ├── another
│ │ ├── c
│ │ │ ├── dim.js
│ │ │ └── sub.js
│ │ ├── minor.js
│ │ └── c.js
│ ├── a1.js
│ ├── b.js
│ ├── a1
│ │ └── sub
│ │ │ └── one.js
│ ├── _reporter.js
│ └── _test.js
├── plugin_normalize
│ ├── a.js
│ ├── c.js
│ ├── prime
│ │ ├── a.js
│ │ ├── c.js
│ │ ├── b.js
│ │ └── earth.js
│ ├── b.js
│ ├── earth.js
│ ├── _test.js
│ ├── _reporter.js
│ ├── index.js
│ └── indexBuilder.js
├── anon_relative
│ ├── util.js
│ ├── impl
│ │ ├── util.js
│ │ └── array.js
│ ├── _test.js
│ └── _reporter.js
├── config_map_star_adapter
│ ├── d.js
│ ├── adapter
│ │ └── d.js
│ ├── e.js
│ ├── _test.js
│ └── _reporter.js
├── config_shim
│ ├── d.js
│ ├── f.js
│ ├── c.js
│ ├── a.js
│ ├── b.js
│ ├── e.js
│ ├── _reporter.js
│ └── _test.js
├── cjs_define
│ ├── four.js
│ ├── five.js
│ ├── one.js
│ ├── three.js
│ ├── two.js
│ ├── _reporter.js
│ └── _test.js
├── cjs_named
│ ├── engine.js
│ ├── wheels.js
│ ├── car.js
│ ├── _test.js
│ └── _reporter.js
├── config_packages
│ ├── pkgs
│ │ ├── alpha
│ │ │ ├── main.js
│ │ │ └── replace.js
│ │ ├── beta
│ │ │ └── 0.2
│ │ │ │ └── scripts
│ │ │ │ ├── util.js
│ │ │ │ └── beta.js
│ │ └── dojox
│ │ │ ├── chair
│ │ │ ├── legs.js
│ │ │ └── main.js
│ │ │ └── table
│ │ │ ├── legs.js
│ │ │ └── table.js
│ ├── dojox
│ │ ├── door.js
│ │ └── window
│ │ │ ├── pane.js
│ │ │ └── window.js
│ ├── baz
│ │ └── lib
│ │ │ ├── helper.js
│ │ │ └── index.js
│ ├── foo
│ │ └── lib
│ │ │ ├── second.js
│ │ │ └── main.js
│ ├── funky
│ │ ├── lib
│ │ │ └── monkey.js
│ │ └── index.js
│ ├── bar
│ │ └── 0.4
│ │ │ └── scripts
│ │ │ └── main.js
│ ├── replace.js
│ ├── _reporter.js
│ └── _test.js
├── config_paths_relative
│ ├── util.js
│ ├── impl
│ │ ├── util.js
│ │ └── array.js
│ ├── _test.js
│ └── _reporter.js
├── config_paths
│ ├── bar.js
│ ├── foo.js
│ ├── bar
│ │ └── sub.js
│ ├── alternate
│ │ └── b.js
│ ├── elsewhere
│ │ └── c.js
│ ├── _test.js
│ └── _reporter.js
├── plugin_fromtext
│ ├── a.refine
│ ├── _test.js
│ ├── _reporter.js
│ └── refine.js
├── plugin_double
│ ├── double.js
│ ├── _reporter.js
│ └── _test.js
├── config_module
│ ├── a.js
│ ├── b
│ │ └── c.js
│ ├── plain.js
│ ├── _test.js
│ └── _reporter.js
├── basic_define
│ ├── _test.js
│ └── _reporter.js
├── plugin_dynamic_string
│ ├── mattress.js
│ ├── _test.js
│ ├── dynamic.js
│ └── _reporter.js
├── anon_circular
│ ├── one.js
│ ├── funcFour.js
│ ├── funcThree.js
│ ├── funcTwo.js
│ ├── funcOne.js
│ ├── two.js
│ ├── _reporter.js
│ └── _test.js
├── basic_circular
│ ├── one.js
│ ├── funcFour.js
│ ├── funcThree.js
│ ├── funcTwo.js
│ ├── two.js
│ ├── funcOne.js
│ ├── _reporter.js
│ └── _test.js
├── plugin_dynamic
│ ├── pillow.js
│ ├── sub
│ │ └── blanket.js
│ ├── dynamic.js
│ ├── _reporter.js
│ └── _test.js
├── basic_empty_deps
│ ├── _test.js
│ └── _reporter.js
└── basic_no_deps
│ ├── _reporter.js
│ └── _test.js
├── .travis.yml
├── impl
├── needs
│ ├── config.js
│ └── needs.js
├── lsjs
│ ├── config.js
│ └── lsjs.js
├── sample.js
├── requirejs
│ └── config.js
├── esl
│ └── config.js
├── zazl
│ ├── config.js
│ └── installer.js
└── inject
│ └── config.js
├── package.json
├── server
├── resources
│ ├── all.css
│ ├── template.html
│ ├── reporter.js
│ ├── all.js
│ └── all.html
├── server_wait.js
├── phantom-server.js
├── manifest.js
├── phantom-runner.js
└── server.js
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/tests/basic_require/c/templates/first.txt:
--------------------------------------------------------------------------------
1 | first
--------------------------------------------------------------------------------
/tests/anon_simple/a.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'a'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map/c.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map/c1.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c1'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map/c2.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c2'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/basic_require/a.js:
--------------------------------------------------------------------------------
1 | define('a', {
2 | name: 'a'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/basic_simple/a.js:
--------------------------------------------------------------------------------
1 | define('a', {
2 | name: 'a'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map/c/sub.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c/sub'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star/c.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star/c1.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c1'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star/c2.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c2'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/a.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'a'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/c.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: "c"
3 | });
4 |
--------------------------------------------------------------------------------
/tests/anon_relative/util.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'util'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map/c1/sub.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c1/sub'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map/c2/sub.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c2/sub'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star/c/sub.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c/sub'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star_adapter/d.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'd'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_shim/d.js:
--------------------------------------------------------------------------------
1 | function D() {
2 | this.name = 'd';
3 | };
4 |
--------------------------------------------------------------------------------
/tests/cjs_define/four.js:
--------------------------------------------------------------------------------
1 | define(function(){
2 | return 'four';
3 | });
4 |
--------------------------------------------------------------------------------
/tests/cjs_named/engine.js:
--------------------------------------------------------------------------------
1 | define('engine', {
2 | name: 'engine'
3 | });
--------------------------------------------------------------------------------
/tests/config_map_star/c1/sub.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c1/sub'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star/c2/sub.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'c2/sub'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/alpha/main.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'alpha'
3 | });
--------------------------------------------------------------------------------
/tests/config_paths_relative/util.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'util'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/prime/a.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'aPrime'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/prime/c.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: "cPrime"
3 | });
4 |
--------------------------------------------------------------------------------
/tests/anon_relative/impl/util.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'impl/util'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/dojox/door.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'dojox/door'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/baz/lib/helper.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: "baz/helper"
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/foo/lib/second.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'foo/second'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/funky/lib/monkey.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'monkey'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_paths_relative/impl/util.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'impl/util'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_shim/f.js:
--------------------------------------------------------------------------------
1 | var FCAP = {
2 | name: 'FCAP',
3 | globalA: A
4 | };
5 |
--------------------------------------------------------------------------------
/tests/config_map_star/another/c/dim.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'another/c/dim'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_shim/c.js:
--------------------------------------------------------------------------------
1 | var C = {
2 | name: 'c',
3 | a: A,
4 | b: B
5 | };
6 |
--------------------------------------------------------------------------------
/tests/config_map_star/another/minor.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'another/minor'
3 | });
4 |
5 |
--------------------------------------------------------------------------------
/tests/config_packages/dojox/window/pane.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'dojox/window/pane'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/alpha/replace.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'alpha/replace'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/beta/0.2/scripts/util.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'beta/util'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/dojox/chair/legs.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'dojox/chair/legs'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/dojox/table/legs.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'dojox/table/legs'
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/beta/0.2/scripts/beta.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return 'beta';
3 | });
4 |
--------------------------------------------------------------------------------
/tests/anon_simple/sub/c.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: 'c'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_packages/bar/0.4/scripts/main.js:
--------------------------------------------------------------------------------
1 | define({
2 | name: 'bar',
3 | version: '0.4'
4 | });
5 |
--------------------------------------------------------------------------------
/tests/config_paths/bar.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: 'bar'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_paths/foo.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: 'foo'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_shim/a.js:
--------------------------------------------------------------------------------
1 | (function (root) {
2 | root.A = {
3 | name: 'a'
4 | };
5 | }(this));
6 |
--------------------------------------------------------------------------------
/tests/config_shim/b.js:
--------------------------------------------------------------------------------
1 | var B = {
2 | name: 'b',
3 | aValue: A.name,
4 | dValue: new D()
5 | };
6 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/b.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: "b"
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/basic_require/b.js:
--------------------------------------------------------------------------------
1 | define('b', [], function () {
2 | return {
3 | name: 'b'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_paths/bar/sub.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: 'barSub'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/basic_simple/sub/c.js:
--------------------------------------------------------------------------------
1 | define('sub/c', function () {
2 | return {
3 | name: 'c'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/cjs_define/five.js:
--------------------------------------------------------------------------------
1 | define(function(){
2 | return function () {
3 | return 'five';
4 | }
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_paths/alternate/b.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: 'fooB'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_paths/elsewhere/c.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: 'fooC'
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/prime/b.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return {
3 | name: "bPrime"
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/cjs_named/wheels.js:
--------------------------------------------------------------------------------
1 | define('wheels', function (require, exports, module) {
2 | exports.name = 'wheels';
3 | });
4 |
--------------------------------------------------------------------------------
/tests/config_map_star_adapter/adapter/d.js:
--------------------------------------------------------------------------------
1 | define(['d'], function(d) {
2 | d.adapted = true;
3 | return d;
4 | });
5 |
--------------------------------------------------------------------------------
/tests/config_shim/e.js:
--------------------------------------------------------------------------------
1 | var e = {
2 | nested: {
3 | e: {
4 | name: 'e'
5 | }
6 | }
7 | };
8 |
--------------------------------------------------------------------------------
/tests/plugin_fromtext/a.refine:
--------------------------------------------------------------------------------
1 | //The refine plugin changes the word refine into define.
2 | refine({
3 | name: 'a'
4 | });
5 |
--------------------------------------------------------------------------------
/tests/plugin_double/double.js:
--------------------------------------------------------------------------------
1 | define({
2 | load: function (name, req, load, config) {
3 | load('x');
4 | }
5 | });
6 |
--------------------------------------------------------------------------------
/tests/config_map_star_adapter/e.js:
--------------------------------------------------------------------------------
1 | define(['d'], function (d) {
2 | return {
3 | name: 'e',
4 | d: d
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_module/a.js:
--------------------------------------------------------------------------------
1 | define(['module'], function (module) {
2 | return {
3 | type: module.config().id
4 | };
5 | });
6 |
--------------------------------------------------------------------------------
/tests/anon_simple/b.js:
--------------------------------------------------------------------------------
1 | define(['sub/c'], function (c) {
2 | return {
3 | name: 'b',
4 | cName: c.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_map/a1.js:
--------------------------------------------------------------------------------
1 | define(['c', 'c/sub'], function (c, csub) {
2 | return {
3 | c: c,
4 | csub: csub
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_map/b.js:
--------------------------------------------------------------------------------
1 | define(['c', 'c/sub'], function (c, csub) {
2 | return {
3 | c: c,
4 | csub: csub
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/basic_simple/b.js:
--------------------------------------------------------------------------------
1 | define('b', ['sub/c'], function (c) {
2 | return {
3 | name: 'b',
4 | cName: c.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_map_star/a1.js:
--------------------------------------------------------------------------------
1 | define(['c', 'c/sub'], function (c, csub) {
2 | return {
3 | c: c,
4 | csub: csub
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_map_star/b.js:
--------------------------------------------------------------------------------
1 | define(['c', 'c/sub'], function (c, csub) {
2 | return {
3 | c: c,
4 | csub: csub
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_module/b/c.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | return {
3 | food: module.config().id
4 | };
5 | });
6 |
7 |
--------------------------------------------------------------------------------
/tests/config_map/a1/sub/one.js:
--------------------------------------------------------------------------------
1 | define(['c', 'c/sub'], function (c, csub) {
2 | return {
3 | c: c,
4 | csub: csub
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_packages/replace.js:
--------------------------------------------------------------------------------
1 | //Tests overriding a package path with a more specific mapping.
2 | define({
3 | name: 'fake/alpha/replace'
4 | });
5 |
--------------------------------------------------------------------------------
/tests/config_map_star/a1/sub/one.js:
--------------------------------------------------------------------------------
1 | define(['c', 'c/sub'], function (c, csub) {
2 | return {
3 | c: c,
4 | csub: csub
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_packages/foo/lib/main.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports) {
2 | exports.name = 'foo';
3 | exports.alphaName = require('alpha').name;
4 | });
5 |
--------------------------------------------------------------------------------
/tests/config_map_star/another/c.js:
--------------------------------------------------------------------------------
1 | define(['./minor'], function (minor) {
2 | return {
3 | name: 'another/c',
4 | minorName: minor.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_map_star/another/c/sub.js:
--------------------------------------------------------------------------------
1 | define(['./dim'], function (dim) {
2 | return {
3 | name: 'another/c/sub',
4 | dimName: dim.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_paths_relative/impl/array.js:
--------------------------------------------------------------------------------
1 | define(['./util'], function (util) {
2 | return {
3 | name: 'impl/array',
4 | utilName: util.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_packages/dojox/window/window.js:
--------------------------------------------------------------------------------
1 | define(['./pane'], function (pane) {
2 | return {
3 | name: 'dojox/window',
4 | paneName: pane.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_packages/funky/index.js:
--------------------------------------------------------------------------------
1 | define(['./lib/monkey'], function (monkey) {
2 | return {
3 | name: 'funky',
4 | monkeyName: monkey.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/dojox/chair/main.js:
--------------------------------------------------------------------------------
1 | define(['./legs'], function (legs) {
2 | return {
3 | name: 'dojox/chair',
4 | legsName: legs.name
5 | }
6 | });
7 |
--------------------------------------------------------------------------------
/tests/basic_require/c.js:
--------------------------------------------------------------------------------
1 | define('c', ['require'], function (require) {
2 | return {
3 | name: 'c',
4 | url: require.toUrl('./c/templates/first.txt')
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/config_packages/pkgs/dojox/table/table.js:
--------------------------------------------------------------------------------
1 | define(['dojox/chair'], function (chair) {
2 | return {
3 | name: 'dojox/table',
4 | chairName: chair.name
5 | };
6 | });
7 |
--------------------------------------------------------------------------------
/tests/cjs_named/car.js:
--------------------------------------------------------------------------------
1 | define('car', function (require) {
2 | return {
3 | name: 'car',
4 | wheels: require('wheels'),
5 | engine: require('engine')
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/tests/plugin_fromtext/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "refine!a"],
2 | function (amdJS, a) {
3 | amdJS.assert('a' === a.name, 'plugin_fromtext: a.name');
4 | amdJS.print('DONE', 'done');
5 | });
6 |
--------------------------------------------------------------------------------
/tests/basic_define/_test.js:
--------------------------------------------------------------------------------
1 | go(["_reporter", "require"], function(amdJS, require) {
2 |
3 | amdJS.assert(typeof define.amd === 'object', 'basic_define: define.amd is object');
4 | amdJS.print('DONE', 'done');
5 |
6 | });
--------------------------------------------------------------------------------
/tests/config_module/plain.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | return {
3 | //no config, just should get an empty object.
4 | id: 'plain' + (module.config().foo || '')
5 | }
6 | });
7 |
--------------------------------------------------------------------------------
/tests/anon_relative/impl/array.js:
--------------------------------------------------------------------------------
1 | define(['./util', 'util'], function (dotUtil, util) {
2 | return {
3 | name: 'impl/array',
4 | dotUtilName: dotUtil.name,
5 | utilName: util.name
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/tests/cjs_define/one.js:
--------------------------------------------------------------------------------
1 | define(function(require, exports, module) {
2 | exports.size = "large";
3 | exports.module = module;
4 | exports.doSomething = function() {
5 | return require("two");
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/tests/plugin_dynamic_string/mattress.js:
--------------------------------------------------------------------------------
1 |
2 | define(function (require) {
3 | return {
4 | id1: require('dynamic!medium'),
5 | id2: require('dynamic!medium'),
6 | name: 'mattress'
7 | };
8 | });
9 |
--------------------------------------------------------------------------------
/tests/cjs_define/three.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports) {
2 | var four = require('four'),
3 | five = require('five');
4 |
5 | exports.name = 'three';
6 | exports.fourName = four;
7 | exports.fiveName = five();
8 | });
9 |
--------------------------------------------------------------------------------
/tests/anon_circular/one.js:
--------------------------------------------------------------------------------
1 | define(["require", "exports", "module", "two"], function(require, exports, module) {
2 | exports.size = "large";
3 | exports.module = module;
4 | exports.doSomething = function() {
5 | return require("two");
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/tests/config_packages/baz/lib/index.js:
--------------------------------------------------------------------------------
1 | define(['bar', 'foo', './helper'], function (bar, foo, helper) {
2 | return {
3 | name: 'baz',
4 | barDepVersion: bar.version,
5 | fooName: foo.name,
6 | helperName: helper.name
7 | };
8 | });
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 0.8
4 | before_install:
5 | - git submodule update --init --recursive
6 | before_script:
7 | - npm install
8 | - node server/server.js &
9 | script: node ./server/server_wait.js && node ./server/phantom-server.js
10 |
--------------------------------------------------------------------------------
/tests/basic_circular/one.js:
--------------------------------------------------------------------------------
1 | define("one", ["require", "exports", "module", "two"], function(require, exports, module) {
2 | exports.size = "large";
3 | exports.module = module;
4 | exports.doSomething = function() {
5 | return require("two");
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/tests/plugin_dynamic/pillow.js:
--------------------------------------------------------------------------------
1 | define(['require', 'dynamic!./pillow.resource'], function (require, resource) {
2 | return {
3 | resource: resource,
4 | delayed: function (cb) {
5 | require(['dynamic!./pillow.resource'], cb);
6 | }
7 | };
8 | });
9 |
--------------------------------------------------------------------------------
/impl/needs/config.js:
--------------------------------------------------------------------------------
1 | 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 | };
12 |
13 | require = undefined;
--------------------------------------------------------------------------------
/tests/plugin_dynamic/sub/blanket.js:
--------------------------------------------------------------------------------
1 | define([ 'require', 'dynamic!../pillow.resource', 'dynamic!./blanket.resource'],
2 | function (require, pillowResource, blanketResource) {
3 | return {
4 | resource: blanketResource,
5 | pillowResource: pillowResource
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/tests/anon_simple/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "a", "b"],
2 | function (amdJS, a, b) {
3 | amdJS.assert("a" === a.name, "anon_simple: a.name");
4 | amdJS.assert("b" === b.name, "anon_simple: b.name");
5 | amdJS.assert("c" === b.cName, "anon_simple: c.name via b");
6 | amdJS.print("DONE", "done");
7 | });
8 |
--------------------------------------------------------------------------------
/tests/anon_circular/funcFour.js:
--------------------------------------------------------------------------------
1 | define(["require", "funcThree"], function (require) {
2 | var four = function (arg) {
3 | return "FOUR called with " + arg;
4 | };
5 |
6 | four.suffix = function () {
7 | return require("funcThree").suffix();
8 | };
9 |
10 | return four;
11 | });
12 |
--------------------------------------------------------------------------------
/tests/basic_simple/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "a", "b"],
2 | function (amdJS, a, b) {
3 | amdJS.assert('a' === a.name, 'basic_simple: a.name');
4 | amdJS.assert('b' === b.name, 'basic_simple: b.name');
5 | amdJS.assert('c' === b.cName, 'basic_simple: c.name via b');
6 | amdJS.print('DONE', 'done');
7 | });
8 |
--------------------------------------------------------------------------------
/tests/anon_circular/funcThree.js:
--------------------------------------------------------------------------------
1 | define(["require", "funcFour"], function (require, four) {
2 | var three = function (arg) {
3 | return arg + "-" + require("funcFour").suffix();
4 | };
5 |
6 | three.suffix = function () {
7 | return "THREE_SUFFIX";
8 | };
9 |
10 | return three;
11 | });
12 |
--------------------------------------------------------------------------------
/tests/basic_circular/funcFour.js:
--------------------------------------------------------------------------------
1 | define("funcFour", ["require", "funcThree"], function (require) {
2 | var four = function (arg) {
3 | return "FOUR called with " + arg;
4 | };
5 |
6 | four.suffix = function () {
7 | return require("funcThree").suffix();
8 | };
9 |
10 | return four;
11 | });
12 |
--------------------------------------------------------------------------------
/tests/basic_circular/funcThree.js:
--------------------------------------------------------------------------------
1 | define("funcThree", ["require", "funcFour"], function (require, four) {
2 | var three = function (arg) {
3 | return arg + "-" + require("funcFour").suffix();
4 | };
5 |
6 | three.suffix = function () {
7 | return "THREE_SUFFIX";
8 | };
9 |
10 | return three;
11 | });
12 |
--------------------------------------------------------------------------------
/tests/cjs_named/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "car"],
2 | function (amdJS, car) {
3 | amdJS.assert('car' === car.name, 'cjs_named: car.name');
4 | amdJS.assert('wheels' === car.wheels.name, 'cjs_named: car.wheels.name');
5 | amdJS.assert('engine' === car.engine.name, 'cjs_named: car.engine.name');
6 | amdJS.print('DONE', 'done');
7 | });
8 |
--------------------------------------------------------------------------------
/tests/anon_circular/funcTwo.js:
--------------------------------------------------------------------------------
1 | define(["require", "funcOne"], function (require) {
2 | var two = function (name) {
3 | this.name = name;
4 | this.one = new (require("funcOne"))("ONE");
5 | };
6 |
7 | two.prototype.oneName = function () {
8 | return this.one.getName();
9 | };
10 |
11 | return two;
12 | });
13 |
--------------------------------------------------------------------------------
/tests/anon_circular/funcOne.js:
--------------------------------------------------------------------------------
1 | define(["require", "funcTwo"], function (require) {
2 | var one = function (name) {
3 | this.name = name;
4 | };
5 |
6 | one.prototype.getName = function () {
7 | var inst = new (require("funcTwo"))("-NESTED");
8 | return this.name + inst.name;
9 | };
10 |
11 | return one;
12 | });
13 |
--------------------------------------------------------------------------------
/tests/anon_circular/two.js:
--------------------------------------------------------------------------------
1 | define(["require", "one"], function(require, one) {
2 | return {
3 | size: "small",
4 | color: "redtwo",
5 | doSomething: function() {
6 | return one.doSomething();
7 | },
8 | getOneModule: function() {
9 | return one.module;
10 | }
11 | };
12 | });
13 |
--------------------------------------------------------------------------------
/tests/basic_circular/funcTwo.js:
--------------------------------------------------------------------------------
1 | define("funcTwo", ["require", "funcOne"], function (require) {
2 | var two = function (name) {
3 | this.name = name;
4 | this.one = new (require("funcOne"))("ONE");
5 | };
6 |
7 | two.prototype.oneName = function () {
8 | return this.one.getName();
9 | };
10 |
11 | return two;
12 | });
13 |
--------------------------------------------------------------------------------
/tests/basic_circular/two.js:
--------------------------------------------------------------------------------
1 | define("two", ["require", "one"], function(require, one) {
2 | return {
3 | size: "small",
4 | color: "redtwo",
5 | doSomething: function() {
6 | return one.doSomething();
7 | },
8 | getOneModule: function() {
9 | return one.module;
10 | }
11 | };
12 | });
13 |
--------------------------------------------------------------------------------
/tests/basic_circular/funcOne.js:
--------------------------------------------------------------------------------
1 | define("funcOne", ["require", "funcTwo"], function (require) {
2 | var one = function (name) {
3 | this.name = name;
4 | };
5 |
6 | one.prototype.getName = function () {
7 | var inst = new (require("funcTwo"))("-NESTED");
8 | return this.name + inst.name;
9 | };
10 |
11 | return one;
12 | });
13 |
--------------------------------------------------------------------------------
/tests/cjs_define/two.js:
--------------------------------------------------------------------------------
1 | define(function(require) {
2 | //Dependencies
3 | var one = require('one');
4 | return {
5 | size: "small",
6 | color: "redtwo",
7 | doSomething: function() {
8 | return one.doSomething();
9 | },
10 | getOneModule: function() {
11 | return one.module;
12 | }
13 | };
14 | });
15 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/earth.js:
--------------------------------------------------------------------------------
1 | define(function (require) {
2 | return {
3 | getA: function () {
4 | return require("./index!0?./a:./b:./c");
5 | },
6 | getC: function () {
7 | return require("./index!2?./a:./b:./c");
8 | },
9 | getB: function () {
10 | return require("./index!1?./a:./b:./c");
11 | }
12 | };
13 | });
14 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/prime/earth.js:
--------------------------------------------------------------------------------
1 | define(function (require) {
2 | return {
3 | getA: function () {
4 | return require("../index!0?./a:./b:./c");
5 | },
6 | getC: function () {
7 | return require("../index!2?./a:./b:./c");
8 | },
9 | getB: function () {
10 | return require("../index!1?./a:./b:./c");
11 | }
12 | };
13 | });
14 |
--------------------------------------------------------------------------------
/tests/config_paths_relative/_test.js:
--------------------------------------------------------------------------------
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 | });
13 |
--------------------------------------------------------------------------------
/tests/anon_relative/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "require", "impl/array"],
2 | function (amdJS, require, array) {
3 | amdJS.assert('impl/array' === array.name, 'anon_relative: array.name');
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');
6 | amdJS.print('DONE', 'done');
7 | });
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "amdjs_test_server",
3 | "version": "0.0.1",
4 | "description": "A standalone test server for running generic AMD tests",
5 | "author": "AMD JS",
6 | "private": true,
7 | "implements": [
8 | "https://github.com/amdjs/amdjs-api/wiki/AMD"
9 | ],
10 | "devDependencies": {
11 | "express": "3.0.0",
12 | "npm": ">=1.2.16"
13 | },
14 | "dependencies": {},
15 | "engine": "node >= 0.6.0"
16 | }
--------------------------------------------------------------------------------
/tests/basic_require/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "require", "a"],
2 | function (amdJS, require) {
3 | require(['b', 'c'],
4 | function (b, c) {
5 | amdJS.assert('a' === require('a').name, 'basic_require: require a.name');
6 | amdJS.assert('b' === b.name, 'basic_require: b.name');
7 | amdJS.assert('c' === c.name, 'basic_require: c.name');
8 | amdJS.assert(/c\/templates\/first\.txt$/.test(c.url), 'basic_require: c.url property');
9 | amdJS.print('DONE', 'done');
10 | });
11 | });
12 |
--------------------------------------------------------------------------------
/server/resources/all.css:
--------------------------------------------------------------------------------
1 | #run-tests, .or {
2 | display: none;
3 | }
4 | .has-tests #run-tests, .has-tests .or {
5 | display: inline;
6 | }
7 | li {
8 | clear: both;
9 | list-style-type: none;
10 | }
11 | iframe {
12 | width: 1em;
13 | height: 1em;
14 | display: block;
15 | float: left;
16 | margin-right: 10px;
17 | border: 0;
18 | }
19 | .skipped {
20 | width: 1em;
21 | height: 1em;
22 | background: #ccc;
23 | display: block;
24 | float: left;
25 | margin-right: 10px;
26 | border: 0;
27 | }
--------------------------------------------------------------------------------
/server/resources/template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{TEST_NAME}}
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/server/server_wait.js:
--------------------------------------------------------------------------------
1 | var http = require('http');
2 |
3 | var waitForServer = function() {
4 | console.log("Waiting for amdjs-tests server to start");
5 | var req = http.request("http://localhost:4000/", function(res) {
6 | if (res.statusCode === 200) {
7 | console.log("amdjs-tests server has started");
8 | process.exit();
9 | } else {
10 | setTimeout(waitForServer, 1000);
11 | }
12 | });
13 | req.on('error', function(e) {
14 | setTimeout(waitForServer, 1000);
15 | });
16 | req.end();
17 | }
18 |
19 | waitForServer();
--------------------------------------------------------------------------------
/tests/plugin_dynamic_string/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "mattress"],
2 | function (amdJS, mattress) {
3 | //Make sure the resource names do not match for the
4 | //three kinds of pillow-related resources.
5 | amdJS.assert('mattress' === mattress.name, 'plugin_dynamic_string: mattress.name is unique');
6 | amdJS.assert('1:medium' === mattress.id1, 'plugin_dynamic_string: mattress.id1 is unique');
7 | amdJS.assert('2:medium' === mattress.id2, 'plugin_dynamic_string: mattress.id2 is unique');
8 | amdJS.print('DONE', 'done');
9 | });
10 |
--------------------------------------------------------------------------------
/tests/basic_empty_deps/_test.js:
--------------------------------------------------------------------------------
1 | go(["_reporter", "require"], function(amdJS, require) {
2 |
3 | // tests if there are empty dependencies, no arguments are
4 | // available in the factory's method
5 | define('emptyDeps', [], function() {
6 | amdJS.assert(arguments.length === 0, 'basic_empty_deps: [] should be treated as no dependencies instead of the default require, exports, module');
7 | });
8 |
9 | window.setTimeout(function() {
10 | require(['emptyDeps'], function () {
11 | amdJS.print('DONE', 'done');
12 | });
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/tests/config_module/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: './',
3 | config: {
4 | a: {
5 | id: 'magic'
6 | },
7 | 'b/c': {
8 | id: 'beans'
9 | }
10 | }
11 | });
12 |
13 | go( ["_reporter", "a", "b/c", "plain"],
14 | function (amdJS, a, c, plain) {
15 | amdJS.assert('magic' === a.type, 'config_module: a.type is magic');
16 | amdJS.assert('beans' === c.food, 'config_module: c.food is beans');
17 | amdJS.assert('plain' === plain.id, 'config_module: module.id is defined');
18 | amdJS.print('DONE', 'done');
19 | });
20 |
--------------------------------------------------------------------------------
/tests/plugin_dynamic/dynamic.js:
--------------------------------------------------------------------------------
1 |
2 | /*jslint strict: false */
3 | /*global define: false */
4 |
5 | (function () {
6 | var counter = 0;
7 | define(function () {
8 | //Depends on loader to normalize relative resource names, so it
9 | //does not implement normalize().
10 | return {
11 | dynamic: true,
12 |
13 | load: function (name, require, load, config) {
14 | counter += 1;
15 | load(counter + ':' + name);
16 | }
17 | };
18 | });
19 |
20 | }());
21 |
--------------------------------------------------------------------------------
/tests/plugin_dynamic_string/dynamic.js:
--------------------------------------------------------------------------------
1 |
2 | /*jslint strict: false */
3 | /*global define: false */
4 |
5 | (function () {
6 | var counter = 0;
7 | define(function () {
8 | //Depends on loader to normalize relative resource names, so it
9 | //does not implement normalize().
10 | return {
11 | dynamic: true,
12 |
13 | load: function (name, require, load, config) {
14 | counter += 1;
15 | load(counter + ':' + name);
16 | }
17 | };
18 | });
19 |
20 | }());
21 |
--------------------------------------------------------------------------------
/impl/lsjs/config.js:
--------------------------------------------------------------------------------
1 | /*
2 | Note: When running the tests for the lsjs loader make sure localStorage has been
3 | cleared for the first run to ensure the latest version of the tests are executed.
4 | Either clear the browser cookies or programatically run localStorage.clear();
5 | */
6 |
7 | // localstorage is programatically cleared
8 | localStorage.clear();
9 | var config = lsjs,
10 | go = lsjs,
11 | implemented = {
12 | basic: true,
13 | anon: true,
14 | funcString: true,
15 | namedWrapped: true,
16 | require: true,
17 | plugins: true
18 | //pluginDynamic: true
19 | };
20 | require = undefined;
21 |
--------------------------------------------------------------------------------
/tests/config_paths/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: '.',
3 | paths: {
4 | 'foo/b': 'alternate/b',
5 | 'foo/b/c': 'elsewhere/c'
6 | }
7 | });
8 |
9 | go( ["_reporter", "foo", "foo/b", "foo/b/c", "bar", "bar/sub"],
10 | function (amdJS, foo, fooB, fooC, bar, barSub) {
11 | amdJS.assert('foo' === foo.name, 'config_paths: foo.name');
12 | amdJS.assert('fooB' === fooB.name, 'config_paths: fooB.name');
13 | amdJS.assert('fooC' === fooC.name, 'config_paths: fooC.name');
14 | amdJS.assert('bar' === bar.name, 'config_paths: bar.name');
15 | amdJS.assert('barSub' === barSub.name, 'config_paths: barSub.name');
16 | amdJS.print('DONE', 'done');
17 | });
18 |
--------------------------------------------------------------------------------
/tests/config_map_star_adapter/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: './',
3 | map: {
4 | '*': {
5 | 'd': 'adapter/d'
6 | },
7 | 'adapter/d': {
8 | d: 'd'
9 | }
10 | }
11 | });
12 |
13 | go( ["_reporter", "e", "adapter/d"],
14 | function (amdJS, e, adapterD) {
15 | 'use strict';
16 | amdJS.assert('e' === e.name, 'config_map_star_adapter: e.name');
17 | amdJS.assert('d' === e.d.name, 'config_map_star_adapter: e.d.name');
18 | amdJS.assert(e.d.adapted, 'config_map_star_adapter: e.d.adapted');
19 | amdJS.assert(adapterD.adapted, 'config_map_star_adapter: adapterD.adapted');
20 | amdJS.assert('d' === adapterD.name, 'config_map_star_adapter: adapterD.name');
21 | amdJS.print('DONE', 'done');
22 | });
23 |
--------------------------------------------------------------------------------
/impl/sample.js:
--------------------------------------------------------------------------------
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 | };
--------------------------------------------------------------------------------
/tests/plugin_normalize/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "require", "earth", "prime/earth"],
2 | function (amdJS, require, earth, primeEarth) {
3 | amdJS.assert('a' === earth.getA().name, 'plugin_normalize: earth.getA().name');
4 | amdJS.assert('c' === earth.getC().name, 'plugin_normalize: earth.getC().name');
5 | amdJS.assert('b' === earth.getB().name, 'plugin_normalize: earth.getB().name');
6 | amdJS.assert('aPrime' === primeEarth.getA().name, 'plugin_normalize: primeEarth.getA().name is aPrime, not a');
7 | amdJS.assert('cPrime' === primeEarth.getC().name, 'plugin_normalize: primeEarth.getC().name is cPrime, not c');
8 | amdJS.assert('bPrime' === primeEarth.getB().name, 'plugin_normalize: primeEarth.getB().name is bPrime, not b');
9 | amdJS.print('DONE', 'done');
10 | });
11 |
--------------------------------------------------------------------------------
/tests/anon_simple/_reporter.js:
--------------------------------------------------------------------------------
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_define/_reporter.js:
--------------------------------------------------------------------------------
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_simple/_reporter.js:
--------------------------------------------------------------------------------
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/cjs_define/_reporter.js:
--------------------------------------------------------------------------------
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/cjs_named/_reporter.js:
--------------------------------------------------------------------------------
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_map/_reporter.js:
--------------------------------------------------------------------------------
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/_reporter.js:
--------------------------------------------------------------------------------
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_shim/_reporter.js:
--------------------------------------------------------------------------------
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/anon_circular/_reporter.js:
--------------------------------------------------------------------------------
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/anon_relative/_reporter.js:
--------------------------------------------------------------------------------
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_circular/_reporter.js:
--------------------------------------------------------------------------------
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/_reporter.js:
--------------------------------------------------------------------------------
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_no_deps/_reporter.js:
--------------------------------------------------------------------------------
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_require/_reporter.js:
--------------------------------------------------------------------------------
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_map_star/_reporter.js:
--------------------------------------------------------------------------------
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_module/_reporter.js:
--------------------------------------------------------------------------------
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_packages/_reporter.js:
--------------------------------------------------------------------------------
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/plugin_double/_reporter.js:
--------------------------------------------------------------------------------
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/plugin_dynamic/_reporter.js:
--------------------------------------------------------------------------------
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/plugin_fromtext/_reporter.js:
--------------------------------------------------------------------------------
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/plugin_normalize/_reporter.js:
--------------------------------------------------------------------------------
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_no_deps/_test.js:
--------------------------------------------------------------------------------
1 | go(["_reporter", "require"], function(amdJS, require) {
2 |
3 | // tests if there are NO dependencies, the default
4 | // values of "require, exports, module" are used
5 | define('noDeps', function(require, exports, module) {
6 | amdJS.assert(typeof(require) === 'function', 'basic_no_deps: no dependencies case uses require in first slot. Is a function');
7 | amdJS.assert(typeof(exports) === 'object', 'basic_no_deps: no dependencies case uses exports in second slot. Is an object.');
8 | amdJS.assert(typeof(module) === 'object', 'basic_no_deps: no dependencies case uses module in third slot. Is an object.');
9 | });
10 |
11 | window.setTimeout(function() {
12 | require(['noDeps'], function () {
13 | amdJS.print('DONE', 'done');
14 | });
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/tests/config_paths_relative/_reporter.js:
--------------------------------------------------------------------------------
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/plugin_double/_test.js:
--------------------------------------------------------------------------------
1 | go(["_reporter", "require"], function(amdJS, require) {
2 | var count = 0;
3 | var timeout = 10000;
4 |
5 | var timer = window.setTimeout(function() {
6 | amdJS.assert(false, 'plugin_double: test timed out');
7 | amdJS.print('DONE', 'done');
8 | }, timeout);
9 |
10 | var done = function() {
11 | count++;
12 | if (count === 2) {
13 | window.clearTimeout(timer);
14 | amdJS.assert(true, 'plugin_double: double plugin called okay');
15 | amdJS.print('DONE', 'done');
16 | }
17 | };
18 |
19 | require(['double!foo'],
20 | function (foo) {
21 | if (foo === 'x') {
22 | done();
23 | }
24 | });
25 |
26 | require(['double!foo'],
27 | function (foo) {
28 | if (foo === 'x') {
29 | done();
30 | }
31 | });
32 |
33 | });
--------------------------------------------------------------------------------
/tests/plugin_dynamic_string/_reporter.js:
--------------------------------------------------------------------------------
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/cjs_define/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "one", "two", "three"],
2 | function (amdJS, one, two, three) {
3 | var args = two.doSomething(),
4 | oneMod = two.getOneModule();
5 |
6 | amdJS.assert('large' === one.size, 'cjs_define: one.size');
7 | amdJS.assert('small' === two.size, 'cjs_define: two.size');
8 | amdJS.assert('small' === args.size, 'cjs_define: args.size');
9 | amdJS.assert('redtwo' === args.color, 'cjs_define: args.color');
10 | amdJS.assert('one' === oneMod.id, 'cjs_define: module.id property support');
11 | amdJS.assert('three' === three.name, 'cjs_define: three.name');
12 | amdJS.assert('four' === three.fourName, 'cjs_define: four.name via three');
13 | amdJS.assert('five' === three.fiveName, 'cjs_define: five.name via four');
14 | amdJS.print('DONE', 'done');
15 | });
16 |
--------------------------------------------------------------------------------
/tests/config_map_star_adapter/_reporter.js:
--------------------------------------------------------------------------------
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/anon_circular/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "require", "two", "funcTwo", "funcThree"],
2 | function (amdJS, require, two, funcTwo, funcThree) {
3 | var args = two.doSomething(),
4 | twoInst = new funcTwo("TWO"),
5 | oneMod = two.getOneModule();
6 | amdJS.assert('small' === args.size, 'anon_circular: args.size');
7 | amdJS.assert('redtwo' === args.color, 'anon_circular: args.color');
8 | amdJS.assert('one' === oneMod.id, 'anon_circular: module.id property supported');
9 | amdJS.assert('TWO' === twoInst.name, 'anon_circular: instantiated objects');
10 | amdJS.assert('ONE-NESTED' === twoInst.oneName(), 'anon_circular: nested objects');
11 | amdJS.assert('THREE-THREE_SUFFIX' === funcThree('THREE'), 'anon_circular: resolved circular references');
12 | amdJS.print('DONE', 'done');
13 | });
14 |
--------------------------------------------------------------------------------
/tests/basic_circular/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "require", "two", "funcTwo", "funcThree"],
2 | function (amdJS, require, two, funcTwo, funcThree) {
3 | var args = two.doSomething(),
4 | twoInst = new funcTwo("TWO"),
5 | oneMod = two.getOneModule();
6 |
7 | amdJS.assert('small' === args.size, 'basic_circular: args.size');
8 | amdJS.assert('redtwo' === args.color, 'basic_circular: args.color');
9 | amdJS.assert('one' === oneMod.id, 'basic_circular: module.id property supported');
10 | amdJS.assert('TWO' === twoInst.name, 'basic_circular: instantiated objects');
11 | amdJS.assert('ONE-NESTED' === twoInst.oneName(), 'basic_circular: nested objects');
12 | amdJS.assert('THREE-THREE_SUFFIX' === funcThree('THREE'), 'basic_circular: resolved circular references');
13 | amdJS.print('DONE', 'done');
14 | });
15 |
--------------------------------------------------------------------------------
/tests/config_map/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: './',
3 | paths: {
4 | a: 'a1'
5 | },
6 | map: {
7 | 'a': {
8 | c: 'c1'
9 | },
10 | 'a/sub/one': {
11 | 'c': 'c2'
12 | }
13 | }
14 | });
15 |
16 | go( ["_reporter", "a", "b", "c", "a/sub/one"],
17 | function (amdJS, a, b, c, one) {
18 | amdJS.assert('c1' === a.c.name, 'config_map: a.c.name');
19 | amdJS.assert('c1/sub' === a.csub.name, 'config_map: a.csub.name');
20 | amdJS.assert('c2' === one.c.name, 'config_map: one.c.name');
21 | amdJS.assert('c2/sub' === one.csub.name, 'config_map: one.csub.name');
22 | amdJS.assert('c' === b.c.name, 'config_map: b.c.name');
23 | amdJS.assert('c/sub', b.csub.name, 'config_map: b.csub.name');
24 | amdJS.assert('c' === c.name, 'config_map: c.name');
25 | amdJS.print('DONE', 'done');
26 | });
27 |
--------------------------------------------------------------------------------
/impl/requirejs/config.js:
--------------------------------------------------------------------------------
1 |
2 | //Map the configure({}) call to loader-specific call.
3 | var config = require,
4 |
5 | //Map the top-level entry point to start loading to loader-specific call.
6 | go = require,
7 |
8 | //Indicate what levels of the API are implemented by this loader,
9 | //and therefore which tests to run.
10 | implemented = {
11 | basic: true,
12 | anon: true,
13 | funcString: true,
14 | namedWrapped: true,
15 | require: true,
16 | plugins: true,
17 | pathsConfig: true,
18 | packagesConfig: true,
19 | mapConfig: true,
20 | moduleConfig: true,
21 | shimConfig: true
22 | //Does NOT support pluginDynamic in 1.0
23 | //pluginDynamic: true
24 | };
25 |
26 | //Remove the global require, to make sure a global require is not assumed
27 | //in the tests
28 | require = undefined;
29 |
--------------------------------------------------------------------------------
/impl/esl/config.js:
--------------------------------------------------------------------------------
1 |
2 | //Map the configure({}) call to loader-specific call.
3 | var config = require.config,
4 |
5 | //Map the top-level entry point to start loading to loader-specific call.
6 | go = require,
7 |
8 | //Indicate what levels of the API are implemented by this loader,
9 | //and therefore which tests to run.
10 | implemented = {
11 | basic: true,
12 | anon: true,
13 | funcString: true,
14 | namedWrapped: true,
15 | require: true,
16 | plugins: true,
17 | pathsConfig: true,
18 | packagesConfig: true,
19 | mapConfig: true,
20 | moduleConfig: true,
21 | //shimConfig: true
22 | //Does NOT support pluginDynamic in 1.0
23 | //pluginDynamic: true
24 | };
25 |
26 | //Remove the global require, to make sure a global require is not assumed
27 | //in the tests
28 | require = undefined;
29 |
--------------------------------------------------------------------------------
/server/phantom-server.js:
--------------------------------------------------------------------------------
1 | var manifest = require('./manifest');
2 | var remaining = 0;
3 | var failures = 0;
4 | var exec = require('child_process').exec;
5 | var spawn = require('child_process').spawn;
6 | var phantomTmpl = 'phantomjs server/phantom-runner.js {FRAMEWORK} http://localhost:4000/?framework={FRAMEWORK}\\&autorun=true';
7 | var runCmd = '';
8 |
9 | for (var name in manifest.manifest) {
10 | remaining++;
11 | runCmd = phantomTmpl.replace(/\{FRAMEWORK\}/g, name);
12 | exec(runCmd, {timeout: 10000}, function (error, stdout, stderr) {
13 | if (error) {
14 | failures++;
15 | }
16 |
17 | console.warn(stdout);
18 |
19 | remaining--;
20 | if (!remaining) {
21 | if (failures) {
22 | console.warn('test suite failed');
23 | process.exit(1);
24 | }
25 | else {
26 | console.warn('test suite passes');
27 | process.exit(0);
28 | }
29 | }
30 | });
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/impl/zazl/config.js:
--------------------------------------------------------------------------------
1 | var zazlConfig;
2 |
3 | var config = function(cfg) {
4 | zazlConfig = cfg;
5 | };
6 |
7 | var go = function(dependencies, callback) {
8 | var cfg = zazlConfig ? zazlConfig : {};
9 | var pathname = window.location.pathname;
10 | pathname = pathname.substring(1);
11 | pathname = pathname.substring(pathname.indexOf('/'));
12 | pathname = pathname.substring(0, pathname.lastIndexOf('/')) + "/./";
13 | cfg.baseUrl = pathname;
14 | cfg.directInject = true;
15 | cfg.injectUrl = "/zazl/_javascript";
16 | cfg.scanCJSRequires = true;
17 | zazl(cfg, dependencies, callback);
18 | };
19 | var implemented = {
20 | basic: true,
21 | anon: true,
22 | funcString: true,
23 | namedWrapped: true,
24 | require: true,
25 | plugins: true,
26 | pathsConfig: true,
27 | packagesConfig: true,
28 | mapConfig: true,
29 | moduleConfig: true,
30 | shimConfig: true
31 | //pluginDynamic: true
32 | };
33 | require = undefined;
34 |
--------------------------------------------------------------------------------
/server/manifest.js:
--------------------------------------------------------------------------------
1 | // implied impl/ directory...
2 | exports.manifest = {};
3 |
4 | exports.manifest.requirejs = {
5 | name: 'RequireJS @ 2.1.8',
6 | impl: 'requirejs/require.js',
7 | config: 'requirejs/config.js'
8 | };
9 |
10 | exports.manifest.needs = {
11 | name: 'Needs JS @ a915dce3',
12 | impl: 'needs/needs.js',
13 | config: 'needs/config.js'
14 | };
15 |
16 | exports.manifest.inject = {
17 | name: 'Inject @ 0.4.1',
18 | impl: 'inject/inject.js',
19 | config: 'inject/config.js'
20 | };
21 |
22 | exports.manifest.lsjs = {
23 | name: 'lsjs @ e61412da',
24 | impl: 'lsjs/lsjs.js',
25 | config: 'lsjs/config.js'
26 | };
27 |
28 | exports.manifest.zazl = {
29 | name: 'zazl @ 1.0.4',
30 | impl: 'zazl/zazl.js',
31 | config: 'zazl/config.js',
32 | installer: '../impl/zazl/installer'
33 | };
34 |
35 | exports.manifest.esl = {
36 | name: 'esl @ 1.8.4',
37 | impl: 'esl/esl.js',
38 | config: 'esl/config.js'
39 | };
40 |
41 |
42 |
--------------------------------------------------------------------------------
/impl/inject/config.js:
--------------------------------------------------------------------------------
1 | /*
2 | Note: When running the tests for the inject loader make sure localStorage has been
3 | cleared for the first run to ensure the latest version of the tests are executed.
4 | Either clear the browser cookies or programatically run localStorage.clear();
5 | */
6 | function setModuleRoot() {
7 | var url = location.href.split("?")[0],
8 | base = url.substr(0, url.lastIndexOf("/")+1);
9 | Inject.setModuleRoot(base);
10 | }
11 |
12 | Inject.reset();
13 | Inject.enableAMDPlugins();
14 | setModuleRoot();
15 | var config = function(pathObj) {
16 | for(var key in pathObj.paths) {
17 | Inject.addRule(key, {path:pathObj.paths[key]});
18 | }
19 | },
20 | go = function() {
21 | Inject.require.apply(this, arguments)
22 | },
23 | implemented = {
24 | basic: true,
25 | anon: true,
26 | funcString: true,
27 | namedWrapped: true,
28 | require: true,
29 | plugins: true,
30 | pathsConfig: true
31 | };
32 | require = undefined;
33 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/index.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function parse(name) {
4 | var parts = name.split('?'),
5 | index = parseInt(parts[0], 10),
6 | choices = parts[1].split(':'),
7 | choice = choices[index];
8 |
9 | return {
10 | index: index,
11 | choices: choices,
12 | choice: choice
13 | };
14 | }
15 |
16 | define({
17 | pluginBuilder: './indexBuilder',
18 | normalize: function (name, normalize) {
19 | var parsed = parse(name),
20 | choices = parsed.choices;
21 |
22 | //Normalize each path choice.
23 | for (i = 0; i < choices.length; i++) {
24 | choices[i] = normalize(choices[i]);
25 | }
26 |
27 | return parsed.index + '?' + choices.join(':');
28 | },
29 |
30 | load: function (name, req, load, config) {
31 | req([parse(name).choice], function (value) {
32 | load(value);
33 | });
34 | }
35 | });
36 |
37 | }());
38 |
--------------------------------------------------------------------------------
/tests/config_map_star/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: './',
3 | paths: {
4 | a: 'a1'
5 | },
6 |
7 | map: {
8 | '*': {
9 | 'c': 'another/c'
10 | },
11 | 'a': {
12 | c: 'c1'
13 | },
14 | 'a/sub/one': {
15 | 'c': 'c2',
16 | 'c/sub': 'another/c/sub'
17 | }
18 | }
19 | });
20 |
21 | go( ["_reporter", "a", "b", "c", "a/sub/one"],
22 | function (amdJS, a, b, c, one) {
23 | amdJS.assert('c1' === a.c.name, 'config_map_star: a.c.name');
24 | amdJS.assert('c1/sub' === a.csub.name, 'config_map_star: a.csub.name');
25 | amdJS.assert('c2' === one.c.name, 'config_map_star: one.c.name');
26 | amdJS.assert('another/c/sub' === one.csub.name, 'config_map_star: one.csub.name');
27 | amdJS.assert('another/c/dim' === one.csub.dimName, 'config_map_star: one.csub.dimName');
28 | amdJS.assert('another/c' === b.c.name, 'config_map_star: b.c.name');
29 | amdJS.assert('another/minor' === b.c.minorName, 'config_map_star: b.c.minorName');
30 | amdJS.assert('another/c/sub' === b.csub.name, 'config_map_star: b.csub.name');
31 | amdJS.assert('another/c' === c.name, 'config_map_star: c.name');
32 | amdJS.assert('another/minor' === c.minorName, 'config_map_star: c.minorName');
33 | amdJS.print('DONE', 'done');
34 | });
35 |
--------------------------------------------------------------------------------
/impl/zazl/installer.js:
--------------------------------------------------------------------------------
1 | var npm = require('npm');
2 | var path = require('path');
3 | var fs = require('fs');
4 | var util = require('util');
5 |
6 | function startZazl(zazloptimizer, app) {
7 | var testsdir = fs.realpathSync(path.join(__dirname, "../../tests"));
8 | var optimizer = zazloptimizer.createConnectOptimizer(testsdir, false);
9 | app.use("/zazl/_javascript", optimizer);
10 | app.get('/framework/zazl.js', function(req, res) {
11 | fs.readFile(zazloptimizer.getLoaderDir()+"/loader/amd/zazl.js", function(err, data) {
12 | res.setHeader('Content-Type', 'text/javascript');
13 | res.end(data.toString());
14 | });
15 | });
16 | }
17 |
18 | exports.install = function(app, cb) {
19 | npm.load([], function(err, npm) {
20 | if (err) {
21 | cb("zazl", false);
22 | return;
23 | }
24 | var zazloptimizer;
25 | try {
26 | zazloptimizer = require('zazloptimizer');
27 | util.log("zazloptimizer is already installed");
28 | startZazl(zazloptimizer, app);
29 | cb("zazl", true);
30 | } catch (e) {
31 | npm.commands.install(['zazloptimizer'], function() {
32 | util.log("zazloptimizer has been installed");
33 | zazloptimizer = require('zazloptimizer');
34 | startZazl(zazloptimizer, app);
35 | cb("zazl", true);
36 | });
37 | }
38 | });
39 | }
--------------------------------------------------------------------------------
/tests/plugin_dynamic/_test.js:
--------------------------------------------------------------------------------
1 | go( ["_reporter", "pillow", "sub/blanket"],
2 | function (amdJS, pillow, blanket) {
3 | pillow.delayed(function (resource) {
4 | amdJS.assert(resource !== pillow.resource, 'plugin_dynamic: resource and pillow.resource should have different names');
5 | amdJS.assert(blanket.pillowResource !== pillow.resource, 'plugin_dynamic: blanket.pillowResource and pillow.resource should have different names');
6 | amdJS.assert(resource !== blanket.pillowResource, 'plugin_dynamic: resource and blanket.pillowResource should have different names');
7 | //Make sure the paths after the counter ID are not relative.
8 | amdJS.assert(resource.split(':')[1].indexOf('./pillow') === -1, 'plugin_dynamic: after the counter ID for resource, path is not relative');
9 | amdJS.assert(pillow.resource.split(':')[1].indexOf('./pillow') === -1, 'plugin_dynamic: after the counter ID for pillow.resource, path is not relative');
10 | amdJS.assert(blanket.pillowResource.split(':')[1].indexOf('../pillow') === -1, 'plugin_dynamic: after the counter ID for blanket.pillowResource, path is not relative');
11 | amdJS.assert(blanket.resource.split(':')[1].indexOf('./blanket') === -1, 'plugin_dynamic: after the counter ID for blanket.resource, path is not relative');
12 | amdJS.print('DONE', 'done');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/tests/plugin_normalize/indexBuilder.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function parse(name) {
4 | var parts = name.split('?'),
5 | index = parseInt(parts[0], 10),
6 | choices = parts[1].split(':'),
7 | choice = choices[index];
8 |
9 | return {
10 | index: index,
11 | choices: choices,
12 | choice: choice
13 | };
14 | }
15 |
16 | define({
17 | normalize: function (name, normalize) {
18 | var parsed = parse(name),
19 | choices = parsed.choices;
20 |
21 | //Normalize each path choice.
22 | for (i = 0; i < choices.length; i++) {
23 | choices[i] = normalize(choices[i]);
24 | }
25 |
26 | return parsed.index + '?' + choices.join(':');
27 | },
28 |
29 | load: function (name, req, load, config) {
30 | req([parse(name).choice], function (value) {
31 | load(value);
32 | });
33 | },
34 |
35 | //This is strictly not necessary (and *not* recommended),
36 | //but just doing it as a test.
37 | write: function (pluginName, moduleName, write) {
38 | var parsed = parse(moduleName);
39 | write("define('" + pluginName + "!" + moduleName +
40 | "', ['" + parsed.choice + "'], function (value) { return value;});\n");
41 | }
42 | });
43 |
44 | }());
45 |
--------------------------------------------------------------------------------
/tests/config_shim/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: './',
3 | shim: {
4 | a: {
5 | exports: 'A.name',
6 | init: function () {
7 | window.globalA = this.A.name;
8 | }
9 | },
10 | 'b': ['a', 'd'],
11 | 'c': {
12 | deps: ['a', 'b'],
13 | exports: 'C'
14 | },
15 | 'e': {
16 | exports: 'e.nested.e',
17 | init: function () {
18 | return {
19 | name: e.nested.e.name + 'Modified'
20 | };
21 | }
22 | },
23 | 'f': {
24 | deps: ['a'],
25 | init: function (a) {
26 | return {
27 | name: FCAP.name,
28 | globalA: FCAP.globalA,
29 | a: a
30 | };
31 | }
32 | }
33 | }
34 | });
35 |
36 |
37 | go( ["_reporter", "a", "c", "e", "f"],
38 | function (amdJS, a, c, e, f) {
39 | amdJS.assert('a' === a, 'config_shim: a');
40 | amdJS.assert('a' === window.globalA, 'config_shim: window.globalA');
41 | amdJS.assert('a' === c.b.aValue, 'config_shim: c.b.aValue');
42 | amdJS.assert('b' === c.b.name, 'config_shim: c.b.name');
43 | amdJS.assert('c' === c.name, 'config_shim: c.name');
44 | amdJS.assert('d' === c.b.dValue.name, 'config_shim: c.b.dValue.name');
45 | amdJS.assert('eModified' === e.name, 'config_shim: e.name');
46 | amdJS.assert('FCAP' === f.name, 'config_shim: f.name');
47 | amdJS.assert('a' === f.globalA.name, 'config_shim: f.globalA.name');
48 | amdJS.assert('a' === f.a, 'config_shim: f.a');
49 | amdJS.print('DONE', 'done');
50 | });
51 |
--------------------------------------------------------------------------------
/server/resources/reporter.js:
--------------------------------------------------------------------------------
1 | /*
2 | * This file bridges the standard AMD-JS test suite with the simple
3 | * browser runner. We proxy the go() method, and then we implement
4 | * the window.amdJSPrint method as per the specification.
5 | *
6 | * The proxy of go() allows us to manage a timeout for the test
7 | * in case there is a deep problem with the loader itself
8 | * (read: even require() is broken)
9 | *
10 | * The amdJSPrint method pushes data to the top-level window.console
11 | * as well as registering its suite result with the parent
12 | */
13 | (function(scope) {
14 | // load me after your AMD implementation that provides
15 | // "go", "config", and "implemented"
16 | window.setTimeout(function() {
17 | document.body.style.backgroundColor = 'gray';
18 | }, 0);
19 |
20 | var oldGo = window.go;
21 | var stopStack = [];
22 | var pass = true;
23 |
24 | // resolve the tests to a background color
25 | var resolve = function() {
26 | var color = 'gray';
27 | // empty stack or failing tests resolve immediately
28 | if (stopStack.length === 0 || !pass) {
29 | color = (pass) ? 'green' : 'red';
30 | }
31 | document.body.style.backgroundColor = color;
32 | };
33 |
34 | // override go() with a start/stop timer
35 | window.go = function () {
36 | var newArgs = [].splice.call(arguments, 0);
37 | var fn = newArgs[newArgs.length - 1];
38 |
39 | stopStack.push(window.setTimeout(function() {
40 | window.amdJSPrint('Test timed out: ' + newArgs.join(';'), 'fail');
41 | }, 3000));
42 |
43 | oldGo.apply(oldGo, newArgs);
44 | };
45 |
46 | // print causes a console log event
47 | // on first fail, we flag as red
48 | window.amdJSPrint = function (message, type) {
49 | var fullMessage = type + ' ' + message;
50 | window.top.console.log(fullMessage);
51 |
52 | try {
53 | if (window.top.amdJSSignal) {
54 | if (type === 'fail') {
55 | window.top.amdJSSignal.fail(message);
56 | }
57 | else if (type === 'done') {
58 | window.top.amdJSSignal.done();
59 | }
60 | }
61 | }
62 | catch (e) {}
63 |
64 | if (type === 'fail') {
65 | pass = false;
66 | resolve();
67 | }
68 |
69 | if (type === 'done') {
70 | window.clearTimeout(stopStack.pop());
71 | resolve();
72 | }
73 | };
74 | })(this);
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | amdjs-tests is released under two licenses: new BSD, and MIT. You may pick the
2 | license that best suits your development needs. The text of both licenses are
3 | provided below.
4 |
5 | The individual loader implementations are subject to their own specific
6 | licenses. This license only covers the tests.
7 |
8 |
9 | The "New" BSD License:
10 | ----------------------
11 |
12 | Copyright (c) 2010-2011, The Dojo Foundation
13 | All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without
16 | modification, are permitted provided that the following conditions are met:
17 |
18 | * Redistributions of source code must retain the above copyright notice, this
19 | list of conditions and the following disclaimer.
20 | * Redistributions in binary form must reproduce the above copyright notice,
21 | this list of conditions and the following disclaimer in the documentation
22 | and/or other materials provided with the distribution.
23 | * Neither the name of the Dojo Foundation nor the names of its contributors
24 | may be used to endorse or promote products derived from this software
25 | without specific prior written permission.
26 |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
31 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 |
38 |
39 |
40 | MIT License
41 | -----------
42 |
43 | Copyright (c) 2010-2011, The Dojo Foundation
44 |
45 | Permission is hereby granted, free of charge, to any person obtaining a copy
46 | of this software and associated documentation files (the "Software"), to deal
47 | in the Software without restriction, including without limitation the rights
48 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49 | copies of the Software, and to permit persons to whom the Software is
50 | furnished to do so, subject to the following conditions:
51 |
52 | The above copyright notice and this permission notice shall be included in
53 | all copies or substantial portions of the Software.
54 |
55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
61 | THE SOFTWARE.
62 |
--------------------------------------------------------------------------------
/tests/config_packages/_test.js:
--------------------------------------------------------------------------------
1 | config({
2 | baseUrl: './',
3 | paths: {
4 | 'alpha/replace' : 'replace'
5 | },
6 | packages: [
7 | {
8 | name: 'alpha',
9 | location: 'pkgs/alpha'
10 | },
11 | {
12 | name: 'beta',
13 | location: 'pkgs/beta/0.2/scripts',
14 | main: 'beta'
15 | },
16 | {
17 | name: 'dojox/chair',
18 | location: 'pkgs/dojox/chair'
19 | },
20 | {
21 | name: 'dojox/table',
22 | location: 'pkgs/dojox/table',
23 | main: 'table'
24 | },
25 | {
26 | name: 'bar',
27 | location: 'bar/0.4',
28 | main: 'scripts/main'
29 | },
30 | {
31 | name: 'foo',
32 | location: 'foo/lib'
33 | },
34 | {
35 | name: 'funky',
36 | main: 'index.js'
37 | },
38 | {
39 | name: 'baz',
40 | location: 'baz/lib',
41 | main: 'index'
42 | },
43 | {
44 | name: 'dojox/window',
45 | location: 'dojox/window',
46 | main: 'window'
47 | }
48 | ]
49 | });
50 |
51 | go([
52 | "_reporter",
53 | "require",
54 | "alpha",
55 | "alpha/replace",
56 | "beta",
57 | "beta/util",
58 | "bar",
59 | "baz",
60 | "foo",
61 | "foo/second",
62 | "dojox/chair",
63 | "dojox/table",
64 | "dojox/door",
65 | "dojox/window/pane",
66 | "dojox/window",
67 | "dojox/table/legs",
68 | "funky"],
69 | function (amdJS, require, alpha, replace, beta, util, bar, baz, foo, second,
70 | chair, table, door, pane, window, legs, funky) {
71 |
72 | amdJS.assert('alpha' === alpha.name, 'config_packages: alpha.name');
73 | amdJS.assert('fake/alpha/replace' === replace.name, 'config_packages: replace.name');
74 | amdJS.assert('beta' === beta, 'config_packages: beta');
75 | amdJS.assert('beta/util' === util.name, 'config_packages: util.name');
76 | amdJS.assert('bar' === bar.name, 'config_packages: bar.name');
77 | amdJS.assert('0.4' === bar.version, 'config_packages: bar.version');
78 | amdJS.assert('baz' === baz.name, 'config_packages: baz.name');
79 | amdJS.assert('0.4' === baz.barDepVersion, 'config_packages: baz.barDepVersion');
80 | amdJS.assert('foo' === baz.fooName, 'config_packages: baz.fooName');
81 | amdJS.assert('baz/helper' === baz.helperName, 'config_packages: baz.helperName');
82 | amdJS.assert('foo' === foo.name, 'config_packages: foo.name');
83 | amdJS.assert('alpha' === foo.alphaName, 'config_packages: foo.alphaName');
84 | amdJS.assert('foo/second' === second.name, 'config_packages: second.name');
85 | amdJS.assert('dojox/chair' === chair.name, 'config_packages: chair.name');
86 | amdJS.assert('dojox/chair/legs' === chair.legsName, 'config_packages: chair.legsName');
87 | amdJS.assert('dojox/table' === table.name, 'config_packages: table.name');
88 | amdJS.assert('dojox/chair' === table.chairName, 'config_packages: table.chairName');
89 | amdJS.assert('dojox/table/legs' === legs.name, 'config_packages: legs.name');
90 | amdJS.assert('dojox/door' === door.name, 'config_packages: door.name');
91 | amdJS.assert('dojox/window/pane' === pane.name, 'config_packages: pane.name');
92 | amdJS.assert('dojox/window' === window.name, 'config_packages: window.name');
93 | amdJS.assert('dojox/window/pane' === window.paneName, 'config_packages: window.paneName');
94 | amdJS.assert('funky' === funky.name, 'config_packages: funky.name');
95 | amdJS.assert('monkey' === funky.monkeyName, 'config_packages: funky.monkeyName');
96 | amdJS.print('DONE', 'done');
97 | }
98 | );
99 |
--------------------------------------------------------------------------------
/server/phantom-runner.js:
--------------------------------------------------------------------------------
1 | // phantomJS runner
2 | // http://phantomjs.org/download.html
3 |
4 | /**
5 | * Wait until the test condition is true or a timeout occurs. Useful for waiting
6 | * on a server response or for a ui change (fadeIn, etc.) to occur.
7 | *
8 | * @param testFx javascript condition that evaluates to a boolean,
9 | * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
10 | * as a callback function.
11 | * @param onReady what to do when testFx condition is fulfilled,
12 | * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
13 | * as a callback function.
14 | * @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
15 | */
16 | function waitFor(testFx, onReady, timeOutMillis) {
17 | var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 10000, //< Default Max Timout is 10s
18 | start = new Date().getTime(),
19 | condition = false,
20 | interval = setInterval(function () {
21 | if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
22 | // If not time-out yet and condition not yet fulfilled
23 | condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
24 | } else {
25 | if(!condition) {
26 | // If condition still not fulfilled (timeout but condition is 'false')
27 | console.warn("'waitFor()' timeout");
28 | phantom.exit(1);
29 | } else {
30 | // Condition fulfilled (timeout and/or condition is 'true')
31 | console.warn("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
32 | typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
33 | clearInterval(interval); //< Stop this interval
34 | }
35 | }
36 | }, 100); //< repeat check every 250ms
37 | };
38 |
39 |
40 | if (phantom.args.length === 0 || phantom.args.length > 3) {
41 | console.warn('Usage: phantom-runner.js NAME URL');
42 | phantom.exit();
43 | }
44 |
45 | var page = new WebPage();
46 | var opened = false;
47 |
48 | // Route "console.warn()" calls from within the Page context to the main Phantom context (i.e. current "this")
49 | page.onConsoleMessage = function(msg) {
50 | console.warn(msg);
51 | };
52 |
53 | // open phantom page
54 | page.open(phantom.args[1], function (status) {
55 | if (status !== "success") {
56 | console.warn("Unable to access network");
57 | phantom.exit();
58 | } else {
59 | if (!opened) {
60 | console.warn("BEGIN: "+phantom.args[0]+"\n==============================");
61 | opened = true;
62 | }
63 |
64 | // begin polling for results
65 | waitFor(function() {
66 | // only proceed if the travis-results node exists
67 | return page.evaluate(function(){
68 | var el = document.getElementById('travis-results');
69 | if (el && el.innerHTML.length > 0) {
70 | return true;
71 | }
72 | return false;
73 | });
74 | }, function () {
75 | // test if we have failed
76 | var passed = page.evaluate(function () {
77 | var el = document.getElementById('travis-results'),
78 | result = el.innerHTML.replace(/^\s+/, '').replace(/\s+$/, '');
79 | return (result == 'pass') ? true : false;
80 | });
81 | console.warn((passed) ? 'pass' : 'fail');
82 | console.warn("END: "+phantom.args[0]+"\n==============================");
83 | phantom.exit((passed) ? 0 : 1);
84 | });
85 | }
86 | });
--------------------------------------------------------------------------------
/server/resources/all.js:
--------------------------------------------------------------------------------
1 | /*
2 | ABOUT THIS FILE
3 | ===============
4 | This file is the JS driver for the test running interface. Its main purpose
5 | is selecting a test from the suite list, performing the "runTests" operation,
6 | and reporting back for the sake of its own Travis-CI runner.
7 |
8 | On boot, it tags tests as valid based on the window.implemented from a
9 | framework's test config.
10 |
11 | The global amdJSSignal object will listen for a failure and flag tests
12 | as failed or complete.
13 |
14 | Finally, calling a framework with &autorun=true will start the tests
15 | automatically, again for Travis-CI.
16 | */
17 |
18 | (function() {
19 |
20 | // autoRun based on url parameters, triggers automatic run of the test
21 | // suite
22 | var autoRun = (location.search.indexOf('autorun=true') != -1) ? true : false;
23 |
24 | // a collection of test passes and fails, grouped by their test identifier
25 | var groupings = {};
26 |
27 | // how many tests are we expecting to complete. Determined at runTests time
28 | var expectedDone = 0;
29 |
30 | // have any of the tests failed
31 | var failed = false;
32 |
33 | // a node to contain the result ID for travis
34 | var travisResult = document.createElement('div');
35 | travisResult.id = 'travis-results';
36 |
37 | // a global timeout for the AMD system (ms)
38 | var globalAMDTimeout = 20000;
39 |
40 | // holds the window timeout object to be cancelled when tests are done
41 | var globalTimeout;
42 |
43 | // tag valid tests as testable
44 | // we give it a "testable" class. We then add a bunch of
45 | // pending DIVs until test execution fires
46 | // this helps an end user visualize which tests will be
47 | // executed
48 | if (window.implemented) {
49 | for (impl in implemented) {
50 | nodes = document.getElementsByClassName(impl);
51 | for (i = 0, len = nodes.length; i < len; i++) {
52 | nodes[i].className += ' testable';
53 | iframe = document.createElement('div');
54 | iframe.className = 'skipped';
55 | nodes[i].insertBefore(iframe, nodes[i].firstChild);
56 | }
57 | }
58 | }
59 |
60 | // selects a framework and reloads the page, enabling that framework
61 | function selectFramework() {
62 | var qstr = '?framework=' + document.getElementById('select-framework').value;
63 | location.href = location.pathname + qstr;
64 | }
65 |
66 | // runs the test collection
67 | // 1. start a timer
68 | // 2. find all the tests that are flagged "testable"
69 | // 3. add to the # of expected tests
70 | // 4. create an iframe to house the test based on the tag
71 | // 5. drop the iframe in where the div was previously
72 | function runTests() {
73 | document.getElementById('run-tests').disabled = true;
74 |
75 | globalTimeout = window.setTimeout(function() {
76 | failed = true;
77 | travisResult.innerHTML = 'fail';
78 | document.body.appendChild(travisResult);
79 | }, globalAMDTimeout);
80 |
81 | var using = (implemented) ? implemented : {}; // global
82 | var nodes;
83 | var impl;
84 | var i;
85 | var len;
86 | var link;
87 | var parent;
88 | var testable;
89 | var iframe;
90 |
91 | groupings = {};
92 | nodes = [].slice.apply(document.getElementById('tests').getElementsByTagName('a'));
93 | failed = false;
94 |
95 | for (i = 0, len = nodes.length; i < len; i++) {
96 | link = nodes[i];
97 | parent = link.parentNode;
98 | testable = parent.className.indexOf('testable') >= 0;
99 | if (testable) {
100 | expectedDone++;
101 | if (parent.getElementsByTagName('div')[0]) {
102 | parent.removeChild(parent.getElementsByTagName('div')[0]);
103 | }
104 | iframe = document.createElement('iframe');
105 | iframe.src = link.href;
106 | parent.insertBefore(iframe, link);
107 | }
108 | }
109 | }
110 |
111 | // handle the explcit AMD signalling infrastructure.
112 | // our reporter (in individual test files) is bridged to invoke
113 | // window.top.amdJSSignal.*, with pass(), fail(), and done()
114 | // methods. We use this for travis signalling
115 | window.amdJSSignal = {
116 | fail: function() {
117 | failed = true;
118 | travisResult.innerHTML = 'fail';
119 | document.body.appendChild(travisResult);
120 | },
121 | done: function() {
122 | expectedDone--;
123 | if (expectedDone <= 0 && !failed) {
124 | window.clearTimeout(globalTimeout);
125 | travisResult.innerHTML = 'pass';
126 | document.body.appendChild(travisResult);
127 | }
128 | }
129 | };
130 |
131 | document.getElementById('run-tests').removeAttribute('disabled');
132 |
133 | // do an autorun if enabled by query string
134 | if (autoRun) {
135 | window.setTimeout(function() {
136 | runTests();
137 | }, 10);
138 | }
139 |
140 | // add very simple low level event listeners
141 | document.getElementById('select-framework').onchange = selectFramework;
142 | document.getElementById('run-tests').onclick = runTests;
143 |
144 | })();
--------------------------------------------------------------------------------
/tests/plugin_fromtext/refine.js:
--------------------------------------------------------------------------------
1 |
2 | /*jslint strict: false, plusplus: false */
3 | /*global define: false, require: false, XMLHttpRequest: false, ActiveXObject: false,
4 | window: false, Packages: false, java: false, process: false */
5 |
6 | (function () {
7 | //Load the text plugin, so that the XHR calls can be made.
8 | var buildMap = {}, fetchText, fs,
9 | progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
10 |
11 | function createXhr() {
12 | //Would love to dump the ActiveX crap in here. Need IE 6 to die first.
13 | var xhr, i, progId;
14 | if (typeof XMLHttpRequest !== "undefined") {
15 | return new XMLHttpRequest();
16 | } else {
17 | for (i = 0; i < 3; i++) {
18 | progId = progIds[i];
19 | try {
20 | xhr = new ActiveXObject(progId);
21 | } catch (e) {}
22 |
23 | if (xhr) {
24 | progIds = [progId]; // so faster next time
25 | break;
26 | }
27 | }
28 | }
29 |
30 | if (!xhr) {
31 | throw new Error("require.getXhr(): XMLHttpRequest not available");
32 | }
33 |
34 | return xhr;
35 | }
36 |
37 | if (typeof window !== "undefined" && window.navigator && window.document) {
38 | fetchText = function (url, callback) {
39 | var xhr = createXhr();
40 | xhr.open('GET', url, true);
41 | xhr.onreadystatechange = function (evt) {
42 | //Do not explicitly handle errors, those should be
43 | //visible via console output in the browser.
44 | if (xhr.readyState === 4) {
45 | callback(xhr.responseText);
46 | }
47 | };
48 | xhr.send(null);
49 | };
50 | } else if (typeof process !== "undefined" &&
51 | process.versions &&
52 | !!process.versions.node) {
53 | //Using special require.nodeRequire, something added by r.js.
54 | fs = require.nodeRequire('fs');
55 |
56 | fetchText = function (url, callback) {
57 | callback(fs.readFileSync(url, 'utf8'));
58 | };
59 | } else if (typeof Packages !== 'undefined') {
60 | //Why Java, why is this so awkward?
61 | fetchText = function (url, callback) {
62 | var encoding = "utf-8",
63 | file = new java.io.File(url),
64 | lineSeparator = java.lang.System.getProperty("line.separator"),
65 | input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
66 | stringBuffer, line,
67 | content = '';
68 | try {
69 | stringBuffer = new java.lang.StringBuffer();
70 | line = input.readLine();
71 |
72 | // Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
73 | // http://www.unicode.org/faq/utf_bom.html
74 |
75 | // Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
76 | // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
77 | if (line && line.length() && line.charAt(0) === 0xfeff) {
78 | // Eat the BOM, since we've already found the encoding on this file,
79 | // and we plan to concatenating this buffer with others; the BOM should
80 | // only appear at the top of a file.
81 | line = line.substring(1);
82 | }
83 |
84 | stringBuffer.append(line);
85 |
86 | while ((line = input.readLine()) !== null) {
87 | stringBuffer.append(lineSeparator);
88 | stringBuffer.append(line);
89 | }
90 | //Make sure we return a JavaScript string and not a Java string.
91 | content = String(stringBuffer.toString()); //String
92 | } finally {
93 | input.close();
94 | }
95 | callback(content);
96 | };
97 | }
98 |
99 | define(function () {
100 | return {
101 | load: function (name, parentRequire, load, config) {
102 | var url = parentRequire.toUrl(name + '.refine');
103 | fetchText(url, function (text) {
104 | text = text.replace(/refine/g, 'define');
105 |
106 | if (config.isBuild) {
107 | buildMap[name] = text;
108 | }
109 |
110 | //Add in helpful debug line
111 | text += "\r\n//@ sourceURL=" + url;
112 |
113 | load.fromText(name, text);
114 |
115 | parentRequire([name], function (value) {
116 | load(value);
117 | });
118 | });
119 | },
120 |
121 | write: function (pluginName, name, write) {
122 | if (name in buildMap) {
123 | var text = buildMap[name];
124 | write.asModule(pluginName + "!" + name, text);
125 | }
126 | }
127 | };
128 | });
129 |
130 | }());
131 |
--------------------------------------------------------------------------------
/server/server.js:
--------------------------------------------------------------------------------
1 | var util = require('util');
2 | var path = require('path');
3 | var fs = require('fs');
4 | var express = require('express');
5 | var manifest = require('./manifest').manifest;
6 | var app = express();
7 | var systemNotify = false;
8 |
9 | function fourOhFour(res, msg) {
10 | console.log(msg);
11 | res.end('', 404);
12 | }
13 |
14 | function start() {
15 | app.get('/', function(req, res) {
16 | // run all tests
17 | if (req.query)
18 | fs.readFile(path.normalize(path.join(__dirname, './resources/all.html')), function(err, data) {
19 | if (err) return fourOhFour(res, err);
20 |
21 | var frameworkConfigScriptTag = (req.query.framework) ? '' : '';
22 | var frameworkLibScriptTag = (req.query.framework) ? '' : '';
23 |
24 | var frameworkOptions = [];
25 | for (var id in manifest) {
26 | frameworkOptions.push('');
27 | }
28 |
29 | var output = data.toString()
30 | .replace(/\{\{HASTESTS\}\}/g, (req.query.framework) ? 'has-tests' : '')
31 | .replace(/\{\{FRAMEWORK_OPTIONS\}\}/g, frameworkOptions.join('\n'))
32 | .replace(/\{\{FRAMEWORK\}\}/g, req.query.framework)
33 | .replace(/\{\{FRAMEWORK_CONFIG\}\}/, frameworkConfigScriptTag)
34 | .replace(/\{\{FRAMEWORK_LIB\}\}/, frameworkLibScriptTag);
35 | res.setHeader('Content-Type', 'text/html');
36 | res.end(output);
37 | });
38 | });
39 |
40 | app.get('/util/reporter.js', function(req, res) {
41 | // load the reporters
42 | fs.readFile(path.normalize(path.join(__dirname, './resources/reporter.js')), function(err, data) {
43 | if (err) return fourOhFour(res, err);
44 | res.setHeader('Content-Type', 'text/javascript');
45 | res.end(data.toString());
46 | });
47 | });
48 |
49 | app.get('/util/all.js', function(req, res) {
50 | // load the reporters
51 | fs.readFile(path.normalize(path.join(__dirname, './resources/all.js')), function(err, data) {
52 | if (err) return fourOhFour(res, err);
53 | res.setHeader('Content-Type', 'text/javascript');
54 | res.end(data.toString());
55 | });
56 | });
57 |
58 | app.get('/util/all.css', function(req, res) {
59 | // load the reporters
60 | fs.readFile(path.normalize(path.join(__dirname, './resources/all.css')), function(err, data) {
61 | if (err) return fourOhFour(res, err);
62 | res.setHeader('Content-Type', 'text/css');
63 | res.end(data.toString());
64 | });
65 | });
66 |
67 | app.get('/framework/:framework', function(req, res) {
68 | // load a framework file
69 | var framework = req.params.framework.replace(/\.js$/, '');
70 | fs.readFile(path.normalize(path.join(__dirname, '../impl/'+manifest[framework].impl)), function(err, data) {
71 | if (err) return fourOhFour(res, err);
72 | res.setHeader('Content-Type', 'text/javascript');
73 | res.end(data.toString());
74 | });
75 | });
76 |
77 | app.get('/config/:framework', function(req, res) {
78 | // load a config file
79 | var framework = req.params.framework.replace(/\.js$/, '');
80 | fs.readFile(path.normalize(path.join(__dirname, '../impl/'+manifest[framework].config)), function(err, data) {
81 | if (err) return fourOhFour(res, err);
82 | res.setHeader('Content-Type', 'text/javascript');
83 | res.end(data.toString());
84 | });
85 | });
86 |
87 | app.get('/:framework/:test/system.js', function(req, res) {
88 | // get a file for the specified test
89 | res.setHeader('Content-Type', 'text/javascript');
90 | if (!systemNotify) {
91 | systemNotify = true;
92 | console.log('"system" module requested by browser. Usually a side-effect of doing static analysis');
93 | }
94 | res.end('', 404);
95 | });
96 |
97 | app.get('/:framework/:test/test.html', function(req, res) {
98 | // run one test
99 | fs.readFile(path.normalize(path.join(__dirname, './resources/template.html')), function(err, data) {
100 | if (err) return fourOhFour(res, err);
101 |
102 | var framework = '/framework/'+req.params.framework+'.js';
103 | var fwkConfig = '/config/'+req.params.framework+'.js';
104 | var reporter = '/util/reporter.js';
105 | var testFile = '/'+req.params.framework+'/'+req.params.test+'/_test.js';
106 | var testName = req.params.test;
107 |
108 | var output = data.toString()
109 | .replace(/\{\{FRAMEWORK\}\}/g, framework)
110 | .replace(/\{\{FRAMEWORK_CONFIG\}\}/g, fwkConfig)
111 | .replace(/\{\{REPORTER\}\}/g, reporter)
112 | .replace(/\{\{TEST\}\}/g, testFile)
113 | .replace(/\{\{TEST_NAME\}\}/g, testName);
114 | res.setHeader('Content-Type', 'text/html');
115 | res.end(output);
116 | });
117 | });
118 |
119 | app.get('/:framework/:test/*', function(req, res) {
120 | // get a file for the specified test
121 | var testPath = '../tests/'+req.params.test+'/'+req.params[0];
122 | fs.readFile(path.normalize(path.join(__dirname, testPath)), function(err, data) {
123 | if (err) return fourOhFour(res, err);
124 | res.setHeader('Content-Type', 'text/javascript');
125 | res.end(data.toString());
126 | });
127 | });
128 |
129 | app.get('*', function(req, res){
130 | res.send('', 404);
131 | });
132 |
133 | app.listen(4000);
134 |
135 | util.log('AMD JS Test server running on port 4000');
136 | util.log('To run: http://localhost:4000');
137 | }
138 |
139 | // This will be called when an installer has completed. If there are more than one
140 | // manifest with an installer wait for all of them to complete before starting.
141 | function installerCallback(framework, installed) {
142 | manifest[framework].installed = installed;
143 | var readyToStart = true;
144 | for (var framework in manifest) {
145 | if (manifest[framework].installer && manifest[framework].installed === false) {
146 | readyToStart = false;
147 | }
148 | }
149 |
150 | if (readyToStart) {
151 | util.log("Installers have completed");
152 | start();
153 | }
154 | }
155 |
156 | // Look in the manifests for any installers and run them.
157 | var installer;
158 | for (var framework in manifest) {
159 | if (manifest[framework].installer) {
160 | manifest[framework].installed = false;
161 | installer = require(manifest[framework].installer);
162 | // Call the installer with the express app object allowing it to setup any handlers
163 | installer.install(app, installerCallback);
164 | }
165 | }
166 |
167 | // Check for any installers. If none found call start();
168 | if (!installer) {
169 | start();
170 | }
171 |
172 |
--------------------------------------------------------------------------------
/server/resources/all.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AMD Test Suite
5 |
6 |
7 |
8 | To run, select an implementation library from the list:
9 |
13 | or
14 |
15 |
16 | {{FRAMEWORK_LIB}}
17 | {{FRAMEWORK_CONFIG}}
18 |
19 | Tests for {{FRAMEWORK}}
20 |
21 |
22 | - Anonymous Tests
23 |
34 |
35 |
36 | - Basic Tests
37 |
57 |
58 |
59 | - funcString and CommonJS
60 |
65 |
66 |
67 | - named define() and CommonJS
68 |
73 |
74 |
75 | - "map" in config (DRAFT)
76 |
87 |
88 |
89 | - "module" in config (DRAFT)
90 |
95 |
96 |
97 | - "packages" in config (DRAFT)
98 |
103 |
104 |
105 | - "paths" in config (DRAFT)
106 |
113 |
114 |
115 |
116 | "shim" in config (DRAFT)
117 |
122 |
123 |
124 | Plugin Support
125 |
133 |
134 |
135 | Dynamic Plugin Support
136 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AMD Tests
2 |
3 | [](https://travis-ci.org/amdjs/amdjs-tests/)
4 |
5 | A set of Asynchronous Module Definition
6 | [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) compliance
7 | tests.
8 |
9 | 1. Built In Test Runner
10 | 2. Adding Your Own AMD Framework
11 | 3. Adding AMD-JS Tests To Your CI
12 |
13 | # Using The Built In Test Runner
14 |
15 | The amd-js test suite comes with a node based test runner. Node is available from the [node.js website](http://nodejs.org). A version greater than **0.8.0** is recommended.
16 |
17 | Clone this repository into a local directory, install dependencies with the `npm install` command, and start the server:
18 |
19 | ```sh
20 | node server/server.js
21 | ```
22 |
23 | You can visit **http://localhost:4000** in your browser and run the tests from there.
24 |
25 | # Adding Your Own AMD Framework
26 |
27 | An implementation needs to have the following two files in the **impl** directory:
28 |
29 | * AMD loader implementation
30 | * configure script
31 | * optional installer script (for use if loader provides a Node.js server-side component. see impl/zazl for an example)
32 |
33 | The configure script should define the following global variables:
34 |
35 | * **config**: a function that accepts configuration parameters. Similar to the
36 | RequireJS form of require({}).
37 | * **go**: a function that implements the top level, global function that starts
38 | loading of modules. Equivalent to the RequireJS global require([], function(){})
39 | signature.
40 | * **implemented**: an object whose properties are the types of tests that the
41 | loader expects to pass. A list of valid test categories are at the end of this readme.
42 |
43 | Please then add your framework to `server/manifest` and add a line to `.travis.yml` to begin auto-testing your code.
44 |
45 | # Adding AMD-JS Tests To Your Own Framework
46 |
47 | It's possible to run the AMD-JS tests as part of your existing CI system. You need to provide *bridges* between the AMD-JS suite and your unit testing framework of choice. You can do this by either implementing a global `amdJSPrint` object or defining/implementing a global `system` object on which a `print()` method resides.
48 |
49 | Here is a rudimentary system that just outputs to the console:
50 |
51 | ```js
52 | window.amdJSPrint = function (message, type) {
53 | console.log(message, type);
54 | };
55 | ```
56 |
57 | * **amdJSPrint(message, type)**: Outputs the results of a reporter assertion. The *type* is one of `pass`, `fail`, `info`, or `done`.
58 |
59 | Using the above, this would be the QUnit equivalent. We use the QUnit **stop** and **start** methods to support any asynchronous operations that may be occuring in the test. In the example below, we also proxy our `go` method, allowing us to capture when a require() call begins, and when all callbacks have completed.
60 |
61 | ```js
62 | // load me after your AMD implementation that provides
63 | // "go", "config", and "implemented"
64 | (function() {
65 | var oldGo = window.go;
66 | window.go = function () {
67 | var newArgs = [].splice.call(arguments, 0);
68 | var fn = newArgs[newArgs.length - 1];
69 |
70 | // pause qunit test execution until the dependencies
71 | // are resolved
72 | stop();
73 | newArgs[newArgs.length - 1] = function () {
74 | fn.apply(undefined, arguments);
75 | start();
76 | };
77 |
78 | oldGo.apply(window, newArgs);
79 | };
80 | window.amdJSPrint = function (message, type) {
81 | if (type === 'info' || type === 'done') return;
82 | test(message, function() {
83 | ok(type === 'pass', message);
84 | });
85 | };
86 | })();
87 | ```
88 |
89 | We recommend mounting this repository as a [git submodule](http://git-scm.com/book/en/Git-Tools-Submodules), at which point you can have your testing framework invoke each individual js test.
90 |
91 | If you wish to hook this up directly to Travis-CI, an element is added to the page (*#travis-results*) with a pass/fail string as its contents. A capture of `console.log()` will also output details in the CI runs.
92 |
93 | # Test Types
94 |
95 | Each test type builds on the other: supporting later test types implies support
96 | for earlier test types.
97 |
98 | ## Basic AMD Functionality (basic)
99 |
100 | **in the basic_* directories (except basic_require)**
101 |
102 | Very basic loading of named modules that have dependency arrays.
103 |
104 | * Support for define.amd to indicate an AMD loader.
105 | * Named modules.
106 | * Dependency arrays.
107 | * Circular dependency support via the "exports" and "require" dependency.
108 | * Test for the CommonJS "module" dependency.
109 |
110 | ## The Basic require() Method (require)
111 |
112 | **in the basic_require directory**
113 |
114 | Basic require() support, in accordance with the [amdjs require API](https://github.com/amdjs/amdjs-api/wiki/require):
115 |
116 | * require(String)
117 | * require(Array, Function)
118 | * require.toUrl(String)
119 |
120 | ## Anonymous Module Support (anon)
121 |
122 | **in the anon_* directories**
123 |
124 | Similar tests to **basic**, but using anonymous modules.
125 |
126 | ## CommonJS Compatibility (funcString)
127 |
128 | **in the cjs_define directory**
129 |
130 | Tests parsing of definition functions via Function.prototype.toString() to
131 | get out dependencies. Used to support simplified CommonJS module wrapping:
132 |
133 | ```js
134 | define(function (require) {
135 | var a = require('a');
136 | // Return the module definition.
137 | return {};
138 | });
139 | ```
140 |
141 | ## CommonJS Compatibility with Named Modules (namedWrap)
142 |
143 | **in the cjs_named directory**
144 |
145 | Similar to the **funcString** tests, but using named modules.
146 |
147 | ```javascript
148 | define('some/module', function (require) {
149 | var a = require('a');
150 | //Return the module definition.
151 | return {};
152 | });
153 | ```
154 |
155 | ## AMD Loader Plugins (plugins)
156 |
157 | **in the plugin_double, plugin_fromtext, plugin_normalize* directories**
158 |
159 | Support for loader plugins.
160 |
161 | * Calling the same plugin resource twice and getting the same value.
162 | * Testing a plugin that implements normalize().
163 | * Testing a plugin that uses load.fromText().
164 |
165 | ## Dynamic Plugins (pluginsDynamic)
166 |
167 | **in the plugin_dynamic and plugin_dynamic_string* directories**
168 |
169 | Support for loader plugins that use dynamic: true to indicate their resources
170 | should not be cached by the loader. Instead the loader should call the plugin's
171 | load() method for each instance of a dependency that can be loaded by the plugin.
172 |
173 | ## Common Config: Packages
174 |
175 | **in the config_packages directory**
176 |
177 | Support for the [common config API](https://github.com/amdjs/amdjs-api/wiki/Common-Config) section on [map config](https://github.com/amdjs/amdjs-api/wiki/Common-Config#wiki-packages).
178 |
179 | ## Common Config: Map
180 |
181 | **in the config_map and config_map_* directories**
182 |
183 | Support for the [common config API](https://github.com/amdjs/amdjs-api/wiki/Common-Config) section on [map config](https://github.com/amdjs/amdjs-api/wiki/Common-Config#wiki-map).
184 |
185 | ## Common Config: Module
186 |
187 | **in the config_module directory**
188 |
189 | Support for the [common config API](https://github.com/amdjs/amdjs-api/wiki/Common-Config) section on [module config](https://github.com/amdjs/amdjs-api/wiki/Common-Config#wiki-config).
190 |
191 | ## Common Config: Path
192 |
193 | **in the config_paths directory**
194 |
195 | Support for the [common config API](https://github.com/amdjs/amdjs-api/wiki/Common-Config) section on [paths config](https://github.com/amdjs/amdjs-api/wiki/Common-Config#wiki-path).
196 |
197 | ## Common Config: Shim
198 |
199 | **in the config_shim directory**
200 |
201 | Support for the [common config API](https://github.com/amdjs/amdjs-api/wiki/Common-Config) section on [shim config](https://github.com/amdjs/amdjs-api/wiki/Common-Config#wiki-shim).
202 |
203 | # License
204 |
205 | amdjs-tests is released under two licenses: new BSD, and MIT. See the LICENSE
206 | file for more info.
207 |
208 | The individual loader implementations are subject to their own specific
209 | licenses. This license only covers the tests.
210 |
211 |
--------------------------------------------------------------------------------
/impl/needs/needs.js:
--------------------------------------------------------------------------------
1 | /*
2 | * needs.js v0.9.5
3 | * http://minion.org
4 | *
5 | * (c) 2012, Taka Kojima (taka@gigafied.com)
6 | * Licensed under the MIT License
7 | *
8 | * Date: Sun Feb 26 15:24:15 2012 -0800
9 | */
10 | (function (root) {
11 |
12 | /**
13 | * You will see the use of `~` throughout the code.
14 | * `~(Number)` will return true for anything other than -1,
15 | * Essentially another way of doing `>= 0`, just less bytes
16 | */
17 |
18 | Array.prototype.indexOf = Array.prototype.indexOf || function (a, b, c, r) {
19 | for (b = this, c = b.length, r = -1; ~c; r = b[--c] === a ? c : r);
20 | return r;
21 | };
22 |
23 | var _loadQ = [],
24 | _defineQ = [],
25 | _loadedFiles = {},
26 | _modules = {},
27 | _head,
28 | // Used for checking circular dependencies.
29 | _dependencies = {},
30 | // Used in various places, defined here for smaller file size
31 | _rem = ["require", "exports", "module"],
32 |
33 | // Configurable properties...
34 | _config = {},
35 | _baseUrl = "",
36 | _urlArgs = "",
37 | _waitSeconds = 10,
38 | _paths = {};
39 |
40 |
41 | function _isArray (a) {
42 | return a instanceof Array;
43 | }
44 |
45 | /**
46 | * Normalizes a path/url, cleaning up duplicate slashes,
47 | * takes care of `../` and `./` parts
48 | */
49 | function _normalize (path, prevPath) {
50 | // Replace any matches of "./" with "/"
51 | path = path.replace(/(^|[^\.])(\.\/)/g, "$1");
52 |
53 | // Replace any matches of "some/path/../" with "some/"
54 | while (prevPath !== path) {
55 | prevPath = path;
56 | path = path.replace(/([\w,\-]*[\/]{1,})([\.]{2,}\/)/g, "");
57 | }
58 |
59 | // Replace any matches of multiple "/" with a single "/"
60 | return path.replace(/(\/{2,})/g, "/");
61 | }
62 |
63 | /**
64 | * Similar to UNIX dirname, returns the parent path of another path.
65 | */
66 | function _getContext (path) {
67 | return path.substr(0, path.lastIndexOf("/"));
68 | }
69 |
70 | /**
71 | * Given a path and context (optional), will normalize the url
72 | * and convert a relative path to an absolute path.
73 | */
74 | function _resolve (path, context) {
75 |
76 | /**
77 | * If the path does not start with a ".", it's relative
78 | * to the base URL.
79 | */
80 | context = (path.indexOf(".") < 0) ? "" : context;
81 |
82 | /**
83 | * Never resolve "require", "module" and "exports" to absolute paths
84 | * For plugins, only resolve the plugin path, not anything after the first "!"
85 | */
86 | if (~_rem.indexOf(path) || ~path.indexOf("!")) {
87 | return path.replace(/([\d,\w,\s,\.\/]*)(?=\!)/, function ($0, $1) {
88 | return _resolve($1, context);
89 | });
90 | }
91 |
92 | return _normalize((context ? context + "/" : "") + path);
93 | }
94 |
95 | /**
96 | * Loop through all of the items in _loadQ and if all modules in a given
97 | * queue are defined, call the callback function associated with the queue.
98 | */
99 | function _checkLoadQ (i, j, q, ready) {
100 |
101 | for (i = _loadQ.length - 1; ~i && (q = _loadQ[i]); i --) {
102 |
103 | ready = 1;
104 | for (j = q.m.length - 1; ~j && ready; j --) {
105 | ready = _module(q.m[j]);
106 | }
107 | if (ready) {
108 | _loadQ.splice(i, 1);
109 | require(q.m, q.cb);
110 | }
111 | }
112 | }
113 |
114 | /**
115 | * Invokes the first anonymous item in _defineQ.
116 | * Called from script.onLoad, and loader plugins .fromText() method.
117 | */
118 | function _invokeAnonymousDefine (id, q) {
119 | if (_defineQ.length) {
120 | q = _defineQ.splice(0,1)[0];
121 | if (q) {
122 | /**
123 | * If the q is not null, it's an anonymous module and we have to invoke define()
124 | * But first we need to tell the q which id to use, and set alreadyQed to true.
125 | */
126 | q.splice(0,0, id); // set the module id
127 | q.splice(q.length,0, 1); // set alreadyQed to true
128 | define.apply(root, q);
129 | }
130 | }
131 | }
132 |
133 | /**
134 | * Injects a script tag into the DOM
135 | */
136 | function _inject (f, m, script, q, isReady, timeoutID) {
137 |
138 | _head = _head || document.getElementsByTagName('head')[0];
139 |
140 | script = document.createElement("script");
141 | script.src = f;
142 |
143 | /**
144 | * Bind to load events, we do it this way vs. addEventListener for IE support.
145 | * No reason to use addEventListener() then fallback to script.onload, just always use script.onload;
146 | */
147 | script.onreadystatechange = script.onload = function () {
148 |
149 | if (!script.readyState || script.readyState === "complete" || script.readyState === "loaded") {
150 |
151 | clearTimeout(timeoutID);
152 | script.onload = script.onreadystatechange = script.onerror = null;
153 |
154 | _invokeAnonymousDefine(m);
155 | }
156 | };
157 |
158 | /**
159 | * script.onerror gets called in two ways.
160 | * The first, if a script request actually errors (i.e. a 404)
161 | * The second, if a script takes more than X seconds to respond. Where X = _waitSeconds
162 | */
163 | script.onerror = function (e) {
164 |
165 | clearTimeout(timeoutID);
166 | script.onload = script.onreadystatechange = script.onerror = null;
167 |
168 | throw new Error(f + " failed to load.");
169 | };
170 |
171 | timeoutID = setTimeout(script.onerror, _waitSeconds * 1000);
172 |
173 | // Prepend the script to document.head
174 | _head.insertBefore(script, _head.firstChild);
175 |
176 | return 1;
177 | }
178 |
179 | /**
180 | * Does all the loading of modules and plugins.
181 | */
182 | function _load (modules, callback, context, i, q, m, f) {
183 |
184 | q = {m: modules, cb: callback};
185 | _loadQ.push(q);
186 |
187 | for (i = 0; i < modules.length; i ++) {
188 | m = modules[i];
189 | if (~m.indexOf("!")) {
190 | /**
191 | * If the module id has a "!"" in it, it's a plugin...
192 | */
193 | _loadPluginModule(m, context, q, i);
194 | continue;
195 | }
196 |
197 | /**
198 | * Otherwise, it's normal module, not a plugin. Inject the file into the DOM if
199 | * the file has not been loaded yet and if the module is not yet defined.
200 | */
201 | f = _getURL(m);
202 | _loadedFiles[f] = (!_module(m) && !_loadedFiles[f]) ? _inject(f, m) : 1;
203 | }
204 | }
205 |
206 | /**
207 | * Called by _load() and require() used for loading and getting plugin-type modules
208 | */
209 | function _loadPluginModule (module, context, q, moduleIndex, definition, plugin, pluginPath) {
210 |
211 | /**
212 | * Set the plugin path. Plugins are stored differently than normal modules
213 | * Essentially they are stored along with the context in a special "plugins"
214 | * property. This allows modules to lookup plugins with the sync require("index!./foo:./bar") method
215 | */
216 | pluginPath = (context ? context + "/" : "") + "plugins/" + module.replace(/\//g, "_");
217 |
218 | /*
219 | * Let's check to see if the module is already defined.
220 | */
221 | definition = _module(pluginPath);
222 |
223 | /*
224 | * If no load queue is specified, then this function was invoked from require()
225 | * Return whether or not the plugin has been defined yet.
226 | * If the plugin is defined, no need to do anything else, so return.
227 | */
228 |
229 | if (!q || definition) {
230 | return definition;
231 | }
232 |
233 | /*
234 | * Update the path to this plugin in the queue
235 | */
236 | q.m[moduleIndex] = pluginPath;
237 |
238 | module = module.split("!");
239 | plugin = module.splice(0,1)[0];
240 | module = module.join("!");
241 |
242 | /**
243 | * Let's make sure the plugin is loaded before we do anything else.
244 | */
245 | require(plugin, function (pluginModule) {
246 |
247 | /**
248 | * If the plugin module has a normalize() method defined, use it
249 | */
250 | module = pluginModule.normalize ?
251 | pluginModule.normalize(module, function (path) {
252 | return _resolve(path, context);
253 | }) :
254 | _normalize(module);
255 |
256 | function load (definition) {
257 | _module(pluginPath, {exports: definition});
258 | _checkLoadQ();
259 | }
260 |
261 | load.fromText = function (name, definition, dqL) {
262 |
263 | /**
264 | * Update the module path in the load queue with the newly computed module id
265 | */
266 | q.m[moduleIndex] = pluginPath = name;
267 |
268 | /**
269 | * Store the length of the define queue, to check against after the eval().
270 | */
271 | dqL = _defineQ.length;
272 |
273 | /**
274 | * Yes, eval/Function is bad, evil. I hate it, you hate it, but some plugins need it.
275 | * If you don't have any plugins using fromText(), feel free to comment
276 | * the entire load.fromText() out and re-minify the source.
277 | * I use Function vs eval() because nothing executing through fromText() should need access
278 | * to local vars, and Uglify does not mangle variables if it finds "eval()" in your code.
279 | */
280 |
281 | /*jslint evil: true */
282 | new Function(definition)();
283 |
284 | if(_defineQ.length-dqL) {
285 | // Looks like there was a define call in the eval'ed text.
286 | _invokeAnonymousDefine(pluginPath);
287 | }
288 | };
289 |
290 | return pluginModule.load(
291 | module,
292 | require.localize(_getContext(plugin)),
293 | load,
294 | _config[plugin] || {}
295 | );
296 | });
297 | }
298 |
299 | /**
300 | * Gets the module by `id`, otherwise if `def` is specified, define a new module.
301 | */
302 | function _module (id, def, noExports, ns, i, l, parts, pi) {
303 |
304 | /**
305 | * Always return back the id for "require", "module" and "exports",
306 | * these are replaced by calling _swapValues
307 | */
308 | if (~_rem.indexOf(id)) {
309 | return id;
310 | }
311 |
312 | ns = _modules;
313 | parts = id.split("/");
314 |
315 | for (i = 0, l = parts.length; i < l; i ++) {
316 | pi = parts[i];
317 | if (!ns[pi] || (!ns[pi].exports && l-i==1)) {
318 | if (!def) {
319 | /**
320 | * The module is not yet defined, and no definition
321 | * was supplied, so return false.
322 | */
323 | return 0;
324 | }
325 | }
326 |
327 | /**
328 | * If a definition was specified and we are
329 | * at the last part of the path, store the definition.
330 | */
331 | ns[pi] = (l-i==1 && def) ? def : (ns[pi] || {});
332 |
333 | ns = ns[pi];
334 | }
335 | /**
336 | * noExports is set to true from within define, to get back the full module object.
337 | * If noExports != true, then we return the exports property of the module.
338 | */
339 | return noExports ? ns : ns.exports;
340 | }
341 |
342 | /**
343 | * Gets the URL for a module by `id`. Paths passed to _getURL must be absolute.
344 | * To get URLs for relative paths use require.toUrl(id, context)
345 | */
346 | function _getURL (id, prefix) {
347 |
348 | /**
349 | * If the path starts with a "/", or "http", it's an absolute URL
350 | * If it's not an absolute URL, prefix the request with baseUrl
351 | */
352 | prefix = (!id.indexOf("/") || !id.indexOf("http")) ? "" : _baseUrl;
353 |
354 |
355 | for(var p in _paths) {
356 | id = id.replace(new RegExp("(^" + p + ")", "g"), _paths[p]);
357 | }
358 |
359 | return prefix + id + (id.indexOf(".") < 0 ? ".js" : "") + _urlArgs;
360 | }
361 |
362 | /**
363 | * Takes an array as the first argument, and an object as the second.
364 | * Replaces any values found in the array, with values in the object.
365 | */
366 | function _swapValues (a, s, j) {
367 | for (var i in s) {
368 | j = a.indexOf(i);
369 | if (~j) {
370 | a[j] = s[i];
371 | }
372 | }
373 | return a;
374 | }
375 |
376 | /**
377 | * Stores dependencies for this module id.
378 | * Also checks for any circular dependencies, if found, it defines those modules as empty objects temporarily
379 | */
380 | function _resolveCircularReferences (id, dependencies, circulars, i, j, d, subDeps, sd, cid) {
381 |
382 | _dependencies[id] = dependencies;
383 |
384 | /**
385 | * Check for any dependencies that have circular references back to this module
386 | */
387 | for (i = 0; i < dependencies.length; i ++) {
388 | d = dependencies[i];
389 | subDeps = _dependencies[d];
390 | if (subDeps) {
391 | for (j = 0; j < subDeps.length; j ++) {
392 | sd = subDeps[j];
393 | if (dependencies.indexOf(sd) < 0) {
394 | if (sd !== id) {
395 | dependencies.push(sd);
396 | }
397 | else{
398 | /**
399 | * Circular reference detected, define circular
400 | * references as empty modules to be defined later
401 | */
402 | _module(d, {exports : {}});
403 | }
404 | }
405 | }
406 | }
407 | }
408 | }
409 |
410 | /**
411 | * Define modules. AMD-spec compliant.
412 | */
413 | function define (id, dependencies, factory, alreadyQed, depsLoaded, module, facArgs, context, ri) {
414 |
415 | if (typeof id !== 'string') {
416 | /**
417 | * No id means that this is an anonymous module,
418 | * push it to a queue, to be defined upon onLoad
419 | */
420 | factory = dependencies;
421 | dependencies = id;
422 | id = 0;
423 |
424 | _defineQ.push([dependencies, factory]);
425 | return;
426 | }
427 |
428 | if (!_isArray(dependencies)) {
429 | factory = dependencies;
430 | dependencies = [];
431 | }
432 |
433 | if (!alreadyQed) {
434 | /**
435 | * ID was specified, so this is not an anonymous module,
436 | * However, we still need to add an empty queue here to be cleaned up by onLoad
437 | */
438 | _defineQ.push(0);
439 | }
440 |
441 | context = _getContext(id);
442 |
443 | /**
444 | * No dependencies, but the factory function is expecting arguments?
445 | * This means that this is a CommonJS-type module...
446 | */
447 | if (!dependencies.length && factory.length && typeof factory === "function") {
448 |
449 | /**
450 | * Let's check for any references of sync-type require("moduleID")
451 | */
452 | factory.toString()
453 | .replace(/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, "") // Remove any comments first
454 | .replace(/(?:require)\(\s*["']([^'"\s]+)["']\s*\)/g, // Now let's check for any sync style require("module") calls
455 |
456 | function ($0, $1) {
457 | if (dependencies.indexOf($1) < 0) {
458 | /**
459 | * We're not actually replacing anyting inside factory.toString(),
460 | * but this is a nice, clean, convenient way to add any
461 | * sync-type require() matches to the dependencies array.
462 | */
463 | dependencies.push($1);
464 | }
465 | }
466 | );
467 |
468 | dependencies = (_rem.slice(0,factory.length)).concat(dependencies);
469 | }
470 |
471 | if (dependencies.length && !depsLoaded) {
472 |
473 | /**
474 | * Dependencies have not been loaded yet, so let's call require() to load them
475 | * After the dependencies are loaded, reinvoke define() with depsLoaded set to true.
476 | */
477 | _resolveCircularReferences(id, dependencies.slice(0));
478 |
479 | require(dependencies, function () {
480 | define(id, Array.prototype.slice.call(arguments, 0), factory, 1, 1);
481 | }, context);
482 |
483 | return;
484 | }
485 |
486 | /**
487 | * At this point, we know all dependencies have been loaded,
488 | * and `dependencies` is an actually array of modules, not their ids
489 | * Get the module if it has already been defined, otherwise let's create it
490 | */
491 |
492 | module = _module(id, 0, 1);
493 | module = module || {exports: {}};
494 |
495 | module.id = id;
496 | module.url = _getURL(id);
497 |
498 | if (typeof factory === "function") {
499 |
500 | /**
501 | * If the factory is a function, we need to invoke it.
502 | * First let's swap "require", "module" and "exports" with actual objects
503 | */
504 | facArgs =_swapValues(
505 | dependencies.length ? dependencies : (_rem.slice(0,factory.length)),
506 | {
507 | "require" : require.localize(context),
508 | "module" : module,
509 | "exports" : module.exports
510 | }
511 | );
512 |
513 | /**
514 | * In some scenarios, the global require object might have slipped through,
515 | * If so, replace it with a localized require.
516 | */
517 | ri = facArgs.indexOf(require);
518 | if (~ri) {
519 | facArgs[ri] = require.localize(context);
520 | }
521 |
522 | /**
523 | * If the function returns a value, then use that as the module definition
524 | * Otherwise, assume the function modifies the exports object.
525 | */
526 | module.exports = factory.apply(factory, facArgs) || module.exports;
527 | }
528 | else{
529 | /**
530 | * If the factory is not a function, set module.exports to whatever factory is
531 | */
532 | module.exports = factory;
533 | }
534 |
535 | /**
536 | * Make the call to define the module.
537 | */
538 | _module(id, module);
539 |
540 | /**
541 | * Clear the dependencies from the _dependencies object.
542 | * _dependencies gets checked regularly to resolve circular dependencies
543 | * and if this module had any circulars, they have already been resolved.
544 | */
545 | delete _dependencies[id];
546 |
547 | /**
548 | * Now let's check the _loadQ
549 | */
550 | _checkLoadQ();
551 | }
552 |
553 | /**
554 | * Our define() function is an AMD implementation
555 | */
556 | define.amd = {};
557 |
558 | /**
559 | * Asynchronously loads in js files for the modules specified.
560 | * If all modules are already defined, the callback function is invoked immediately.
561 | * If id(s) is specified but no callback function, attempt to get the module and
562 | * return the module if it is defined, otherwise throw an Error.
563 | */
564 | function require (ids, callback, context, plugins, i, modules) {
565 |
566 | if (!callback) {
567 | /**
568 | * If no callback is specified, then try to get the module by it's ID
569 | */
570 | ids = _resolve(ids, context);
571 | callback = _module(ids);
572 | if (!callback) {
573 | plugin = _loadPluginModule(ids, context);
574 | if (plugin) {
575 | return plugin;
576 | }
577 | throw new Error(ids + " is not defined.");
578 | }
579 | /**
580 | * Otherwise return the module's definition.
581 | */
582 | return callback;
583 | }
584 |
585 | ids = (!_isArray(ids)) ? [ids] : ids;
586 | modules = [];
587 |
588 | for (i = 0; i < ids.length; i ++) {
589 | /**
590 | * Convert all relative paths to absolute paths,
591 | * Then check to see if the modules are already defined.
592 | */
593 | ids[i] = _resolve(ids[i], context);
594 | modules.push(_module(ids[i]));
595 | }
596 |
597 | if (~modules.indexOf(0)) {
598 | /**
599 | * If any one of the modules is not yet defined, we need to
600 | * wait until the undefined module(s) are loaded, so call load() and return.
601 | */
602 | _load(ids, callback, context);
603 | return;
604 | }
605 |
606 | /**
607 | * Otherwise, we know all modules are already defined.
608 | * Invoke the callback immediately, swapping "require" with the actual require function
609 | */
610 | return callback.apply(root, _swapValues(modules, {"require" : require}));
611 | }
612 |
613 | /**
614 | * Configure NeedsJS, possible configuration properties are:
615 | *
616 | * - baseUrl
617 | * - urlArgs
618 | * - waitSeconds
619 | */
620 | require.config = function (obj) {
621 | _config = obj || {};
622 |
623 | _baseUrl = _config.baseUrl || _baseUrl;
624 | // Add a trailing slash to baseUrl if needed.
625 | _baseUrl += (_baseUrl && _baseUrl.charAt(_baseUrl.length-1) !== "/") ? "/" : "";
626 |
627 | _urlArgs = _config.urlArgs ? "?" + _config.urlArgs : _urlArgs;
628 |
629 | _waitSeconds = _config.waitSeconds || _waitSeconds;
630 |
631 | for (var p in _config.paths) {
632 | _paths[p] = _config.paths[p];
633 | }
634 | };
635 |
636 | /**
637 | * Get a url for a relative id.
638 | * You do not need to specify `context` if calling this from within a define() call,
639 | * or a localized version of require();
640 | */
641 | require.toUrl = function (id, context) {
642 | return _getURL(_resolve(id, context));
643 | };
644 |
645 | /**
646 | * Returns a localized version of require, so that modules do not need
647 | * to specify their own id, when requiring relative modules, or resolving relative urls.
648 | */
649 | require.localize = function (context) {
650 |
651 | function localRequire (ids, callback) {
652 | return require(ids, callback, context);
653 | }
654 |
655 | localRequire.toUrl = function (id) {
656 | return require.toUrl(id, context);
657 | };
658 |
659 | return localRequire;
660 | };
661 |
662 | /**
663 | * Define global define/require methods, unless they are already defined.
664 | */
665 | root.define = root.define || define;
666 | root.require = root.require || require;
667 |
668 | /**
669 | * If we're in a browser environment use window as the root object
670 | * Otherwise, assume we're in a CommonJS environment and use exports
671 | */
672 | })(window || exports);
673 |
--------------------------------------------------------------------------------
/impl/lsjs/lsjs.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
4 | see: http://dojotoolkit.org/license for details
5 | */
6 |
7 | var require;
8 | var define;
9 |
10 | (function () {
11 | /* These regexs are taken from requirejs */
12 | var commentRegExp = /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg;
13 | /* Based on the cjs regexs in requirejs, modified slightly */
14 | var cjsRequireRegExp = /[^\d\w\.]require\(["']([^'"\s]+)["']\)/g;
15 | var cjsVarPrefixRegExp = /^~#/;
16 | var pluginRegExp = /.+!/;
17 |
18 | Iterator = function(array) {
19 | this.array = array;
20 | this.current = 0;
21 | };
22 |
23 | Iterator.prototype = {
24 | hasMore: function() {
25 | return this.current < this.array.length;
26 | },
27 | next: function() {
28 | return this.array[this.current++];
29 | }
30 | };
31 |
32 | lsImpl = {
33 | isSupported: function() {
34 | try {
35 | return 'localStorage' in window && window['localStorage'] !== null;
36 | } catch (e) {
37 | return false;
38 | }
39 | },
40 | remove: function(key, handler, errorHandler) {
41 | try {
42 | var json = localStorage[key];
43 | if (json !== undefined && json !== null) {
44 | var value = JSON.parse(json);
45 | localStorage.removeItem(key);
46 | if (handler) {
47 | handler(value);
48 | }
49 | } else {
50 | if (errorHandler) {
51 | errorHandler("Failed to remove value in local storage ["+key+"]");
52 | } else {
53 | console.log("Failed to remove value in local storage ["+key+"]");
54 | }
55 | }
56 | } catch(e) {
57 | if (errorHandler) {
58 | errorHandler(e);
59 | } else {
60 | console.log("Failed to remove value in local storage ["+key+"] : "+e);
61 | }
62 | }
63 | },
64 | get: function(key, handler, errorHandler) {
65 | try {
66 | var json = localStorage[key];
67 | if (json !== undefined && json !== null) {
68 | var value = JSON.parse(json);
69 | handler(value);
70 | } else {
71 | if (errorHandler) {
72 | errorHandler("Failed to get value in local storage ["+key+"]");
73 | } else {
74 | console.log("Failed to get value in local storage ["+key+"]");
75 | }
76 | }
77 | } catch(e) {
78 | if (errorHandler) {
79 | errorHandler(e);
80 | } else {
81 | console.log("Failed to get value in local storage ["+key+"] : "+e);
82 | }
83 | }
84 | },
85 | set: function(key, entry, handler, errorHandler) {
86 | try {
87 | localStorage[key] = JSON.stringify(entry);
88 | if (handler) {
89 | handler(true);
90 | }
91 | } catch (e) {
92 | if (errorHandler) {
93 | errorHandler(e);
94 | } else {
95 | console.log("Failed to set value in local storage ["+key+"] : "+e);
96 | }
97 | }
98 | }
99 | };
100 |
101 | var modules = {};
102 | var moduleStack = [];
103 | var paths = {};
104 | var pkgs = {};
105 | var reload = {};
106 | var storage = lsImpl;
107 | var loaded = {};
108 | var cache = {};
109 | var cachets = {};
110 | var usesCache = {};
111 | var cblist = {};
112 | var strands = [];
113 | var circRefs = {};
114 |
115 | var geval = window.execScript || eval;
116 |
117 | var opts = Object.prototype.toString;
118 |
119 | function isFunction(it) { return opts.call(it) === "[object Function]"; };
120 | function isArray(it) { return opts.call(it) === "[object Array]"; };
121 | function isString(it) { return (typeof it == "string" || it instanceof String); };
122 |
123 | function _getCurrentId() {
124 | return moduleStack.length > 0 ? moduleStack[moduleStack.length-1].id : "";
125 | }
126 |
127 | function _normalize(path) {
128 | var segments = path.split('/');
129 | var skip = 0;
130 |
131 | for (var i = (segments.length-1); i >= 0; i--) {
132 | var segment = segments[i];
133 | if (segment === '.') {
134 | segments.splice(i, 1);
135 | } else if (segment === '..') {
136 | segments.splice(i, 1);
137 | skip++;
138 | } else if (skip) {
139 | segments.splice(i, 1);
140 | skip--;
141 | }
142 | }
143 | return segments.join('/');
144 | };
145 |
146 | function _expand(path) {
147 | var isRelative = path.search(/^\./) === -1 ? false : true;
148 | if (isRelative) {
149 | var pkg;
150 | if ((pkg = pkgs[_getCurrentId()])) {
151 | path = pkg.name + "/" + path;
152 | } else {
153 | path = _getCurrentId() + "/../" + path;
154 | }
155 | path = _normalize(path);
156 | }
157 | return path;
158 | };
159 |
160 | function _idToUrl(path) {
161 | var segments = path.split("/");
162 | for (var i = segments.length; i >= 0; i--) {
163 | var pkg;
164 | var parent = segments.slice(0, i).join("/");
165 | if (paths[parent]) {
166 | segments.splice(0, i, paths[parent]);
167 | break;
168 | }else if ((pkg = pkgs[parent])) {
169 | var pkgPath;
170 | if (path === pkg.name) {
171 | pkgPath = pkg.location + '/' + pkg.main;
172 | } else {
173 | pkgPath = pkg.location;
174 | }
175 | segments.splice(0, i, pkgPath);
176 | break;
177 | }
178 | }
179 | path = segments.join("/");
180 | if (path.charAt(0) !== '/') {
181 | path = cfg.baseUrl + path;
182 | }
183 | path = _normalize(path);
184 | return path;
185 | };
186 |
187 | function fireZazlLoadEvent() {
188 | var evt = document.createEvent('Events');
189 | evt.initEvent('zazlload', true, false);
190 | document.documentElement.dispatchEvent(evt);
191 | };
192 |
193 | function _loadModule(id, cb, scriptText) {
194 | var expandedId = _expand(id);
195 | var dependentId = _getCurrentId();
196 | if (cblist[expandedId] === undefined) {
197 | cblist[expandedId] = [];
198 | }
199 | if (modules[expandedId] !== undefined) {
200 | processModules();
201 | if (modules[expandedId].loaded) {
202 | var savedStack;
203 | if (dependentId !== "") {
204 | var root = modules[dependentId];
205 | savedStack = moduleStack;
206 | moduleStack = [root];
207 | }
208 | cb(modules[expandedId].exports);
209 | if (dependentId !== "") {
210 | moduleStack = savedStack;
211 | }
212 | } else {
213 | cblist[expandedId].push({cb:cb, mid:dependentId});
214 | }
215 | return;
216 | }
217 | modules[expandedId] = {id: expandedId, exports: {}};
218 |
219 | var url = _idToUrl(expandedId);
220 | url += ".js";
221 |
222 | var storedModule;
223 | function _load() {
224 | if (scriptText) {
225 | _inject(expandedId, dependentId, cb, scriptText);
226 | } else if (storedModule === undefined || storedModule === null) {
227 | _getModule(url, function(_url, scriptSrc, ts) {
228 | var entry = {url: _url, timestamp: ts};
229 | loaded[_url] = ts;
230 | storage.set("loaded!"+window.location.pathname, loaded);
231 | storage.set(_url, {src: scriptSrc, timestamp: ts});
232 | _inject(expandedId, dependentId, cb, scriptSrc);
233 | });
234 | } else {
235 | _inject(expandedId, dependentId, cb, storedModule.src);
236 | }
237 | };
238 | if (cfg.forceLoad || url in reload) {
239 | storage.remove(url, function(){
240 | _load();
241 | });
242 | } else {
243 | storage.get(url, function(value) {
244 | storedModule = value;
245 | _load();
246 | }, function(error){
247 | _load();
248 | });
249 | }
250 | };
251 |
252 | function _inject(moduleId, dependentId, cb, scriptSrc) {
253 | var module = modules[moduleId];
254 | moduleStack.push(module);
255 | if (cfg.injectViaScriptTag) {
256 | var script = document.createElement('script');
257 | script.type = "text/javascript";
258 | script.charset = "utf-8";
259 | var scriptContent = document.createTextNode(scriptSrc);
260 | script.appendChild(scriptContent);
261 | document.getElementsByTagName("head")[0].appendChild(script);
262 | } else {
263 | geval(scriptSrc+"//@ sourceURL="+module.id);
264 | }
265 | _loadModuleDependencies(module.id, function(){
266 | moduleStack.pop();
267 | cblist[moduleId].push({cb:cb, mid:dependentId});
268 | if (pageLoaded) {
269 | fireZazlLoadEvent();
270 | }
271 | });
272 | };
273 |
274 | function _getModule(url, cb) {
275 | var xhr = new XMLHttpRequest();
276 | xhr.open("GET", url+"?nocache="+new Date().valueOf(), true);
277 | xhr.onreadystatechange = function() {
278 | if (xhr.readyState == 4) {
279 | if (xhr.status == 200) {
280 | cb(url, xhr.responseText, xhr.getResponseHeader("Last-Modified"));
281 | } else {
282 | throw new Error("Unable to load ["+url+"]:"+xhr.status);
283 | }
284 | }
285 | };
286 | xhr.send(null);
287 | };
288 |
289 | function _loadModuleDependencies(id, cb) {
290 | var m = modules[id];
291 | m.args = [];
292 | m.deploaded = {};
293 | var idx = 0;
294 | var iterate = function(itr) {
295 | if (itr.hasMore()) {
296 | var dependency = itr.next();
297 | var argIdx = idx++;
298 | var depname;
299 | if (dependency.match(pluginRegExp)) {
300 | var add = true;
301 | if (dependency.match(cjsVarPrefixRegExp)) {
302 | dependency = dependency.substring(2);
303 | add = false;
304 | }
305 | var pluginName = dependency.substring(0, dependency.indexOf('!'));
306 | pluginName = _expand(pluginName);
307 | var pluginModuleName = dependency.substring(dependency.indexOf('!')+1);
308 | if (add) {
309 | m.dependencies[argIdx] = pluginName + "!"+pluginModuleName;
310 | m.args[argIdx] = undefined;
311 | depname = pluginName + "!"+pluginModuleName;
312 | } else {
313 | depname = "~#"+pluginName + "!"+pluginModuleName;
314 | }
315 | m.deploaded[depname] = false;
316 | _loadPlugin(pluginName, pluginModuleName, function(pluginInstance) {
317 | if (add) {
318 | m.args[argIdx] = pluginInstance;
319 | }
320 | m.deploaded[depname] = true;
321 | });
322 | iterate(itr);
323 | } else if (dependency === 'require') {
324 | m.args[argIdx] = _createRequire(_getCurrentId());
325 | m.deploaded['require'] = true;
326 | iterate(itr);
327 | } else if (dependency === 'module') {
328 | m.args[argIdx] = m;
329 | m.deploaded['module'] = true;
330 | iterate(itr);
331 | } else if (dependency === 'exports') {
332 | m.args[argIdx] = m.exports;
333 | m.deploaded['exports'] = true;
334 | iterate(itr);
335 | } else {
336 | var add = true;
337 | if (dependency.match(cjsVarPrefixRegExp)) {
338 | dependency = dependency.substring(2);
339 | add = false;
340 | }
341 | var expandedId = _expand(dependency);
342 | if (add) {
343 | m.dependencies[argIdx] = expandedId;
344 | m.args[argIdx] = modules[expandedId] === undefined ? undefined : modules[expandedId].exports;
345 | depname = expandedId;
346 | } else {
347 | depname = "~#"+expandedId;
348 | }
349 | m.deploaded[depname] = false;
350 | _loadModule(dependency, function(module){
351 | if (add) {
352 | m.args[argIdx] = module;
353 | }
354 | m.deploaded[depname] = true;
355 | });
356 | iterate(itr);
357 | }
358 | } else {
359 | m.cjsreq = _createRequire(_getCurrentId());
360 | cb();
361 | }
362 | };
363 | iterate(new Iterator(m.dependencies));
364 | };
365 |
366 | function _loadPlugin(pluginName, pluginModuleName, cb) {
367 | _loadModule(pluginName, function(plugin){
368 | if (plugin.normalize) {
369 | pluginModuleName = plugin.normalize(pluginModuleName, _expand);
370 | } else {
371 | pluginModuleName = _expand(pluginModuleName);
372 | }
373 | var isDynamic = plugin.dynamic || false;
374 | if (modules[pluginName+"!"+pluginModuleName] !== undefined && !isDynamic) {
375 | cb(modules[pluginName+"!"+pluginModuleName].exports);
376 | return;
377 | }
378 | var req = _createRequire(pluginName);
379 | var load = function(pluginInstance){
380 | if (pluginInstance === undefined) {
381 | pluginInstance = null;
382 | }
383 | modules[pluginName+"!"+pluginModuleName] = {};
384 | modules[pluginName+"!"+pluginModuleName].exports = pluginInstance;
385 | if (pluginName in usesCache) {
386 | var url = _idToUrl(pluginModuleName);
387 | if (cache[url] === undefined || url in reload) {
388 | _getLastModified(url, function(lastModified){
389 | if (lastModified) {
390 | cachets[url] = lastModified;
391 | _storeCache();
392 | }
393 | });
394 | cache[url] = pluginInstance;
395 | _storeCache();
396 | }
397 | }
398 | cb(pluginInstance);
399 | };
400 | load.fromText = function(name, text) {
401 | _loadModule(name, function(){}, text);
402 | };
403 | plugin.load(pluginModuleName, req, load, cfg);
404 | });
405 | };
406 |
407 | function _createRequire(id) {
408 | var req = function(dependencies, callback) {
409 | var root = modules[id];
410 | var savedStack = moduleStack;
411 | moduleStack = [root];
412 | if (isArray(dependencies)) {
413 | for (var i = 0; i < dependencies.length; i++) {
414 | if (dependencies[i] !== 'exports' && dependencies[i] != 'module' && dependencies[i] !== 'require') {
415 | strands[dependencies[i]] = false;
416 | }
417 | }
418 | } else if (isString(dependencies)) {
419 | if (dependencies !== 'exports' && dependencies != 'module' && dependencies !== 'require') {
420 | strands[dependencies] = false;
421 | }
422 | }
423 | if (isFunction(callback)) {
424 | _require(dependencies, function() {
425 | moduleStack = savedStack;
426 | callback.apply(null, arguments);
427 | });
428 | } else {
429 | var mod = _require(dependencies, callback);
430 | moduleStack = savedStack;
431 | return mod;
432 | }
433 | };
434 | req.toUrl = function(moduleResource) {
435 | var url = _idToUrl(_expand(moduleResource));
436 | return url;
437 | };
438 | req.defined = function(moduleName) {
439 | return _expand(moduleName) in modules;
440 | };
441 | req.specified = function(moduleName) {
442 | return _expand(moduleName) in modules;
443 | };
444 | req.ready = function(callback) {
445 | if (pageLoaded) {
446 | callback();
447 | } else {
448 | readyCallbacks.push(callback);
449 | }
450 | };
451 | req.nameToUrl = function(moduleName, ext, relModuleMap) {
452 | return moduleName + ext;
453 | };
454 | // Dojo specific require properties and functions
455 | req.cache = cache;
456 | req.toAbsMid = function(id) {
457 | return _expand(id);
458 | };
459 | req.isXdUrl = function(url) {
460 | return false;
461 | };
462 | return req;
463 | };
464 |
465 | function _getTimestamps(timestampUrl, cb) {
466 | var xhr = new XMLHttpRequest();
467 | xhr.open("POST", timestampUrl, true);
468 | xhr.setRequestHeader("Content-Type", "application/json");
469 |
470 | xhr.onreadystatechange = function() {
471 | if (xhr.readyState == 4) {
472 | if (xhr.status == 200) {
473 | var urlsToReload = JSON.parse(xhr.responseText);
474 | for (var i = 0; i < urlsToReload.length; i++) {
475 | reload[urlsToReload[i]] = urlsToReload[i];
476 | }
477 | cb();
478 | } else {
479 | throw new Error("Unable to get timestamps via the url ["+timestampUrl+"]:"+xhr.status);
480 | }
481 | }
482 | };
483 | var current = [];
484 | var url;
485 |
486 | for (url in loaded) {
487 | current.push({url: url, timestamp: loaded[url]});
488 | }
489 | for (url in cachets) {
490 | current.push({url: url, timestamp: cachets[url]});
491 | }
492 | xhr.send(JSON.stringify(current));
493 | };
494 |
495 | function _getLastModified(url, cb) {
496 | var xhr = new XMLHttpRequest();
497 | xhr.open("HEAD", url, true);
498 | xhr.onreadystatechange = function() {
499 | if (xhr.readyState == 4) {
500 | if (xhr.status == 200) {
501 | cb(xhr.getResponseHeader("Last-Modified"));
502 | } else {
503 | cb();
504 | }
505 | }
506 | };
507 | xhr.send(null);
508 | };
509 |
510 | function _storeCache() {
511 | var storedCache = {};
512 | for (var url in cache) {
513 | storedCache[url] = {value: cache[url], timestamp: cachets[url]};
514 | }
515 | storage.set("cache!"+window.location.pathname, storedCache);
516 | };
517 |
518 | define = function (id, dependencies, factory) {
519 | var simpleCJS = false;
520 | if (!isString(id)) {
521 | factory = dependencies;
522 | dependencies = id;
523 | id = _getCurrentId();
524 | }
525 | if (!isArray(dependencies)) {
526 | simpleCJS = true;
527 | factory = dependencies;
528 | dependencies = [];
529 | }
530 | if (!modules[id]) {
531 | var args = [];
532 | if (!simpleCJS) {
533 | args= undefined;
534 | }
535 | modules[id] = {id: id, exports: {}, cjsreq: _createRequire(id), args: args};
536 | }
537 | if (isFunction(factory)) {
538 | if (simpleCJS) {
539 | factory.toString().replace(commentRegExp, "").replace(cjsRequireRegExp, function (match, dep) {
540 | dependencies.push("~#"+dep);
541 | });
542 | }
543 | modules[id].factory = factory;
544 | } else {
545 | modules[id].literal = factory;
546 | }
547 | modules[id].dependencies = dependencies;
548 | };
549 |
550 | define.amd = {
551 | plugins: true,
552 | jQuery: true
553 | };
554 |
555 | _require = function (dependencies, callback) {
556 | if (isString(dependencies)) {
557 | var id = dependencies;
558 | id = _expand(id);
559 | if (id.match(pluginRegExp)) {
560 | var pluginName = id.substring(0, id.indexOf('!'));
561 | pluginName = _expand(pluginName);
562 | var plugin = modules[pluginName].exports;
563 | var pluginModuleName = id.substring(id.indexOf('!')+1);
564 | if (plugin.normalize) {
565 | pluginModuleName = plugin.normalize(pluginModuleName, function(path){
566 | return _expand(path);
567 | });
568 | } else {
569 | pluginModuleName = _expand(pluginModuleName);
570 | }
571 | id = pluginName+"!"+pluginModuleName;
572 | }
573 | if (modules[id] === undefined) {
574 | throw new Error("Module ["+id+"] has not been loaded");
575 | }
576 | return modules[id].exports;
577 | } else if (isArray(dependencies)) {
578 | var args = [];
579 | var iterate = function(itr) {
580 | if (itr.hasMore()) {
581 | var dependency = itr.next();
582 | if (dependency.match(pluginRegExp)) {
583 | var pluginName = dependency.substring(0, dependency.indexOf('!'));
584 | pluginName = _expand(pluginName);
585 | var pluginModuleName = dependency.substring(dependency.indexOf('!')+1);
586 | _loadPlugin(pluginName, pluginModuleName, function(pluginInstance) {
587 | args.push(pluginInstance);
588 | iterate(itr);
589 | });
590 | } else {
591 | _loadModule(dependency, function(module){
592 | args.push(module);
593 | iterate(itr);
594 | });
595 | }
596 | } else if (callback !== undefined) {
597 | callback.apply(null, args);
598 | }
599 | };
600 | iterate(new Iterator(dependencies));
601 | return undefined;
602 | }
603 | };
604 |
605 | modules["require"] = {};
606 | modules["require"].exports = _require;
607 | modules["require"].loaded = true;
608 |
609 | var cfg;
610 |
611 | function processConfig(config) {
612 | if (!cfg) {
613 | var i;
614 | cfg = config || {};
615 | if (cfg.paths) {
616 | for (var p in cfg.paths) {
617 | var path = cfg.paths[p];
618 | paths[p] = path;
619 | }
620 | }
621 | if (cfg.packages) {
622 | for (i = 0; i < cfg.packages.length; i++) {
623 | var pkg = cfg.packages[i];
624 | if (!pkg.location) {
625 | pkg.location = pkg.name;
626 | }
627 | if (!pkg.main) {
628 | pkg.main = "main";
629 | }
630 | pkgs[pkg.name] = pkg;
631 | }
632 | }
633 |
634 | if (cfg.storageImpl) {
635 | storage = cfg.storageImpl;
636 | var requiredProps = ["get", "set", "remove", "isSupported"];
637 | for (i = 0; i < requiredProps.length; i++) {
638 | if (!storage[requiredProps[i]]) {
639 | throw new Error("Storage implementation must implement ["+requiredProps[i]+"]");
640 | }
641 | }
642 | }
643 |
644 | if (cfg.usesCache) {
645 | for (i = 0; i < cfg.usesCache.length; i++) {
646 | usesCache[cfg.usesCache[i]] = true;
647 | }
648 | }
649 |
650 | cfg.baseUrl = cfg.baseUrl || "./";
651 |
652 | if (cfg.baseUrl.charAt(0) !== '/' && !cfg.baseUrl.match(/^[\w\+\.\-]+:/)) {
653 | cfg.baseUrl = _normalize(window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/'+ cfg.baseUrl);
654 | }
655 | }
656 | };
657 |
658 | lsjs = function(config, dependencies, callback) {
659 | if (!isArray(config) && typeof config == "object") {
660 | processConfig(config);
661 | } else {
662 | callback = dependencies;
663 | dependencies = config;
664 | processConfig(typeof lsjsConfig === 'undefined' ? {} : lsjsConfig);
665 | }
666 |
667 | if (!storage.isSupported()) {
668 | throw new Error("Storage implementation is unsupported");
669 | }
670 |
671 | storage.get("loaded!"+window.location.pathname, function(value){
672 | loaded = value;
673 | }, function(error){});
674 |
675 | storage.get("cache!"+window.location.pathname, function(storedcache) {
676 | for (var url in storedcache) {
677 | cache[url] = storedcache[url].value;
678 | cachets[url] = storedcache[url].timestamp;
679 | }
680 | }, function(error){});
681 |
682 | if (!isArray(dependencies)) {
683 | callback = dependencies;
684 | dependencies = [];
685 | }
686 | function callRequire(dependencies, callback) {
687 | for (var i = 0; i < dependencies.length; i++) {
688 | if (dependencies[i] !== 'exports' && dependencies[i] != 'module' && dependencies[i] !== 'require') {
689 | strands[dependencies[i]] = false;
690 | }
691 | }
692 | if (isFunction(callback)) {
693 | _require(dependencies, function() {
694 | callback.apply(null, arguments);
695 | });
696 | } else {
697 | _require(dependencies);
698 | }
699 | queueProcessor();
700 | };
701 | if (cfg.timestampUrl) {
702 | _getTimestamps(cfg.timestampUrl, function(){
703 | callRequire(dependencies, callback);
704 | });
705 | } else {
706 | callRequire(dependencies, callback);
707 | }
708 | };
709 |
710 | var pageLoaded = false;
711 | var modulesLoaded = false;
712 | var domLoaded = false;
713 | var readyCallbacks = [];
714 |
715 | document.addEventListener("DOMContentLoaded", function() {
716 | domLoaded = true;
717 | }, false);
718 |
719 | if (!require) {
720 | require = lsjs;
721 | require.toUrl = function(moduleResource) {
722 | var url = _idToUrl(_expand(moduleResource));
723 | return url;
724 | };
725 | }
726 |
727 | function queueProcessor() {
728 | var poller = function() {
729 | if (processQueues()) { return; }
730 | setTimeout(poller, 0);
731 | };
732 | poller();
733 | };
734 |
735 | function processCallbacks() {
736 | var savedStack;
737 |
738 | var cbiterate = function(exports, itr) {
739 | if (itr.hasMore()) {
740 | var cbinst = itr.next();
741 | if (cbinst.mid !== "") {
742 | var root = modules[cbinst.mid];
743 | savedStack = moduleStack;
744 | moduleStack = [root];
745 | }
746 | cbinst.cb(exports);
747 | if (cbinst.mid !== "") {
748 | moduleStack = savedStack;
749 | }
750 | cbiterate(exports, itr);
751 | } else {
752 | delete cblist[mid];
753 | }
754 | };
755 | for (mid in cblist) {
756 | if (modules[mid].loaded) {
757 | cbiterate(modules[mid].exports, new Iterator(cblist[mid]));
758 | }
759 | }
760 | };
761 |
762 | function processModules() {
763 | var isCircular = function(id, module) {
764 | return circRefs[module.id] && circRefs[module.id].refs[id] ? true : false;
765 | };
766 |
767 | var isComplete = function(module) {
768 | var complete = false;
769 | if (module.cjsreq) {
770 | complete = true;
771 | for (var dep in module.deploaded) {
772 | var iscjs = dep.match(cjsVarPrefixRegExp);
773 | if (module.deploaded[dep] === false && isCircular(iscjs ? dep.substring(2) : dep, module) === false) {
774 | complete = false;
775 | break;
776 | }
777 | }
778 | }
779 | return complete;
780 | };
781 |
782 | var allLoaded = true;
783 | var mid, m;
784 | for (mid in modules) {
785 | m = modules[mid];
786 | if (!m || m.loaded !== true && !mid.match(pluginRegExp)) {
787 | allLoaded = false;
788 | }
789 | if (mid !== "require") {
790 | if (m.loaded !== true && isComplete(m)) {
791 | if (m.factory !== undefined) {
792 | if (m.args && m.args.length < 1) {
793 | m.args = m.args.concat(m.cjsreq, m.exports, m);
794 | }
795 | var ret = m.factory.apply(null, m.args);
796 | if (ret) {
797 | m.exports = ret;
798 | }
799 | } else {
800 | m.exports = m.literal;
801 | }
802 | m.loaded = true;
803 | }
804 | }
805 | }
806 | return allLoaded;
807 | };
808 |
809 | function processStrands() {
810 | function findCircRefs(id, seen, scanned) {
811 | if (id.match(pluginRegExp)) {
812 | return true;
813 | }
814 | var module = modules[id];
815 | var complete = false;
816 | if (module && module.cjsreq) {
817 | seen.push(module.id);
818 | complete = true;
819 | for (var dep in module.deploaded) {
820 | if (dep !== 'exports' && dep != 'module' && dep !== 'require') {
821 | if (scanned[dep] !== undefined) {
822 | continue;
823 | }
824 | var iscjs = dep.match(cjsVarPrefixRegExp);
825 | var found = false;
826 | var dup;
827 | for (var i = 0; i < seen.length; i++) {
828 | if (seen[i] === (iscjs ? dep.substring(2) : dep)) {
829 | found = true;
830 | dup = dep;
831 | break;
832 | }
833 | }
834 | if (found) {
835 | if (circRefs[module.id] === undefined) {
836 | circRefs[module.id] = {refs: {}};
837 | }
838 | circRefs[module.id].refs[iscjs ? dep.substring(2) : dep] = dep;
839 | } else {
840 | complete = findCircRefs(iscjs ? dep.substring(2) : dep, seen, scanned);
841 | }
842 | }
843 | }
844 | scanned[module.id] = true;
845 | seen.pop();
846 | }
847 | return complete;
848 | }
849 |
850 | for (var id in strands) {
851 | strands[id] = findCircRefs(id, [], {});
852 | }
853 | };
854 |
855 | function processQueues() {
856 | try {
857 | processCallbacks();
858 | var allLoaded = processModules();
859 | if (allLoaded) {
860 | modulesLoaded = true;
861 | }
862 | processStrands();
863 | processCallbacks();
864 | if (!pageLoaded && domLoaded && modulesLoaded) {
865 | pageLoaded = true;
866 | for (var i = 0; i < readyCallbacks.length; i++) {
867 | readyCallbacks[i]();
868 | }
869 | document.addEventListener("zazlload", function() {
870 | if (!processModules()) {
871 | queueProcessor();
872 | }
873 | }, false);
874 | }
875 | } catch (e) {
876 | console.log("queueProcessor error : "+e);
877 | allLoaded = true;
878 | }
879 | return allLoaded;
880 | };
881 | }());
882 |
--------------------------------------------------------------------------------