├── tests ├── node │ ├── syncCall │ │ ├── b.js │ │ ├── a.js │ │ ├── foo.js │ │ ├── main2.js │ │ ├── main1.js │ │ └── plug.js │ ├── embedded │ │ ├── coffee │ │ │ └── foo.coffee │ │ ├── main.js │ │ ├── scripts │ │ │ └── bar.js │ │ └── README.md │ ├── tests │ │ ├── foo.js │ │ ├── alpha │ │ │ ├── foo.js │ │ │ └── hello.html │ │ └── server.js │ ├── pluginLocalId │ │ ├── lib │ │ │ ├── app │ │ │ │ ├── dep.coffee │ │ │ │ └── test.coffee │ │ │ └── cs.js │ │ └── test.js │ ├── nodeRelative │ │ ├── other │ │ │ ├── lib │ │ │ │ └── light.js │ │ │ └── src │ │ │ │ └── lamp.js │ │ └── main.js │ ├── syncMap │ │ ├── jquery.js │ │ ├── cheerio.js │ │ └── syncMap.js │ ├── syncRequire │ │ ├── b.js │ │ ├── a.js │ │ └── main.js │ └── index.js ├── browser │ ├── c.js │ ├── sub │ │ └── d.js │ ├── a.js │ ├── b.js │ ├── r-worker.js │ ├── r.html │ └── r-worker.html ├── alljnashorn.sh ├── rhino │ ├── a.js │ ├── main.js │ ├── run.sh │ ├── build.sh │ ├── run.js │ └── build.js ├── xpcshell │ ├── a.js │ ├── run.sh │ ├── build.sh │ ├── main.js │ ├── run.js │ └── build.js ├── sub │ └── betaSub.js ├── allNode.js ├── alpha.js ├── doh │ ├── runner.sh │ ├── small_logo.png │ ├── _sounds │ │ ├── doh.wav │ │ ├── dohaaa.wav │ │ ├── woohoo.wav │ │ └── LICENSE │ ├── _rhinoRunner.js │ ├── README │ ├── _nodeRunner.js │ ├── _xpconnectRunner.js │ ├── runner.html │ ├── LICENSE │ ├── _browserRunner.js │ └── runner.js ├── allj.sh ├── beta.js ├── alln.sh ├── relative.js └── all.js ├── lib ├── rhino │ ├── js.jar │ └── LICENSE └── closure │ ├── compiler.jar │ ├── COPYING │ └── README.md ├── tasks.txt ├── package.json ├── dist └── README.md ├── copydist.js ├── LICENSE ├── dist.js ├── .gitignore └── README.md /tests/node/syncCall/b.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/browser/c.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'c' 3 | }); -------------------------------------------------------------------------------- /tests/alljnashorn.sh: -------------------------------------------------------------------------------- 1 | jjs -scripting ../r.js -- all.js 2 | -------------------------------------------------------------------------------- /tests/rhino/a.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'a' 3 | }); 4 | 5 | -------------------------------------------------------------------------------- /tests/node/embedded/coffee/foo.coffee: -------------------------------------------------------------------------------- 1 | exports.name ='foo' 2 | -------------------------------------------------------------------------------- /tests/xpcshell/a.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'a' 3 | }); 4 | 5 | -------------------------------------------------------------------------------- /tests/browser/sub/d.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'd' 3 | }); 4 | 5 | -------------------------------------------------------------------------------- /tests/node/tests/foo.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'foo' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/sub/betaSub.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'betaSubName' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/node/pluginLocalId/lib/app/dep.coffee: -------------------------------------------------------------------------------- 1 | define (require) -> 2 | 'dep' -------------------------------------------------------------------------------- /tests/xpcshell/run.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | ../../env/xpcshell/xpcshell run.js 4 | -------------------------------------------------------------------------------- /tests/node/syncCall/a.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'a (should be uppercase)' 3 | }); -------------------------------------------------------------------------------- /tests/xpcshell/build.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | ../../env/xpcshell/xpcshell build.js 4 | -------------------------------------------------------------------------------- /lib/rhino/js.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelhelmick/r.js/HEAD/lib/rhino/js.jar -------------------------------------------------------------------------------- /tasks.txt: -------------------------------------------------------------------------------- 1 | * Need more docs on optimizeAllPluginResources? 2 | * allow for npm install -------------------------------------------------------------------------------- /tests/allNode.js: -------------------------------------------------------------------------------- 1 | var requirejs = require('../r.js'); 2 | 3 | requirejs(['./all']); 4 | -------------------------------------------------------------------------------- /tests/alpha.js: -------------------------------------------------------------------------------- 1 | define(function(require, exports) { 2 | exports.name = 'alpha'; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/doh/runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | java -jar ../../build/lib/rhino/js.jar runner.js "$@" 4 | -------------------------------------------------------------------------------- /tests/node/nodeRelative/other/lib/light.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'light' 3 | }; 4 | -------------------------------------------------------------------------------- /tests/node/pluginLocalId/lib/app/test.coffee: -------------------------------------------------------------------------------- 1 | define (require) -> 2 | require 'coffee!./dep' 3 | -------------------------------------------------------------------------------- /lib/closure/compiler.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelhelmick/r.js/HEAD/lib/closure/compiler.jar -------------------------------------------------------------------------------- /tests/doh/small_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelhelmick/r.js/HEAD/tests/doh/small_logo.png -------------------------------------------------------------------------------- /tests/doh/_sounds/doh.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelhelmick/r.js/HEAD/tests/doh/_sounds/doh.wav -------------------------------------------------------------------------------- /tests/node/syncMap/jquery.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | return function () { return 'jquery'; }; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/doh/_sounds/dohaaa.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelhelmick/r.js/HEAD/tests/doh/_sounds/dohaaa.wav -------------------------------------------------------------------------------- /tests/doh/_sounds/woohoo.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelhelmick/r.js/HEAD/tests/doh/_sounds/woohoo.wav -------------------------------------------------------------------------------- /tests/node/syncMap/cheerio.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | return function () { return 'cheerio'; }; 3 | }); 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "volo": { 3 | "url": "https://raw.github.com/jrburke/r.js/{version}/dist/r.js" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/node/syncCall/foo.js: -------------------------------------------------------------------------------- 1 | define(['plug!a'], function (a) { 2 | return { 3 | name: 'foo', 4 | a: a 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/rhino/main.js: -------------------------------------------------------------------------------- 1 | define(['a'], function (a) { 2 | return { 3 | name: 'main', 4 | a: a 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/allj.sh: -------------------------------------------------------------------------------- 1 | java -classpath ../lib/rhino/js.jar:../lib/closure.compiler.jar org.mozilla.javascript.tools.shell.Main ../r.js all.js 2 | -------------------------------------------------------------------------------- /tests/xpcshell/main.js: -------------------------------------------------------------------------------- 1 | define(['a'], function (a) { 2 | return { 3 | name: 'main', 4 | a: a 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/browser/a.js: -------------------------------------------------------------------------------- 1 | define(['b', 'c'], function (b, c) { 2 | return { 3 | name: 'a', 4 | b: b, 5 | c: c 6 | }; 7 | }); 8 | -------------------------------------------------------------------------------- /tests/browser/b.js: -------------------------------------------------------------------------------- 1 | define(['c', 'd'], function (c, d) { 2 | return { 3 | name: 'b', 4 | c: c, 5 | d: d 6 | }; 7 | }); 8 | -------------------------------------------------------------------------------- /tests/rhino/run.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | java -classpath ../../lib/rhino/js.jar:../../lib/closure.compiler.jar org.mozilla.javascript.tools.shell.Main run.js 4 | -------------------------------------------------------------------------------- /tests/beta.js: -------------------------------------------------------------------------------- 1 | define(['./sub/betaSub'], function (betaSub) { 2 | return { 3 | name: 'beta', 4 | subName: betaSub.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/rhino/build.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | java -classpath ../../lib/rhino/js.jar:../../lib/closure.compiler.jar org.mozilla.javascript.tools.shell.Main build.js 4 | -------------------------------------------------------------------------------- /tests/node/tests/alpha/foo.js: -------------------------------------------------------------------------------- 1 | define(function (require) { 2 | var foo = require('../foo'); 3 | return { 4 | name: 'ALPHA' + foo.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/node/syncCall/main2.js: -------------------------------------------------------------------------------- 1 | var requirejs = require('../../../r.js'), 2 | a = requirejs('plug!a'); 3 | 4 | console.log('"A (SHOULD BE UPPERCASE)" === "' + a.name + '"'); 5 | -------------------------------------------------------------------------------- /tests/alln.sh: -------------------------------------------------------------------------------- 1 | node allNode.js 2 | node ../r.js all.js 3 | node node/syncMap/syncMap.js 4 | node node/pluginLocalId/test.js 5 | node node/syncRequire/main.js 6 | node node/nodeRelative/main.js -------------------------------------------------------------------------------- /tests/node/tests/alpha/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World 5 | 6 | 7 |

Hello World

8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/node/nodeRelative/other/src/lamp.js: -------------------------------------------------------------------------------- 1 | //Load a node lib that is relative. 2 | define(['../lib/light'], function (light) { 3 | return { 4 | name: 'lamp', 5 | light: light 6 | }; 7 | }); 8 | -------------------------------------------------------------------------------- /tests/node/syncRequire/b.js: -------------------------------------------------------------------------------- 1 | define(['require', 'a'], function (require) { 2 | return { 3 | name: 'b', 4 | getA: function () { 5 | return require('a'); 6 | } 7 | }; 8 | }); -------------------------------------------------------------------------------- /tests/node/syncRequire/a.js: -------------------------------------------------------------------------------- 1 | define(['require', 'b'], function (require) { 2 | return { 3 | name: 'a', 4 | getB: function () { 5 | return require('b'); 6 | } 7 | }; 8 | }); 9 | -------------------------------------------------------------------------------- /tests/rhino/run.js: -------------------------------------------------------------------------------- 1 | var requirejsAsLib = true; 2 | load('../../r.js'); 3 | 4 | requirejs(['main'], function (main) { 5 | print('main\'s name is: ' + main.name); 6 | print('a\'s name is: ' + main.a.name); 7 | }); 8 | 9 | -------------------------------------------------------------------------------- /tests/node/syncCall/main1.js: -------------------------------------------------------------------------------- 1 | var requirejs = require('../../../r.js'), 2 | foo = requirejs('foo'); 3 | 4 | console.log('"foo" === "' + foo.name + '"'); 5 | console.log('"A (SHOULD BE UPPERCASE)" === "' + foo.a.name + '"'); 6 | -------------------------------------------------------------------------------- /tests/xpcshell/run.js: -------------------------------------------------------------------------------- 1 | var requirejsAsLib = true; 2 | load('../../r.js'); 3 | 4 | requirejs(['main'], function (main) { 5 | print('main\'s name is: ' + main.name); 6 | print('a\'s name is: ' + main.a.name); 7 | }); 8 | 9 | -------------------------------------------------------------------------------- /dist/README.md: -------------------------------------------------------------------------------- 1 | # Notes 2 | 3 | This directory contains the built version of r.js. For a particular release, 4 | use the version tag of the release to get that release. 5 | 6 | The version in master will be updated with the latest master code. 7 | -------------------------------------------------------------------------------- /lib/rhino/LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Rhino (js.jar from http://www.mozilla.org/rhino/) was 2 | initially developed by Netscape Communications Corporation and is 3 | provided by the Dojo Foundation "as is" under the MPL 1.1 license, 4 | available at http://www.mozilla.org/MPL 5 | -------------------------------------------------------------------------------- /tests/rhino/build.js: -------------------------------------------------------------------------------- 1 | var requirejsAsLib = true; 2 | load('../../r.js'); 3 | 4 | requirejs.optimize({ 5 | name: 'main', 6 | out: 'main-built.js', 7 | optimize: 'none' 8 | }, function (results) { 9 | print(results); 10 | }, function (err) { 11 | print('GOT ERROR: ' + err); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /tests/xpcshell/build.js: -------------------------------------------------------------------------------- 1 | var requirejsAsLib = true; 2 | load('../../r.js'); 3 | 4 | requirejs.optimize({ 5 | name: 'main', 6 | out: 'main-built.js', 7 | optimize: 'none' 8 | }, function (results) { 9 | print(results); 10 | }, function (err) { 11 | print('GOT ERROR: ' + err); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /tests/node/syncCall/plug.js: -------------------------------------------------------------------------------- 1 | define({ 2 | load: function (id, require, load, config) { 3 | require([id], function (mod) { 4 | if (typeof mod.name === 'string') { 5 | mod.name = mod.name.toUpperCase(); 6 | } 7 | load(mod); 8 | }); 9 | } 10 | }); 11 | -------------------------------------------------------------------------------- /tests/node/syncRequire/main.js: -------------------------------------------------------------------------------- 1 | var requirejs = require('../../../r.js'); 2 | 3 | requirejs.config({ 4 | nodeRequire: require 5 | }); 6 | 7 | var a = requirejs('a'); 8 | 9 | console.log('syncRequire A ' + (a.name === 'a' ? 'PASSED' : 'FAILED')); 10 | console.log('syncRequire A ' + (a.getB().name === 'b' ? 'PASSED' : 'FAILED')); 11 | -------------------------------------------------------------------------------- /tests/node/embedded/main.js: -------------------------------------------------------------------------------- 1 | var cs = require('coffee-script'), 2 | requirejs = require('../../../dist/r.js'); 3 | 4 | requirejs.config({ 5 | baseUrl: 'scripts', 6 | nodeRequire: require 7 | }); 8 | 9 | requirejs(['./coffee/foo', 'bar'], 10 | function ( foo, bar) { 11 | console.log('bar.data: ' + bar.data); 12 | console.log('foo.name: ' + foo.name); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/doh/_sounds/LICENSE: -------------------------------------------------------------------------------- 1 | License Disclaimer: 2 | 3 | All contents of this directory are Copyright (c) the Dojo Foundation, with the 4 | following exceptions: 5 | ------------------------------------------------------------------------------- 6 | 7 | woohoo.wav, doh.wav, dohaaa.wav: 8 | * Copyright original authors. 9 | Copied from: 10 | http://simpson-homer.com/homer-simpson-soundboard.html 11 | -------------------------------------------------------------------------------- /tests/relative.js: -------------------------------------------------------------------------------- 1 | /* 2 | Run this file from a directory that is not the directory containing this file 3 | to see if the baseUrl of this file is used instead of the current directory. 4 | */ 5 | 6 | require(['alpha', 'beta'], function (alpha, beta) { 7 | console.log('alpha === ' + alpha.name); 8 | console.log('beta === ' + beta.name); 9 | console.log('betaSubName === ' + beta.subName); 10 | }); 11 | -------------------------------------------------------------------------------- /tests/node/index.js: -------------------------------------------------------------------------------- 1 | //The traditional nodejs http example 2 | 3 | require(['sys', 'http'], function (sys, http) { 4 | http.createServer(function (req, res) { 5 | setTimeout(function () { 6 | res.writeHead(200, {'Content-Type': 'text/plain'}); 7 | res.end('Hello World\n'); 8 | }, 2000); 9 | }).listen(8000); 10 | sys.puts('Server running at http://127.0.0.1:8000/'); 11 | }); 12 | -------------------------------------------------------------------------------- /tests/node/embedded/scripts/bar.js: -------------------------------------------------------------------------------- 1 | define(['uglify-js', 'fs', 'module'], function (uglify, fs, module) { 2 | 3 | var source = fs.readFileSync(module.uri, 'utf8'), 4 | parser = uglify.parser, 5 | minify = uglify.uglify, 6 | ast = parser.parse(source); 7 | 8 | ast = minify.ast_mangle(ast); 9 | 10 | return { 11 | data: minify.gen_code(minify.ast_squeeze(ast)) 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /tests/node/nodeRelative/main.js: -------------------------------------------------------------------------------- 1 | var requirejs = require("../../../r.js"); 2 | 3 | requirejs.config({ 4 | baseUrl: __dirname, 5 | paths: { 6 | lamp: 'other/src/lamp' 7 | } 8 | }); 9 | 10 | requirejs(['lamp'], function (lamp) { 11 | console.log('lamp name ' + (lamp.name === 'lamp' ? 'PASSED' : 'FAILED')); 12 | console.log('light name ' + (lamp.light.name === 'light' ? 'PASSED' : 'FAILED')); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/node/pluginLocalId/test.js: -------------------------------------------------------------------------------- 1 | var requirejs = require("../../../r.js"); 2 | var req = requirejs.config({ 3 | baseUrl: __dirname + '/lib', 4 | map: { 5 | '*': { 6 | 'coffee': 'cs' 7 | } 8 | } 9 | }); 10 | req(['coffee!app/test'], function(test) { 11 | if (test === 'dep') { 12 | console.log('pluginLocalId test PASSED'); 13 | } else { 14 | console.log('pluginLocalId test FAILED: ' + test + ' !== dep'); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /tests/doh/_rhinoRunner.js: -------------------------------------------------------------------------------- 1 | if(this["dojo"]){ 2 | dojo.provide("doh._rhinoRunner"); 3 | } 4 | 5 | doh.debug = print; 6 | 7 | // Override the doh._report method to make it quit with an 8 | // appropriate exit code in case of test failures. 9 | (function(){ 10 | var oldReport = doh._report; 11 | doh._report = function(){ 12 | oldReport.apply(doh, arguments); 13 | if(this._failureCount > 0 || this._errorCount > 0){ 14 | quit(1); 15 | } 16 | } 17 | })(); 18 | -------------------------------------------------------------------------------- /tests/node/syncMap/syncMap.js: -------------------------------------------------------------------------------- 1 | var requirejs = require("../../../r.js"); 2 | 3 | requirejs.config({ 4 | map: { 5 | "*": { 6 | "jquery": "cheerio" 7 | } 8 | } 9 | }); 10 | 11 | requirejs.define("test", function(require) { 12 | var $ = require("jquery"); 13 | if ($() === 'cheerio') { 14 | console.log('syncMap test PASSED'); 15 | } else { 16 | console.log('syncMap test FAILED: ' + $() + ' !== cheerio'); 17 | } 18 | }); 19 | 20 | requirejs(["test"]); 21 | -------------------------------------------------------------------------------- /tests/node/tests/server.js: -------------------------------------------------------------------------------- 1 | //The traditional nodejs http example 2 | 3 | require(['sys', 'foo', 'http', 'alpha/foo', 'text!alpha/hello.html'], function (sys, foo, http, alphaFoo, helloHtml) { 4 | http.createServer(function (req, res) { 5 | res.writeHead(200, {'Content-Type': 'text/plain'}); 6 | res.write('Hello ' + foo.name + '\nHello ' + alphaFoo.name + '\n'); 7 | res.write(helloHtml) 8 | res.end('\n'); 9 | }).listen(8000); 10 | sys.puts('Server running at http://127.0.0.1:8000/'); 11 | }); 12 | -------------------------------------------------------------------------------- /tests/doh/README: -------------------------------------------------------------------------------- 1 | DOH may be run standalone by issuing a command like the following: 2 | 3 | java -jar ../shrinksafe/js.jar runner.js testModule=tests.colors 4 | 5 | where the testModule argument is optional and shrinksafe/js.jar is just a 6 | convenient copy of the Rhino JavaScript engine -- the custom patch is not 7 | required. 8 | 9 | Optional arguments include: 10 | * dojoUrl - specifies the location of dojo.js 11 | * testUrl - specifies a Javascript file to load with initialization code 12 | * testModule - specifies a test module in the dojo package namespace 13 | -------------------------------------------------------------------------------- /tests/doh/_nodeRunner.js: -------------------------------------------------------------------------------- 1 | 2 | /*global doh: false, process: false */ 3 | 4 | var aps = Array.prototype.slice; 5 | 6 | doh.debug = function () { 7 | //Could have multiple args, join them all together. 8 | var msg = aps.call(arguments, 0).join(' '); 9 | console.log(msg); 10 | }; 11 | 12 | // Override the doh._report method to make it quit with an 13 | // appropriate exit code in case of test failures. 14 | var oldReport = doh._report; 15 | doh._report = function () { 16 | oldReport.apply(doh, arguments); 17 | if (this._failureCount > 0 || this._errorCount > 0) { 18 | process.exit(1); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /tests/node/embedded/README.md: -------------------------------------------------------------------------------- 1 | A test of embedding requirejs as a module in a node project, but delegates 2 | to Node's require() when it cannot find a file. Make sure the path resolution 3 | for Node's require is from the perspective of the main.js file, and *not* the 4 | requirejs module. 5 | 6 | ## Setup 7 | 8 | * mkdir node_modules 9 | * npm install coffee-script uglify-js 10 | 11 | Make sure there is a node_modules/requirejs directory with a package.json 12 | that has a 'main': 'bin/r.js' property, and create a bin directory with 13 | a symlink to the project's basedir/r.js file inside the bin directory. 14 | 15 | Tested with Node 0.4.9 -------------------------------------------------------------------------------- /tests/browser/r-worker.js: -------------------------------------------------------------------------------- 1 | importScripts('../../r.js'); 2 | 3 | self.onmessage = function (evt) { 4 | var out, buildText; 5 | 6 | if (evt.data === 'run') { 7 | requirejs.optimize({ 8 | baseUrl: '.', 9 | paths: { 10 | 'd': 'sub/d' 11 | }, 12 | include: ['a'], 13 | out: function (text) { 14 | out = text; 15 | } 16 | }, function (buildText) { 17 | self.postMessage(JSON.stringify({ 18 | out: out, 19 | buildText: buildText 20 | }, null, ' ')); 21 | }); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /tests/doh/_xpconnectRunner.js: -------------------------------------------------------------------------------- 1 | doh.debug = print; 2 | 3 | //Define a console.log for easier logging. Don't 4 | //get fancy though. 5 | if (typeof console === 'undefined') { 6 | console = { 7 | log: function () { 8 | print.apply(undefined, arguments); 9 | } 10 | }; 11 | } 12 | 13 | // Override the doh._report method to make it quit with an 14 | // appropriate exit code in case of test failures. 15 | (function(){ 16 | var oldReport = doh._report; 17 | doh._report = function(){ 18 | oldReport.apply(doh, arguments); 19 | if(this._failureCount > 0 || this._errorCount > 0){ 20 | quit(1); 21 | } 22 | } 23 | })(); 24 | -------------------------------------------------------------------------------- /copydist.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'), 4 | stamp = (new Date()).toUTCString(), 5 | exec = require('child_process').exec, 6 | distFileName = 'dist/r.js', 7 | count = 0, 8 | contents; 9 | 10 | exec('node dist.js', 11 | function (error, stdout, stderr) { 12 | if (error) { 13 | console.error('ERROR: ' + error); 14 | } else { 15 | 16 | fs.writeFileSync(distFileName, fs.readFileSync('r.js', 'utf8'), 'utf8'); 17 | 18 | contents = fs.readFileSync(distFileName, 'utf8') 19 | .replace(/\d\.\d\.\d+(\+|[a-z]+)?/g, function (match) { 20 | //Only do date insertion twice at the top of the file. 21 | count += 1; 22 | if (count < 3) { 23 | return match + ' ' + stamp; 24 | } else { 25 | return match; 26 | } 27 | } 28 | ); 29 | 30 | fs.writeFile(distFileName, contents, 'utf8'); 31 | } 32 | } 33 | ); 34 | -------------------------------------------------------------------------------- /tests/browser/r.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 29 | 30 | 31 |

r.js in the browser

32 | 33 | 34 |

A test of running r.js in the browser.

35 | 36 |

37 | 38 |

39 | 40 |

Build Messages

41 | 42 | 43 |

Output

44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/browser/r-worker.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 32 | 33 | 34 |

r.js in the browser

35 | 36 | 37 |

A test of running r.js in the browser.

38 | 39 |

40 | 41 |

42 | 43 |

Build Messages

44 | 45 | 46 |

Output

47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/all.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /** 8 | * BUILD r.js IN THIS DIRECTORY FIRST BEFORE RUNNING THIS FILE 9 | * 10 | * To run in Node: 11 | * node ../r.js all.js 12 | * 13 | * To run in Rhino: 14 | * java -jar ../../build/lib/rhino/js.jar ../r.js all.js 15 | * Debug: 16 | * java -classpath ../../build/lib/rhino/js.jar org.mozilla.javascript.tools.debugger.Main ../r.js all.js 17 | */ 18 | 19 | /*jslint strict: false */ 20 | /*global require: false, doh: false */ 21 | 22 | //Special global flag used by DOH. 23 | skipDohSetup = true; 24 | 25 | require({ 26 | paths: { 27 | env: '../build/jslib/env' 28 | } 29 | }, [ 30 | 'alpha', 31 | 'beta', 32 | 'doh/runner', 33 | 'env!doh/_{env}Runner' 34 | ], function (alpha, beta, a) { 35 | 36 | doh.register('rjsTests', 37 | [ 38 | function rjsTests(t) { 39 | t.is('alpha', alpha.name); 40 | t.is('beta', beta.name); 41 | t.is('betaSubName', beta.subName); 42 | } 43 | ] 44 | ); 45 | doh.run(); 46 | 47 | define('testError', function () { 48 | requirejs(['nonExistingModule'], function () { 49 | console.log('BIG TIME FAIL'); 50 | }, function (err) { 51 | console.log('OK'); 52 | }); 53 | }); 54 | 55 | require(['testError']); 56 | 57 | 58 | //Print out the test summary. 59 | doh.run(); 60 | }); 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | RequireJS r.js 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 | 6 | The "New" BSD License: 7 | ---------------------- 8 | 9 | Copyright (c) 2010-2014, The Dojo Foundation 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | * Neither the name of the Dojo Foundation nor the names of its contributors 21 | may be used to endorse or promote products derived from this software 22 | without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | 37 | MIT License 38 | ----------- 39 | 40 | Copyright (c) 2010-2011, The Dojo Foundation 41 | 42 | Permission is hereby granted, free of charge, to any person obtaining a copy 43 | of this software and associated documentation files (the "Software"), to deal 44 | in the Software without restriction, including without limitation the rights 45 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 46 | copies of the Software, and to permit persons to whom the Software is 47 | furnished to do so, subject to the following conditions: 48 | 49 | The above copyright notice and this permission notice shall be included in 50 | all copies or substantial portions of the Software. 51 | 52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 57 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 58 | THE SOFTWARE. 59 | -------------------------------------------------------------------------------- /dist.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license Copyright (c) 2010-2013, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /* 8 | * This script will create the final r.js file used in node projects to use 9 | * RequireJS. 10 | * 11 | * This file uses Node to run: 12 | * node dist.js 13 | */ 14 | 15 | /*jslint strict: false */ 16 | /*global require: false, process: false, console: false */ 17 | 18 | 19 | var fs = require('fs'), 20 | child_process = require('child_process'), 21 | contents = fs.readFileSync('build/jslib/x.js', 'utf8'), 22 | loadRegExp = /\/\/INSERT ([\w\/\.]+)/g, 23 | moduleNameRegExp = /build\/jslib\/([\w\/\-]+)\.js$/, 24 | defRegExp = /define\s*\(/, 25 | envs = ['browser', 'node', 'rhino', 'xpconnect'], 26 | //Update this list of files by running the optimizer against 27 | //build/jslib/opto.build.js, 28 | //but then remove any jslib/node entries and make sure there is 29 | //an env! entry for each one of them. Include 30 | //build/jslib/commonjs.js in the list, but remove build/build.js 31 | //since it is loaded separately. 32 | libFiles = [ 33 | 'build/jslib/env.js', 34 | 'build/jslib/lang.js', 35 | 'build/jslib/prim.js', 36 | 'env!env/assert', 37 | 'env!env/args', 38 | 'env!env/load', 39 | 'env!env/file', 40 | 'env!env/quit', 41 | 'env!env/print', 42 | 'build/jslib/logger.js', 43 | 'build/jslib/blank.js', 44 | 'build/jslib/esprima.js', 45 | 'build/jslib/esprimaAdapter.js', 46 | 'build/jslib/source-map.js', 47 | 'build/jslib/uglifyjs/consolidator.js', 48 | 'build/jslib/uglifyjs/parse-js.js', 49 | 'build/jslib/uglifyjs/squeeze-more.js', 50 | 'build/jslib/uglifyjs/process.js', 51 | 'build/jslib/uglifyjs/index.js', 52 | 'build/jslib/uglifyjs2.js', 53 | 'build/jslib/parse.js', 54 | 'build/jslib/transform.js', 55 | 'build/jslib/pragma.js', 56 | 'env!env/optimize', 57 | 'build/jslib/optimize.js', 58 | 'build/jslib/requirePatch.js', 59 | 'build/jslib/commonJs.js', 60 | 'build/jslib/build.js' 61 | ], 62 | optimizerStartFile = 'build/build.js', 63 | libText = ''; 64 | 65 | function readAndNameModule(fileName) { 66 | var contents = fs.readFileSync(fileName, 'utf8'), 67 | match = moduleNameRegExp.exec(fileName), 68 | moduleName = (match && match[1]) || fileName; 69 | 70 | //Insert the module name. 71 | return contents.replace(defRegExp, function (match) { 72 | return match + "'" + moduleName + "', "; 73 | }); 74 | } 75 | 76 | //Load up all the optimizer files. 77 | libFiles.forEach(function (fileName) { 78 | if (fileName.indexOf('env!') === 0) { 79 | envs.forEach(function (env) { 80 | libText += "\nif(env === '" + env + "') {\n" + 81 | readAndNameModule(fileName.replace(/env!env\//, 'build/jslib/' + env + '/') + '.js') + 82 | "\n}\n"; 83 | }); 84 | } else { 85 | libText += readAndNameModule(fileName, 'utf8'); 86 | } 87 | }); 88 | 89 | //Inline file contents 90 | contents = contents.replace(loadRegExp, function (match, fileName) { 91 | if (fileName === 'LIB') { 92 | return libText; 93 | } else { 94 | var text = fs.readFileSync(fileName, 'utf8'); 95 | if (fileName.indexOf('require.js') !== -1) { 96 | text = text.replace(/var requirejs, require\, define\;/, ''); 97 | } 98 | return text; 99 | } 100 | }); 101 | 102 | //Set the isOpto flag to true 103 | fs.writeFileSync('r.js', contents, 'utf8'); 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/ 3 | /r.js 4 | build/jslib/uglifyjs2/temp 5 | build/tests/builds 6 | build/tests/lib/amdefine/built.js 7 | build/tests/lib/anonUmdInteriorModules/main-built.js 8 | build/tests/lib/appDirSrcOverwrite/www-built 9 | build/tests/lib/arrow/main-built.js 10 | build/tests/lib/cjsTranslate/www-built 11 | build/tests/lib/closureExterns/built 12 | build/tests/lib/comments/built.js 13 | build/tests/lib/comments/noPartialDupe/built 14 | build/tests/lib/comments/unique/built.js 15 | build/tests/lib/configPackageShim/built 16 | build/tests/lib/cssComment138/main-built.css 17 | build/tests/lib/cssDuplicates/main-built.css 18 | build/tests/lib/cssKeepComments/main-built.css 19 | build/tests/lib/cssKeepWhitespace/main-built.css 20 | build/tests/lib/cssKeepLicense/main-license-built.css 21 | build/tests/lib/cssKeepLicense/main-built.css 22 | build/tests/lib/cssMediaQuery/main-built.css 23 | build/tests/lib/cssPrefix/356/www-built 24 | build/tests/lib/cssRemoveCombined/www-built 25 | build/tests/lib/depsConfig/main-built.js 26 | build/tests/lib/dormant213/main-built.js 27 | build/tests/lib/dotpackage/built 28 | build/tests/lib/dotTrim/built.js 29 | build/tests/lib/dualLayerOverride/built 30 | build/tests/lib/dynamicDefine/main-built.js 31 | build/tests/lib/empty/built 32 | build/tests/lib/hasOwnProperty/built.js 33 | build/tests/lib/iife/main-built.js 34 | build/tests/lib/insertRequire/main-built.js 35 | build/tests/lib/intDefine/main-built.js 36 | build/tests/lib/inlineDefineNoRequire/testmodule-built.js 37 | build/tests/lib/jqueryConfig/main-built.js 38 | build/tests/lib/keepAmdefine/built.js 39 | build/tests/lib/mainConfigFile/basic/main-built.js 40 | build/tests/lib/mainConfigFile/first/main-built.js 41 | build/tests/lib/mainConfigFile/mergeConfig/main-built.js 42 | build/tests/lib/mainConfigBaseUrl/www-built 43 | build/tests/lib/mapConfigMix/a-built.js 44 | build/tests/lib/moduleThenPlugin/built.js 45 | build/tests/lib/modulesExclude/built 46 | build/tests/lib/nameInsertion/built.js 47 | build/tests/lib/nameInsertion/nested/built.js 48 | build/tests/lib/namespace/foo.js 49 | build/tests/lib/namespaceConfig/foo.js 50 | build/tests/lib/namespaceMinified/foo.js 51 | build/tests/lib/nested/main-built.js 52 | build/tests/lib/nested/main-builtWithCE.js 53 | build/tests/lib/nestedHas/main-built.js 54 | build/tests/lib/nestedHas/main-builtNeedAll.js 55 | build/tests/lib/nestedHas/main-builtNeedB.js 56 | build/tests/lib/nestedHas/main-builtNeedC.js 57 | build/tests/lib/nestedHas/main-builtNeedD.js 58 | build/tests/lib/nestedHas/main-builtNested.js 59 | build/tests/lib/noexports/main-built.js 60 | build/tests/lib/nojQDupeDefine/main-built.js 61 | build/tests/lib/nonStrict/main-built.js 62 | build/tests/lib/nonUmdIdentifiers/main-built.js 63 | build/tests/lib/onBuildAllDir/js-built 64 | build/tests/lib/onBuildRead/main-built.js 65 | build/tests/lib/onBuildWrite/main-built.js 66 | build/tests/lib/override/wrap/built 67 | build/tests/lib/packages/main-built.js 68 | build/tests/lib/packagesNode/main-built.js 69 | build/tests/lib/pathsNoCopy/js-built 70 | build/tests/lib/pluginBuilder/main-built.js 71 | build/tests/lib/pluginDepExec/main-built.js 72 | build/tests/lib/pluginShimDep/main-built.js 73 | build/tests/lib/plugins/main-built.js 74 | build/tests/lib/plugins/main-builtPluginFirst.js 75 | build/tests/lib/plugins/onLayerEnd/built 76 | build/tests/lib/plugins/onLayerEnd/main-built.js 77 | build/tests/lib/plugins/optimizeAllPluginResources/www-built 78 | build/tests/lib/pragmas/override/built 79 | build/tests/lib/pristineSrc/built 80 | build/tests/lib/rawText/built.js 81 | build/tests/lib/rawTextLongId/built.js 82 | build/tests/lib/rawTextNameTarget/a-built.js 83 | build/tests/lib/removeCombined/app-built 84 | build/tests/lib/removeCombined/baseUrl-built 85 | build/tests/lib/removeCombinedPaths/testcase/project/build/build_output 86 | build/tests/lib/requireHoist/perLayer/built 87 | build/tests/lib/rhino-186/built 88 | build/tests/lib/semicolonInsert/a-built.js 89 | build/tests/lib/shimBasicWrap/basic-tests-built.js 90 | build/tests/lib/shimFakeDefine/main-built.js 91 | build/tests/lib/shimWrapShort/main-built.js 92 | build/tests/lib/sourcemap/www-built 93 | build/tests/lib/sourcemap/onejs/www/js/built.js 94 | build/tests/lib/sourcemap/onejs/www/js/built.js.map 95 | build/tests/lib/sourcemap/twojs/www-built 96 | build/tests/lib/stubModules/create/foobar-built.js 97 | build/tests/lib/stubModules/main-built.js 98 | build/tests/lib/stubModules/perModule/built 99 | build/tests/lib/transportBeforeMinify/www-built 100 | build/tests/lib/typescriptConfig/main-built.js 101 | build/tests/lib/umd/main-built.js 102 | build/tests/lib/umd2/built.js 103 | build/tests/lib/umd4/app-built.js 104 | build/tests/lib/umdNested/main-built.js 105 | build/tests/lib/unicode/main-built.js 106 | build/tests/lib/urlToEmpty/main-built.js 107 | build/tests/lib/wrap/outBothArray.js 108 | build/tests/lib/wrap/outOnlyEnd.js 109 | build/tests/lib/wrap/outOnlyEndArray.js 110 | build/tests/lib/wrap/outOnlyStart.js 111 | build/tests/lib/wrap/outOnlyStartArray.js 112 | build/tests/tools/doubleOptimize/built 113 | build/tests/tools/override/node_modules 114 | build/tests/tools/override/one-built.js 115 | build/tests/transform/results 116 | env/xpcshell 117 | tests/node/node_modules 118 | tests/node/embedded/node_modules 119 | tests/rhino/main-built.js 120 | tests/xpcshell/main-built.js 121 | -------------------------------------------------------------------------------- /tests/node/pluginLocalId/lib/cs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license cs 0.4.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/require-cs for details 5 | */ 6 | 7 | /*jslint */ 8 | /*global define, window, XMLHttpRequest, importScripts, Packages, java, 9 | ActiveXObject, process, require */ 10 | 11 | define(['coffee-script'], function (CoffeeScript) { 12 | 'use strict'; 13 | var fs, getXhr, 14 | progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'], 15 | fetchText = function () { 16 | throw new Error('Environment unsupported.'); 17 | }, 18 | buildMap = {}; 19 | 20 | if (typeof process !== "undefined" && 21 | process.versions && 22 | !!process.versions.node) { 23 | //Using special require.nodeRequire, something added by r.js. 24 | fs = require.nodeRequire('fs'); 25 | fetchText = function (path, callback) { 26 | callback(fs.readFileSync(path, 'utf8')); 27 | }; 28 | } else if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") { 29 | // Browser action 30 | getXhr = function () { 31 | //Would love to dump the ActiveX crap in here. Need IE 6 to die first. 32 | var xhr, i, progId; 33 | if (typeof XMLHttpRequest !== "undefined") { 34 | return new XMLHttpRequest(); 35 | } else { 36 | for (i = 0; i < 3; i += 1) { 37 | progId = progIds[i]; 38 | try { 39 | xhr = new ActiveXObject(progId); 40 | } catch (e) {} 41 | 42 | if (xhr) { 43 | progIds = [progId]; // so faster next time 44 | break; 45 | } 46 | } 47 | } 48 | 49 | if (!xhr) { 50 | throw new Error("getXhr(): XMLHttpRequest not available"); 51 | } 52 | 53 | return xhr; 54 | }; 55 | 56 | fetchText = function (url, callback) { 57 | var xhr = getXhr(); 58 | xhr.open('GET', url, true); 59 | xhr.onreadystatechange = function (evt) { 60 | //Do not explicitly handle errors, those should be 61 | //visible via console output in the browser. 62 | if (xhr.readyState === 4) { 63 | callback(xhr.responseText); 64 | } 65 | }; 66 | xhr.send(null); 67 | }; 68 | // end browser.js adapters 69 | } else if (typeof Packages !== 'undefined') { 70 | //Why Java, why is this so awkward? 71 | fetchText = function (path, callback) { 72 | var stringBuffer, line, 73 | encoding = "utf-8", 74 | file = new java.io.File(path), 75 | lineSeparator = java.lang.System.getProperty("line.separator"), 76 | input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)), 77 | content = ''; 78 | try { 79 | stringBuffer = new java.lang.StringBuffer(); 80 | line = input.readLine(); 81 | 82 | // Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324 83 | // http://www.unicode.org/faq/utf_bom.html 84 | 85 | // 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: 86 | // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058 87 | if (line && line.length() && line.charAt(0) === 0xfeff) { 88 | // Eat the BOM, since we've already found the encoding on this file, 89 | // and we plan to concatenating this buffer with others; the BOM should 90 | // only appear at the top of a file. 91 | line = line.substring(1); 92 | } 93 | 94 | stringBuffer.append(line); 95 | 96 | while ((line = input.readLine()) !== null) { 97 | stringBuffer.append(lineSeparator); 98 | stringBuffer.append(line); 99 | } 100 | //Make sure we return a JavaScript string and not a Java string. 101 | content = String(stringBuffer.toString()); //String 102 | } finally { 103 | input.close(); 104 | } 105 | callback(content); 106 | }; 107 | } 108 | 109 | return { 110 | fetchText: fetchText, 111 | 112 | get: function () { 113 | return CoffeeScript; 114 | }, 115 | 116 | write: function (pluginName, name, write) { 117 | if (buildMap.hasOwnProperty(name)) { 118 | var text = buildMap[name]; 119 | write.asModule(pluginName + "!" + name, text); 120 | } 121 | }, 122 | 123 | version: '0.4.3', 124 | 125 | load: function (name, parentRequire, load, config) { 126 | var path = parentRequire.toUrl(name + '.coffee'); 127 | fetchText(path, function (text) { 128 | 129 | //Do CoffeeScript transform. 130 | try { 131 | text = CoffeeScript.compile(text, config.CoffeeScript); 132 | } catch (err) { 133 | err.message = "In " + path + ", " + err.message; 134 | throw err; 135 | } 136 | 137 | //Hold on to the transformed text if a build. 138 | if (config.isBuild) { 139 | buildMap[name] = text; 140 | } 141 | 142 | //IE with conditional comments on cannot handle the 143 | //sourceURL trick, so skip it if enabled. 144 | /*@if (@_jscript) @else @*/ 145 | if (!config.isBuild) { 146 | text += "\r\n//# sourceURL=" + path; 147 | } 148 | /*@end@*/ 149 | 150 | load.fromText(name, text); 151 | 152 | //Give result to load. Need to wait until the module 153 | //is fully parse, which will happen after this 154 | //execution. 155 | parentRequire([name], function (value) { 156 | load(value); 157 | }); 158 | }); 159 | } 160 | }; 161 | }); 162 | -------------------------------------------------------------------------------- /tests/doh/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | RequireJS Tests Via The Dojo Unit Test Harness, $Rev: 20149 $ 11 | 12 | 33 | 34 | 66 | 67 | 68 | 69 | 74 | 229 | 230 | 231 | 232 | 233 | 241 | 242 | 243 | 244 | 245 | 246 | 256 | 261 | 262 | 263 | 297 | 311 | 312 |
234 |

RequireJS Tests Via D.O.H.: The Dojo Objective Harness

235 | 236 | 237 | 238 | 239 | 240 |
247 | 248 | 249 | 250 | 251 | 252 | Stopped 253 | 254 | 255 | 257 | 258 | 259 | 260 |
264 |
265 | 267 | 268 | 269 | 270 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 |
  271 | 273 | testtime
295 |
296 |
298 |
299 |
301 |

302 | 							
303 |
304 | 306 | 309 |
310 |
313 | 314 | 315 | 316 | 317 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # r.js 2 | 3 | A command line tool for running JavaScript scripts that use the 4 | [Asychronous Module Defintion API (AMD)](https://github.com/amdjs/amdjs-api/blob/master/AMD.md) 5 | for declaring and using JavaScript modules and regular JavaScript script files. 6 | 7 | It is part of the [RequireJS project](http://requirejs.org), and works with 8 | the RequireJS implementation of AMD. 9 | 10 | r.js is a single script that has two major functions: 11 | 12 | * Run AMD-based projects [in Node](http://requirejs.org/docs/node.html) and Nashorn, Rhino and xpcshell. 13 | * Includes the [RequireJS Optimizer](http://requirejs.org/docs/optimization.html) 14 | that combines scripts for optimal browser delivery. 15 | 16 | # Installation 17 | 18 | ## Node 19 | 20 | npm install -g requirejs 21 | 22 | From then on, you can use `r.js` on the command line to run the optimizer. 23 | 24 | ## Nashorn/Rhino/Browser 25 | 26 | Download the latest release from the 27 | [RequireJS download page](http://requirejs.org/docs/download.html#rjs). 28 | 29 | ## xpcshell 30 | 31 | [xpcshell](https://developer.mozilla.org/en-US/docs/XPConnect/xpcshell) support 32 | was added in r.js version 2.1.5, so use that r.js version or later. 33 | 34 | Download the latest release of r.js from the 35 | [RequireJS download page](http://requirejs.org/docs/download.html#rjs). 36 | 37 | ## From this repo 38 | 39 | r.js is made up of a series of modules that are built into one file for 40 | distribution. The **dist** directory contains the built version of the 41 | code. In the master branch, it should match the current state of the master 42 | code. 43 | 44 | If you are doing local modifications from a clone of this repo, you can run 45 | the following command to generate an r.js at the root of this repo: 46 | 47 | node dist.js 48 | 49 | To generate an r.js that also gets copied to **dist** with a time stamp, run: 50 | 51 | ./copydist.js 52 | 53 | # Running AMD-based projects 54 | 55 | If your JS project's main application file is called main.js, then do 56 | the following: 57 | 58 | ## Node 59 | 60 | r.js main.js 61 | 62 | Requires Node 0.4 or later. 63 | 64 | r.js allows using Node modules installed via npm. For more info see the 65 | [Use with Node](http://requirejs.org/docs/node.html) docs. 66 | 67 | ## Java 68 | 69 | ### Nashorn 70 | 71 | As of r.js 2.1.16, r.js can run in [Nashorn](http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html), Java 8+'s JavaScript engine, via the `jjs` command line tool that is installed with Java. 72 | 73 | Then general format of the command: 74 | 75 | ``` 76 | jjs -scripting path/to/r.js -- [r.js command line arguments here] 77 | ``` 78 | 79 | Examples: 80 | 81 | ``` 82 | # Calling r.js to optimize a project using the build config in build.js 83 | jjs -scripting path/to/r.js -- -o build.js 84 | 85 | # Calling r.js to run AMD modules, where the main app program is main.js 86 | jjs -scripting path/to/r.js -- main.js 87 | 88 | ``` 89 | 90 | All further examples will use the Node notation, but substitute the **r.js** references below with the command line structure mentioned above (`jjs -scripting path/to/r.js -- `). 91 | 92 | ### Rhino 93 | 94 | Using Rhino requires some JAR files in the CLASSPATH for it to work: 95 | 96 | * [rhino.jar](https://github.com/jrburke/r.js/blob/master/lib/rhino/js.jar?raw=true) from the [Rhino project](http://www.mozilla.org/rhino/). 97 | * [compiler.jar](https://github.com/jrburke/r.js/blob/master/lib/closure/compiler.jar?raw=true) if you are using the optimizer and want to use 98 | [Closure Compiler](http://code.google.com/closure/compiler/). 99 | 100 | Download those files to your machine. To run r.js, you can use this type of 101 | command: 102 | 103 | ### OS X/Linux/Unix: 104 | 105 | java -classpath path/to/rhino/js.jar:path/to/closure/compiler.jar org.mozilla.javascript.tools.shell.Main r.js main.js 106 | 107 | ### Windows 108 | 109 | java -classpath path/to/rhino/js.jar;path/to/closure/compiler.jar org.mozilla.javascript.tools.shell.Main r.js main.js 110 | 111 | If you want to run it in the debugger, replace 112 | org.mozilla.javascript.tools.shell.Main with 113 | **org.mozilla.javascript.tools.debugger.Main**. 114 | 115 | All further examples will use the Node notation, but substitute the **r.js** references below with the appropriate java command. 116 | 117 | ## xpcshell 118 | 119 | To run the optimizer using a build config file or command line build options: 120 | 121 | path/to/xpcshell path/to/r.js -o buildconfig.js 122 | 123 | r.js can also be used as a library in another .js file run via xpcshell. 124 | 125 | * [tests/xpcshell/run.js](https://github.com/jrburke/r.js/blob/master/tests/xpcshell/run.js): 126 | shows how to load AMD modules by using r.js as a library. 127 | * [tests/xpcshell/build.js](https://github.com/jrburke/r.js/blob/master/tests/xpcshell/build.js): 128 | shows how to trigger the optimizer from within another .js file. 129 | 130 | # Optimizer 131 | 132 | The optimizer can be run by passing the **-o** command to r.js: 133 | 134 | r.js -o path/to/buildconfig.js 135 | 136 | See the [Optimization doc](http://requirejs.org/docs/optimization.html) for more 137 | information on the optimizer. 138 | 139 | If running in **Java**, be sure to grab the Rhino and Closure Compiler jar files in the lib/ directory, then run this command: 140 | 141 | ### OS X/Linux/Unix: 142 | 143 | java -classpath path/to/rhino/js.jar:path/to/closure/compiler.jar org.mozilla.javascript.tools.shell.Main r.js -o path/to/buildconfig.js 144 | 145 | ### Windows 146 | 147 | java -classpath path/to/rhino/js.jar;path/to/closure/compiler.jar org.mozilla.javascript.tools.shell.Main r.js -o path/to/buildconfig.js 148 | 149 | 150 | ## What makes it special 151 | 152 | The optimizer is better than using a plain concatenation script because it runs 153 | require.js as part of the optimization, so it knows how to: 154 | 155 | * Use [Loader Plugins](http://requirejs.org/docs/plugins.html) to load non-script 156 | dependencies and inline them in built files. 157 | * [Name anonymous modules](http://requirejs.org/docs/api.html#modulename). 158 | If your optimization step does not do this, and you use anonymous modules, you 159 | will get errors running the built code. 160 | 161 | # Other r.js commands 162 | 163 | ## Get Version 164 | 165 | To get the version of r.js and the version of require.js used by r.js: 166 | 167 | r.js -v 168 | 169 | ## Convert CommonJS modules 170 | 171 | To convert a directory of CommonJS modules to ones that have define() wrappers: 172 | 173 | r.js -convert path/to/commonjs/dir output/dir 174 | 175 | Most, but not all, CommonJS modules can be converted to define()-wrapped modules 176 | and still work. 177 | 178 | However, there are some modules that may fail if: 179 | 180 | * They use code branches like if/else or try/catch to call require(). There are 181 | problems supporting this kind of dynamic module calls in an async environment. 182 | * Some kinds of circular dependencies will not work right. The kinds that fail 183 | are normally very brittle and depend on the execution order of the dependent 184 | modules. 185 | 186 | # Directory layout 187 | 188 | ## Directory prerequisites 189 | 190 | r.js assumes that there are some other projects checked out as sibling 191 | directories to it, and named certain names, in order for the tests to pass. 192 | 193 | So it is best to create the following directory structure with the following 194 | git clone commands: 195 | 196 | mkdir requirejs 197 | cd requirejs 198 | git clone git://github.com/jrburke/r.js.git 199 | git clone git://github.com/jrburke/requirejs.git 200 | git clone git://github.com/requirejs/text.git 201 | 202 | So there should be a sibling `requirejs` and `text` directories to the r.js 203 | directory containing your clone of the r.js project. 204 | 205 | ## Directory details 206 | 207 | The r.js project has the following directory layout: 208 | 209 | * **dist.js**: the script that builds r.js 210 | * **require.js**: the version of require.js to include in r.js 211 | * **dist** the directory containing releases of r.js 212 | * **build**: The files that make up the optimizer. dist.js includes a list of 213 | the files from this directory to build into r.js. 214 | * **lib**: The Java libraries for Rhino and Closure Compiler. Only needed if using 215 | Java/Rhino to run r.js 216 | * **tests**: command line tests. Run it under Node and Rhino by doing ../r.js all.js 217 | 218 | dist.js takes the build/jslib/x.js file and injects the require.js files and other 219 | files from the build/jslib directory into it. 220 | 221 | If you make changes to any of those files, you will need to run **node dist.js** 222 | to generate a new r.js. Be sure to run it through the tests , using both Node 223 | and Java/Rhino: 224 | 225 | * node dist.js 226 | * cd tests 227 | * node ../r.js all.js 228 | * java -classpath ../lib/rhino/js.jar:../lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main ../r.js all.js 229 | * cd ../build/tests 230 | * node ../../r.js all.js 231 | * java -classpath ../../lib/rhino/js.jar:../../lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main ../../r.js all.js 232 | 233 | For running tests, put xpcshell in env/xpcshell/ as a directory, that contains 234 | all the files needed for it to run, including the xpcshell binary. Downloading 235 | [a xulrunner nightly](http://ftp.mozilla.org/pub/mozilla.org/xulrunner/nightly/latest-mozilla-central/) 236 | might work. 237 | 238 | # Contributing code changes 239 | 240 | See the [RequireJS Contributing](http://requirejs.org/docs/contributing.html) 241 | page for info on how to contribute code/bug fixes to this project. 242 | 243 | Use GitHub pull requests to point to code changes, although for larger changes, 244 | contact the [requirejs mailing list](http://groups.google.com/group/requirejs) 245 | to discuss them first. 246 | 247 | # Included libraries 248 | 249 | r.js includes modules from these projects: 250 | 251 | * [Esprima](http://esprima.org/) 252 | * [UglifyJS](https://github.com/mishoo/UglifyJS) 253 | 254 | # Doing a release 255 | 256 | To do a release of version 0.0.0: 257 | 258 | * Make sure the right version of require.js is in the project. 259 | * Modify build/jslib/x.js to update the r.js version number in two places. 260 | * node dist.js 261 | * Run the tests (see above). They should pass. :) 262 | * mv r.js dist/r.js 263 | * git commit -am "Release 0.0.0" 264 | * git tag -am "Release 0.0.0" 0.0.0 265 | * git push origin master 266 | * git push --tags 267 | 268 | Update the RequireJS download site to point to the latest release, then update 269 | the [requirejs/requirejs-npm](https://github.com/requirejs/requirejs-npm) repo to have the latest 270 | changes and publish the result to npm. 271 | 272 | Make sure to keep `#!/usr/bin/env node` as the first line in bin/r.js in 273 | the requirejs-npm repo. 274 | -------------------------------------------------------------------------------- /tests/doh/LICENSE: -------------------------------------------------------------------------------- 1 | Dojo is available under *either* the terms of the modified BSD license *or* the 2 | Academic Free License version 2.1. As a recipient of Dojo, you may choose which 3 | license to receive this code under (except as noted in per-module LICENSE 4 | files). Some modules may not be the copyright of the Dojo Foundation. These 5 | modules contain explicit declarations of copyright in both the LICENSE files in 6 | the directories in which they reside and in the code itself. No external 7 | contributions are allowed under licenses which are fundamentally incompatible 8 | with the AFL or BSD licenses that Dojo is distributed under. 9 | 10 | The text of the AFL and BSD licenses is reproduced below. 11 | 12 | ------------------------------------------------------------------------------- 13 | The "New" BSD License: 14 | ********************** 15 | 16 | Copyright (c) 2005-2009, The Dojo Foundation 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions are met: 21 | 22 | * Redistributions of source code must retain the above copyright notice, this 23 | list of conditions and the following disclaimer. 24 | * Redistributions in binary form must reproduce the above copyright notice, 25 | this list of conditions and the following disclaimer in the documentation 26 | and/or other materials provided with the distribution. 27 | * Neither the name of the Dojo Foundation nor the names of its contributors 28 | may be used to endorse or promote products derived from this software 29 | without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 32 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 33 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 34 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 35 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 37 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 38 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 39 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | 42 | ------------------------------------------------------------------------------- 43 | The Academic Free License, v. 2.1: 44 | ********************************** 45 | 46 | This Academic Free License (the "License") applies to any original work of 47 | authorship (the "Original Work") whose owner (the "Licensor") has placed the 48 | following notice immediately following the copyright notice for the Original 49 | Work: 50 | 51 | Licensed under the Academic Free License version 2.1 52 | 53 | 1) Grant of Copyright License. Licensor hereby grants You a world-wide, 54 | royalty-free, non-exclusive, perpetual, sublicenseable license to do the 55 | following: 56 | 57 | a) to reproduce the Original Work in copies; 58 | 59 | b) to prepare derivative works ("Derivative Works") based upon the Original 60 | Work; 61 | 62 | c) to distribute copies of the Original Work and Derivative Works to the 63 | public; 64 | 65 | d) to perform the Original Work publicly; and 66 | 67 | e) to display the Original Work publicly. 68 | 69 | 2) Grant of Patent License. Licensor hereby grants You a world-wide, 70 | royalty-free, non-exclusive, perpetual, sublicenseable license, under patent 71 | claims owned or controlled by the Licensor that are embodied in the Original 72 | Work as furnished by the Licensor, to make, use, sell and offer for sale the 73 | Original Work and Derivative Works. 74 | 75 | 3) Grant of Source Code License. The term "Source Code" means the preferred 76 | form of the Original Work for making modifications to it and all available 77 | documentation describing how to modify the Original Work. Licensor hereby 78 | agrees to provide a machine-readable copy of the Source Code of the Original 79 | Work along with each copy of the Original Work that Licensor distributes. 80 | Licensor reserves the right to satisfy this obligation by placing a 81 | machine-readable copy of the Source Code in an information repository 82 | reasonably calculated to permit inexpensive and convenient access by You for as 83 | long as Licensor continues to distribute the Original Work, and by publishing 84 | the address of that information repository in a notice immediately following 85 | the copyright notice that applies to the Original Work. 86 | 87 | 4) Exclusions From License Grant. Neither the names of Licensor, nor the names 88 | of any contributors to the Original Work, nor any of their trademarks or 89 | service marks, may be used to endorse or promote products derived from this 90 | Original Work without express prior written permission of the Licensor. Nothing 91 | in this License shall be deemed to grant any rights to trademarks, copyrights, 92 | patents, trade secrets or any other intellectual property of Licensor except as 93 | expressly stated herein. No patent license is granted to make, use, sell or 94 | offer to sell embodiments of any patent claims other than the licensed claims 95 | defined in Section 2. No right is granted to the trademarks of Licensor even if 96 | such marks are included in the Original Work. Nothing in this License shall be 97 | interpreted to prohibit Licensor from licensing under different terms from this 98 | License any Original Work that Licensor otherwise would have a right to 99 | license. 100 | 101 | 5) This section intentionally omitted. 102 | 103 | 6) Attribution Rights. You must retain, in the Source Code of any Derivative 104 | Works that You create, all copyright, patent or trademark notices from the 105 | Source Code of the Original Work, as well as any notices of licensing and any 106 | descriptive text identified therein as an "Attribution Notice." You must cause 107 | the Source Code for any Derivative Works that You create to carry a prominent 108 | Attribution Notice reasonably calculated to inform recipients that You have 109 | modified the Original Work. 110 | 111 | 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that 112 | the copyright in and to the Original Work and the patent rights granted herein 113 | by Licensor are owned by the Licensor or are sublicensed to You under the terms 114 | of this License with the permission of the contributor(s) of those copyrights 115 | and patent rights. Except as expressly stated in the immediately proceeding 116 | sentence, the Original Work is provided under this License on an "AS IS" BASIS 117 | and WITHOUT WARRANTY, either express or implied, including, without limitation, 118 | the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR 119 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. 120 | This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No 121 | license to Original Work is granted hereunder except under this disclaimer. 122 | 123 | 8) Limitation of Liability. Under no circumstances and under no legal theory, 124 | whether in tort (including negligence), contract, or otherwise, shall the 125 | Licensor be liable to any person for any direct, indirect, special, incidental, 126 | or consequential damages of any character arising as a result of this License 127 | or the use of the Original Work including, without limitation, damages for loss 128 | of goodwill, work stoppage, computer failure or malfunction, or any and all 129 | other commercial damages or losses. This limitation of liability shall not 130 | apply to liability for death or personal injury resulting from Licensor's 131 | negligence to the extent applicable law prohibits such limitation. Some 132 | jurisdictions do not allow the exclusion or limitation of incidental or 133 | consequential damages, so this exclusion and limitation may not apply to You. 134 | 135 | 9) Acceptance and Termination. If You distribute copies of the Original Work or 136 | a Derivative Work, You must make a reasonable effort under the circumstances to 137 | obtain the express assent of recipients to the terms of this License. Nothing 138 | else but this License (or another written agreement between Licensor and You) 139 | grants You permission to create Derivative Works based upon the Original Work 140 | or to exercise any of the rights granted in Section 1 herein, and any attempt 141 | to do so except under the terms of this License (or another written agreement 142 | between Licensor and You) is expressly prohibited by U.S. copyright law, the 143 | equivalent laws of other countries, and by international treaty. Therefore, by 144 | exercising any of the rights granted to You in Section 1 herein, You indicate 145 | Your acceptance of this License and all of its terms and conditions. 146 | 147 | 10) Termination for Patent Action. This License shall terminate automatically 148 | and You may no longer exercise any of the rights granted to You by this License 149 | as of the date You commence an action, including a cross-claim or counterclaim, 150 | against Licensor or any licensee alleging that the Original Work infringes a 151 | patent. This termination provision shall not apply for an action alleging 152 | patent infringement by combinations of the Original Work with other software or 153 | hardware. 154 | 155 | 11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this 156 | License may be brought only in the courts of a jurisdiction wherein the 157 | Licensor resides or in which Licensor conducts its primary business, and under 158 | the laws of that jurisdiction excluding its conflict-of-law provisions. The 159 | application of the United Nations Convention on Contracts for the International 160 | Sale of Goods is expressly excluded. Any use of the Original Work outside the 161 | scope of this License or after its termination shall be subject to the 162 | requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et 163 | seq., the equivalent laws of other countries, and international treaty. This 164 | section shall survive the termination of this License. 165 | 166 | 12) Attorneys Fees. In any action to enforce the terms of this License or 167 | seeking damages relating thereto, the prevailing party shall be entitled to 168 | recover its costs and expenses, including, without limitation, reasonable 169 | attorneys' fees and costs incurred in connection with such action, including 170 | any appeal of such action. This section shall survive the termination of this 171 | License. 172 | 173 | 13) Miscellaneous. This License represents the complete agreement concerning 174 | the subject matter hereof. If any provision of this License is held to be 175 | unenforceable, such provision shall be reformed only to the extent necessary to 176 | make it enforceable. 177 | 178 | 14) Definition of "You" in This License. "You" throughout this License, whether 179 | in upper or lower case, means an individual or a legal entity exercising rights 180 | under, and complying with all of the terms of, this License. For legal 181 | entities, "You" includes any entity that controls, is controlled by, or is 182 | under common control with you. For purposes of this definition, "control" means 183 | (i) the power, direct or indirect, to cause the direction or management of such 184 | entity, whether by contract or otherwise, or (ii) ownership of fifty percent 185 | (50%) or more of the outstanding shares, or (iii) beneficial ownership of such 186 | entity. 187 | 188 | 15) Right to Use. You may use the Original Work in all ways not otherwise 189 | restricted or conditioned by this License or by law, and Licensor promises not 190 | to interfere with or be responsible for such uses by You. 191 | 192 | This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. 193 | Permission is hereby granted to copy and distribute this license without 194 | modification. This license may not be modified without the express written 195 | permission of its copyright owner. 196 | -------------------------------------------------------------------------------- /lib/closure/COPYING: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /lib/closure/README.md: -------------------------------------------------------------------------------- 1 | # [Google Closure Compiler](https://developers.google.com/closure/compiler/) 2 | 3 | [![Build Status](https://travis-ci.org/google/closure-compiler.svg?branch=master)](https://travis-ci.org/google/closure-compiler) 4 | 5 | The [Closure Compiler](https://developers.google.com/closure/compiler/) is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. 6 | 7 | ## Getting Started 8 | * [Download the latest version](http://dl.google.com/closure-compiler/compiler-latest.zip) ([Release details here](https://github.com/google/closure-compiler/wiki/Releases)) 9 | * [Download a specific version](https://github.com/google/closure-compiler/wiki/Binary-Downloads). Also available via: 10 | - [Maven](https://github.com/google/closure-compiler/wiki/Maven) 11 | - [NPM](https://www.npmjs.com/package/google-closure-compiler) 12 | * See the [Google Developers Site](https://developers.google.com/closure/compiler/docs/gettingstarted_app) for documentation including instructions for running the compiler from the command line. 13 | 14 | ## Options for Getting Help 15 | 1. Post in the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss) 16 | 2. Ask a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/google-closure-compiler) 17 | 3. Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) 18 | 19 | ## Building it Yourself 20 | 21 | Note: The Closure Compiler requires [Java 7 or higher](http://www.java.com/). 22 | 23 | ### Using [Maven](http://maven.apache.org/) 24 | 25 | 1. Download [Maven](http://maven.apache.org/download.cgi). 26 | 27 | 2. Run `mvn -DskipTests` (omit the `-DskipTests` if you want to run all the 28 | unit tests too). 29 | 30 | This will produce a jar file called `target/closure-compiler-1.0-SNAPSHOT.jar`. 31 | 32 | ### Using [Eclipse](http://www.eclipse.org/) 33 | 34 | 1. Download and open the [Eclipse IDE](http://www.eclipse.org/). 35 | 2. Navigate to ```File > New > Project ...``` and create a Java Project. Give 36 | the project a name. 37 | 3. Select ```Create project from existing source``` and choose the root of the 38 | checked-out source tree as the existing directory. 39 | 3. Navigate to the ```build.xml``` file. You will see all the build rules in 40 | the Outline pane. Run the ```jar``` rule to build the compiler in 41 | ```build/compiler.jar```. 42 | 43 | ## Running 44 | 45 | On the command line, at the root of this project, type 46 | 47 | ``` 48 | java -jar build/compiler.jar 49 | ``` 50 | 51 | This starts the compiler in interactive mode. Type 52 | 53 | ```javascript 54 | var x = 17 + 25; 55 | ``` 56 | 57 | then hit "Enter", then hit "Ctrl-Z" (on Windows) or "Ctrl-D" (on Mac or Linux) 58 | and "Enter" again. The Compiler will respond: 59 | 60 | ```javascript 61 | var x=42; 62 | ``` 63 | 64 | The Closure Compiler has many options for reading input from a file, writing 65 | output to a file, checking your code, and running optimizations. To learn more, 66 | type 67 | 68 | ``` 69 | java -jar compiler.jar --help 70 | ``` 71 | 72 | More detailed information about running the Closure Compiler is available in the 73 | [documentation](http://code.google.com/closure/compiler/docs/gettingstarted_app.html). 74 | 75 | ## Compiling Multiple Scripts 76 | 77 | If you have multiple scripts, you should compile them all together with one 78 | compile command. 79 | 80 | ```bash 81 | java -jar compiler.jar --js_output_file=out.js in1.js in2.js in3.js ... 82 | ``` 83 | 84 | You can also use minimatch-style globs. 85 | 86 | ```bash 87 | # Recursively include all js files in subdirs 88 | java -jar compiler.jar --js_output_file=out.js 'src/**.js' 89 | 90 | # Recursively include all js files in subdirs, exclusing test files. 91 | # Use single-quotes, so that bash doesn't try to expand the '!' 92 | java -jar compiler.jar --js_output_file=out.js 'src/**.js' '!**_test.js' 93 | ``` 94 | 95 | The Closure Compiler will concatenate the files in the order they're passed at 96 | the command line. 97 | 98 | If you're using globs or many files, you may start to run into 99 | problems with managing dependencies between scripts. In this case, you should 100 | use the [Closure Library](https://developers.google.com/closure/library/). It 101 | contains functions for enforcing dependencies between scripts, and Closure Compiler 102 | will re-order the inputs automatically. 103 | 104 | ## How to Contribute 105 | ### Reporting a bug 106 | 1. First make sure that it is really a bug and not simply the way that Closure Compiler works (especially true for ADVANCED_OPTIMIZATIONS). 107 | * Check the [official documentation](https://developers.google.com/closure/compiler/) 108 | * Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) 109 | * Search on [Stack Overflow](http://stackoverflow.com/questions/tagged/google-closure-compiler) and in the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss) 110 | 2. If you still think you have found a bug, make sure someone hasn't already reported it. See the list of [known issues](https://github.com/google/closure-compiler/issues). 111 | 3. If it hasn't been reported yet, post a new issue. Make sure to add enough detail so that the bug can be recreated. The smaller the reproduction code, the better. 112 | 113 | ### Suggesting a Feature 114 | 1. Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) to make sure that the behaviour you would like isn't specifically excluded (such as string inlining). 115 | 2. Make sure someone hasn't requested the same thing. See the list of [known issues](https://github.com/google/closure-compiler/issues). 116 | 3. Read up on [what type of feature requests are accepted](https://github.com/google/closure-compiler/wiki/FAQ#how-do-i-submit-a-feature-request-for-a-new-type-of-optimization). 117 | 4. Submit your reqest as an issue. 118 | 119 | ### Submitting patches 120 | 1. All contributors must sign a contributor license agreement (CLA). 121 | A CLA basically says that you own the rights to any code you contribute, 122 | and that you give us permission to use that code in Closure Compiler. 123 | You maintain the copyright on that code. 124 | If you own all the rights to your code, you can fill out an 125 | [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). 126 | If your employer has any rights to your code, then they also need to fill out 127 | a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). 128 | If you don't know if your employer has any rights to your code, you should 129 | ask before signing anything. 130 | By default, anyone with an @google.com email address already has a CLA 131 | signed for them. 132 | 2. To make sure your changes are of the type that will be accepted, ask about your patch on the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss) 133 | 3. Fork the repository. 134 | 4. Make your changes. 135 | 5. Submit a pull request for your changes. A project developer will review your work and then merge your request into the project. 136 | 137 | ## Closure Compiler License 138 | 139 | Copyright 2009 The Closure Compiler Authors. 140 | 141 | Licensed under the Apache License, Version 2.0 (the "License"); 142 | you may not use this file except in compliance with the License. 143 | You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 144 | 145 | Unless required by applicable law or agreed to in writing, software 146 | distributed under the License is distributed on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 148 | See the License for the specific language governing permissions and 149 | limitations under the License. 150 | 151 | ## Dependency Licenses 152 | 153 | ### Rhino 154 | 155 | 156 | 157 | 158 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 184 | 185 | 186 | 187 | 188 | 191 | 192 |
Code Path 159 | src/com/google/javascript/rhino, test/com/google/javascript/rhino 160 |
URLhttp://www.mozilla.org/rhino
Version1.5R3, with heavy modifications
LicenseNetscape Public License and MPL / GPL dual license
DescriptionA partial copy of Mozilla Rhino. Mozilla Rhino is an 181 | implementation of JavaScript for the JVM. The JavaScript 182 | parse tree data structures were extracted and modified 183 | significantly for use by Google's JavaScript compiler.
Local ModificationsThe packages have been renamespaced. All code not 189 | relevant to the parse tree has been removed. A JsDoc parser and static typing 190 | system have been added.
193 | 194 | ### Args4j 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 221 | 222 | 223 | 224 | 225 | 226 | 227 |
Code Pathlib/args4j.jar
URLhttps://args4j.dev.java.net/
Version2.0.26
LicenseMIT
Descriptionargs4j is a small Java class library that makes it easy to parse command line 220 | options/arguments in your CUI application.
Local ModificationsNone
228 | 229 | ### Guava Libraries 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 |
Code Pathlib/guava.jar
URLhttps://github.com/google/guava
Version18.0
LicenseApache License 2.0
DescriptionGoogle's core Java libraries.
Local ModificationsNone
262 | 263 | ### JSR 305 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 |
Code Pathlib/jsr305.jar
URLhttp://code.google.com/p/jsr-305/
Versionsvn revision 47
LicenseBSD License
DescriptionAnnotations for software defect detection.
Local ModificationsNone
296 | 297 | ### JUnit 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 |
Code Pathlib/junit.jar
URLhttp://sourceforge.net/projects/junit/
Version4.11
LicenseCommon Public License 1.0
DescriptionA framework for writing and running automated tests in Java.
Local ModificationsNone
330 | 331 | ### Protocol Buffers 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 358 | 359 | 360 | 361 | 362 | 363 | 364 |
Code Pathlib/protobuf-java.jar
URLhttps://github.com/google/protobuf
Version2.5.0
LicenseNew BSD License
DescriptionSupporting libraries for protocol buffers, 357 | an encoding of structured data.
Local ModificationsNone
365 | 366 | ### Truth 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 |
Code Pathlib/truth.jar
URLhttps://github.com/google/truth
Version0.24
LicenseApache License 2.0
DescriptionAssertion/Proposition framework for Java unit tests
Local ModificationsNone
399 | 400 | ### Ant 401 | 402 | 403 | 404 | 405 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 429 | 430 | 431 | 432 | 433 | 434 | 435 |
Code Path 406 | lib/ant.jar, lib/ant-launcher.jar 407 |
URLhttp://ant.apache.org/bindownload.cgi
Version1.8.1
LicenseApache License 2.0
DescriptionAnt is a Java based build tool. In theory it is kind of like "make" 428 | without make's wrinkles and with the full portability of pure java code.
Local ModificationsNone
436 | 437 | ### GSON 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 |
Code Pathlib/gson.jar
URLhttps://github.com/google/gson
Version2.2.4
LicenseApache license 2.0
DescriptionA Java library to convert JSON to Java objects and vice-versa
Local ModificationsNone
470 | 471 | ### Node.js Closure Compiler Externs 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 |
Code Pathcontrib/nodejs
URLhttps://github.com/dcodeIO/node.js-closure-compiler-externs
Versione891b4fbcf5f466cc4307b0fa842a7d8163a073a
LicenseApache 2.0 license
DescriptionType contracts for NodeJS APIs
Local ModificationsSubstantial changes to make them compatible with NpmCommandLineRunner.
504 | -------------------------------------------------------------------------------- /tests/doh/_browserRunner.js: -------------------------------------------------------------------------------- 1 | if(window["dojo"]){ 2 | dojo.provide("doh._browserRunner"); 3 | } 4 | 5 | // FIXME: need to add prompting for monkey-do testing 6 | 7 | (function(){ 8 | 9 | doh.setTimeout = function (fn, time) { 10 | return setTimeout(fn, time); 11 | }; 12 | 13 | try{ 14 | var topdog = (window.parent == window) || !Boolean(window.parent.doh); 15 | }catch(e){ 16 | //can't access window.parent.doh, then consider ourselves as topdog 17 | topdog=true; 18 | } 19 | if(topdog){ 20 | // we're the top-dog window. 21 | 22 | // borrowed from Dojo, etc. 23 | var byId = function(id){ 24 | return document.getElementById(id); 25 | }; 26 | 27 | var _addOnEvt = function( type, // string 28 | refOrName, // function or string 29 | scope){ // object, defaults is window 30 | 31 | if(!scope){ scope = window; } 32 | 33 | var funcRef = refOrName; 34 | if(typeof refOrName == "string"){ 35 | funcRef = scope[refOrName]; 36 | } 37 | var enclosedFunc = function(){ return funcRef.apply(scope, arguments); }; 38 | 39 | if((window["dojo"])&&(type == "load")){ 40 | dojo.addOnLoad(enclosedFunc); 41 | }else{ 42 | if(window["attachEvent"]){ 43 | window.attachEvent("on"+type, enclosedFunc); 44 | }else if(window["addEventListener"]){ 45 | window.addEventListener(type, enclosedFunc, false); 46 | }else if(document["addEventListener"]){ 47 | document.addEventListener(type, enclosedFunc, false); 48 | } 49 | } 50 | }; 51 | 52 | // 53 | // Over-ride or implement base runner.js-provided methods 54 | // 55 | var escapeXml = function(str){ 56 | //summary: 57 | // Adds escape sequences for special characters in XML: &<>"' 58 | // Optionally skips escapes for single quotes 59 | return str.replace(/&/gm, "&").replace(//gm, ">").replace(/"/gm, """); // string 60 | }; 61 | 62 | var _logBacklog = [], _loggedMsgLen = 0; 63 | var sendToLogPane = function(args, skip){ 64 | var msg = ""; 65 | for(var x=0; x "); 75 | if(!byId("logBody")){ 76 | _logBacklog.push(msg); 77 | return; 78 | }else if(_logBacklog.length && !skip){ 79 | var tm; 80 | while((tm=_logBacklog.shift())){ 81 | sendToLogPane(tm, true); 82 | } 83 | } 84 | var logBody=byId("logBody"); 85 | var tn = document.createElement("div"); 86 | tn.innerHTML = msg; 87 | //tn.id="logmsg_"+logBody.childNodes.length; 88 | logBody.appendChild(tn); 89 | _loggedMsgLen++; 90 | } 91 | 92 | var findTarget = function(n){ 93 | while(n && !n.getAttribute('_target')){ 94 | n=n.parentNode; 95 | if(!n.getAttribute){ 96 | n=null; 97 | } 98 | } 99 | return n; 100 | } 101 | 102 | doh._jumpToLog = function(e){ 103 | //console.log(e); 104 | 105 | var node = findTarget(e?e.target:window.event.srcElement); 106 | if(!node){ 107 | return; 108 | } 109 | var _t = Number(node.getAttribute('_target')); 110 | var lb = byId("logBody"); 111 | if(_t>=lb.childNodes.length){ 112 | return; 113 | } 114 | var t = lb.childNodes[_t]; 115 | t.scrollIntoView(); 116 | if(window.dojo){ 117 | //t.parentNode.parentNode is
, only it has a explicitly set background-color, 118 | //all children of it are transparent 119 | var bgColor = dojo.style(t.parentNode.parentNode,'backgroundColor'); 120 | //node.parentNode is the tr which has background-color set explicitly 121 | var hicolor = dojo.style(node.parentNode,'backgroundColor'); 122 | var unhilight = dojo.animateProperty({ 123 | node: t, 124 | duration: 500, 125 | properties: 126 | { 127 | backgroundColor: { start:hicolor, end: bgColor } 128 | }, 129 | onEnd: function(){ 130 | t.style.backgroundColor=""; 131 | } 132 | }); 133 | var hilight = dojo.animateProperty({ 134 | node: t, 135 | duration: 500, 136 | properties: 137 | { 138 | backgroundColor: { start:bgColor, end: hicolor } 139 | }, 140 | onEnd: function(){ 141 | unhilight.play(); 142 | } 143 | }); 144 | hilight.play(); 145 | } 146 | }; 147 | 148 | doh._jumpToSuite = function(e){ 149 | var node = findTarget(e ? e.target : window.event.srcElement); 150 | if(!node){ 151 | return; 152 | } 153 | var _g = node.getAttribute('_target'); 154 | var gn = getGroupNode(_g); 155 | if(!gn){ 156 | return; 157 | } 158 | gn.scrollIntoView(); 159 | }; 160 | 161 | doh._init = (function(oi){ 162 | return function(){ 163 | var lb = byId("logBody"); 164 | if(lb){ 165 | // clear the console before each run 166 | while(lb.firstChild){ 167 | lb.removeChild(lb.firstChild); 168 | } 169 | _loggedMsgLen = 0; 170 | } 171 | this._totalTime = 0; 172 | this._suiteCount = 0; 173 | oi.apply(doh, arguments); 174 | } 175 | })(doh._init); 176 | 177 | doh._setupGroupForRun = (function(os){ 178 | //overload _setupGroupForRun to record which log line to jump to when a suite is clicked 179 | return function(groupName){ 180 | var tg = doh._groups[groupName]; 181 | doh._curTestCount = tg.length; 182 | doh._curGroupCount = 1; 183 | var gn = getGroupNode(groupName); 184 | if(gn){ 185 | //two lines will be added, scroll the second line into view 186 | gn.getElementsByTagName("td")[2].setAttribute('_target',_loggedMsgLen+1); 187 | } 188 | os.apply(doh,arguments); 189 | } 190 | })(doh._setupGroupForRun); 191 | 192 | doh._report = (function(or){ 193 | //overload _report to insert a tfoot 194 | return function(){ 195 | var tb = byId("testList"); 196 | if(tb){ 197 | var tfoots=tb.getElementsByTagName('tfoot'); 198 | if(tfoots.length){ 199 | tb.removeChild(tfoots[0]); 200 | } 201 | var foot = tb.createTFoot(); 202 | var row = foot.insertRow(-1); 203 | row.className = 'inProgress'; 204 | var cell=row.insertCell(-1); 205 | cell.colSpan=2; 206 | cell.innerHTML="Result"; 207 | cell = row.insertCell(-1); 208 | cell.innerHTML=this._testCount+" tests in "+this._groupCount+" groups /"+this._errorCount+" errors, "+this._failureCount+" failures"; 209 | cell.setAttribute('_target',_loggedMsgLen+1); 210 | row.insertCell(-1).innerHTML=doh._totalTime+"ms"; 211 | } 212 | 213 | //This location can do the final performance rendering for the results 214 | //of any performance tests. 215 | var plotResults = null; 216 | var standby; 217 | if(doh.perfTestResults){ 218 | if(window.dojo){ 219 | //If we have dojo and here are perf tests results, 220 | //well, we'll use the dojo charting functions 221 | dojo.require("dojox.charting.Chart2D"); 222 | dojo.require("dojox.charting.DataChart"); 223 | dojo.require("dojox.charting.plot2d.Scatter"); 224 | dojo.require("dojox.charting.plot2d.Lines"); 225 | dojo.require("dojo.data.ItemFileReadStore"); 226 | plotResults = doh._dojoPlotPerfResults; 227 | }else{ 228 | plotResults = doh._asciiPlotPerfResults; 229 | } 230 | try{ 231 | var g; 232 | var pBody = byId("perfTestsBody"); 233 | var chartsToRender = []; 234 | 235 | if(doh.perfTestResults){ 236 | doh.showPerfTestsPage(); 237 | } 238 | for(g in doh.perfTestResults){ 239 | var grp = doh.perfTestResults[g]; 240 | var hdr = document.createElement("h1"); 241 | hdr.appendChild(document.createTextNode("Group: " + g)); 242 | pBody.appendChild(hdr); 243 | var ind = document.createElement("blockquote"); 244 | pBody.appendChild(ind); 245 | var f; 246 | for(f in grp){ 247 | var fResults = grp[f]; 248 | if(!fResults){ continue; } 249 | var fhdr = document.createElement("h3"); 250 | fhdr.appendChild(document.createTextNode("TEST: " + f)); 251 | fhdr.style.textDecoration = "underline"; 252 | ind.appendChild(fhdr); 253 | var div = document.createElement("div"); 254 | ind.appendChild(div); 255 | 256 | //Figure out the basic info 257 | var results = "TRIAL SIZE: " + fResults.trials[0].testIterations + " iterations
" + 258 | "NUMBER OF TRIALS: " + fResults.trials.length + "
"; 259 | 260 | //Figure out the average test pass cost. 261 | var i; 262 | var iAvgArray = []; 263 | var tAvgArray = []; 264 | for(i = 0; i < fResults.trials.length; i++){ 265 | iAvgArray.push(fResults.trials[i].average); 266 | tAvgArray.push(fResults.trials[i].executionTime); 267 | } 268 | results += "AVERAGE TRIAL EXECUTION TIME: " + doh.average(tAvgArray).toFixed(10) + "ms.
"; 269 | results += "MAXIMUM TEST ITERATION TIME: " + doh.max(iAvgArray).toFixed(10) + "ms.
"; 270 | results += "MINIMUM TEST ITERATION TIME: " + doh.min(iAvgArray).toFixed(10) + "ms.
"; 271 | results += "AVERAGE TEST ITERATION TIME: " + doh.average(iAvgArray).toFixed(10) + "ms.
"; 272 | results += "MEDIAN TEST ITERATION TIME: " + doh.median(iAvgArray).toFixed(10) + "ms.
"; 273 | results += "VARIANCE TEST ITERATION TIME: " + doh.variance(iAvgArray).toFixed(10) + "ms.
"; 274 | results += "STANDARD DEVIATION ON TEST ITERATION TIME: " + doh.standardDeviation(iAvgArray).toFixed(10) + "ms.
"; 275 | 276 | //Okay, attach it all in. 277 | div.innerHTML = results; 278 | 279 | div = document.createElement("div"); 280 | div.innerHTML = "

Average Test Execution Time (in milliseconds, with median line)

"; 281 | ind.appendChild(div); 282 | div = document.createElement("div"); 283 | dojo.style(div, "width", "600px"); 284 | dojo.style(div, "height", "250px"); 285 | ind.appendChild(div); 286 | chartsToRender.push({ 287 | div: div, 288 | title: "Average Test Execution Time", 289 | data: iAvgArray 290 | }); 291 | 292 | div = document.createElement("div"); 293 | div.innerHTML = "

Average Trial Execution Time (in milliseconds, with median line)

"; 294 | ind.appendChild(div); 295 | div = document.createElement("div"); 296 | dojo.style(div, "width", "600px"); 297 | dojo.style(div, "height", "250px"); 298 | ind.appendChild(div); 299 | chartsToRender.push({ 300 | div: div, 301 | title: "Average Trial Execution Time", 302 | data: tAvgArray 303 | }); 304 | } 305 | } 306 | 307 | //Lazy-render these to give the browser time and not appear locked. 308 | var delayedRenders = function() { 309 | if(chartsToRender.length){ 310 | var chartData = chartsToRender.shift(); 311 | plotResults(chartData.div, chartData.title, chartData.data); 312 | } 313 | doh.setTimeout(delayedRenders, 50); 314 | }; 315 | doh.setTimeout(delayedRenders, 150); 316 | }catch(e){ 317 | doh.debug(e); 318 | } 319 | } 320 | or.apply(doh,arguments); 321 | } 322 | })(doh._report); 323 | 324 | if(this["opera"] && opera.postError){ 325 | doh.debug = function(){ 326 | var msg = ""; 327 | for(var x=0; x
 
"; 391 | tds[3].innerHTML = ""; 392 | 393 | tb.appendChild(tg); 394 | return tg; 395 | } 396 | 397 | var addFixtureToList = function(group, fixture){ 398 | if(!testTemplate){ return; } 399 | var cgn = groupNodes[group]; 400 | if(!cgn["__items"]){ cgn.__items = []; } 401 | var tn = testTemplate.cloneNode(true); 402 | var tds = tn.getElementsByTagName("td"); 403 | 404 | tds[2].innerHTML = fixture.name; 405 | tds[3].innerHTML = ""; 406 | 407 | var nn = (cgn.__lastFixture||cgn.__groupNode).nextSibling; 408 | if(nn){ 409 | nn.parentNode.insertBefore(tn, nn); 410 | }else{ 411 | cgn.__groupNode.parentNode.appendChild(tn); 412 | } 413 | // FIXME: need to make group display toggleable!! 414 | tn.style.display = "none"; 415 | cgn.__items.push(tn); 416 | return (cgn.__lastFixture = tn); 417 | } 418 | 419 | var getFixtureNode = function(group, fixture){ 420 | if(groupNodes[group]){ 421 | return groupNodes[group][fixture.name]; 422 | } 423 | return null; 424 | } 425 | 426 | var getGroupNode = function(group){ 427 | if(groupNodes[group]){ 428 | return groupNodes[group].__groupNode; 429 | } 430 | return null; 431 | } 432 | 433 | var updateBacklog = []; 434 | doh._updateTestList = function(group, fixture, unwindingBacklog){ 435 | if(!loaded){ 436 | if(group && fixture){ 437 | updateBacklog.push([group, fixture]); 438 | } 439 | return; 440 | }else if(updateBacklog.length && !unwindingBacklog){ 441 | var tr; 442 | while((tr=updateBacklog.shift())){ 443 | doh._updateTestList(tr[0], tr[1], true); 444 | } 445 | } 446 | if(group && fixture){ 447 | if(!groupNodes[group]){ 448 | groupNodes[group] = { 449 | "__groupNode": addGroupToList(group) 450 | }; 451 | } 452 | if(!groupNodes[group][fixture.name]){ 453 | groupNodes[group][fixture.name] = addFixtureToList(group, fixture) 454 | } 455 | } 456 | } 457 | 458 | doh._testRegistered = doh._updateTestList; 459 | 460 | doh._groupStarted = function(group){ 461 | if(this._suiteCount == 0){ 462 | this._runedSuite = 0; 463 | this._currentGlobalProgressBarWidth = 0; 464 | this._suiteCount = this._testCount; 465 | } 466 | // console.debug("_groupStarted", group); 467 | if(doh._inGroup != group){ 468 | doh._groupTotalTime = 0; 469 | doh._runed = 0; 470 | doh._inGroup = group; 471 | this._runedSuite++; 472 | } 473 | var gn = getGroupNode(group); 474 | if(gn){ 475 | gn.className = "inProgress"; 476 | } 477 | } 478 | 479 | doh._groupFinished = function(group, success){ 480 | // console.debug("_groupFinished", group); 481 | var gn = getGroupNode(group); 482 | if(gn && doh._inGroup == group){ 483 | doh._totalTime += doh._groupTotalTime; 484 | gn.getElementsByTagName("td")[3].innerHTML = doh._groupTotalTime+"ms"; 485 | gn.getElementsByTagName("td")[2].lastChild.className = ""; 486 | doh._inGroup = null; 487 | //doh._runedSuite++; 488 | var failure = doh._updateGlobalProgressBar(this._runedSuite/this._groupCount,success,group); 489 | gn.className = failure ? "failure" : "success"; 490 | //doh._runedSuite--; 491 | doh._currentGlobalProgressBarWidth = parseInt(this._runedSuite/this._groupCount*10000)/100; 492 | //byId("progressOuter").style.width = parseInt(this._runedSuite/this._suiteCount*100)+"%"; 493 | } 494 | if(doh._inGroup == group){ 495 | this.debug("Total time for GROUP \"",group,"\" is ",doh._groupTotalTime,"ms"); 496 | } 497 | } 498 | 499 | doh._testStarted = function(group, fixture){ 500 | // console.debug("_testStarted", group, fixture.name); 501 | var fn = getFixtureNode(group, fixture); 502 | if(fn){ 503 | fn.className = "inProgress"; 504 | } 505 | } 506 | 507 | var _nameTimes = {}; 508 | var _playSound = function(name){ 509 | if(byId("hiddenAudio") && byId("audio") && byId("audio").checked){ 510 | // console.debug("playing:", name); 511 | var nt = _nameTimes[name]; 512 | // only play sounds once every second or so 513 | if((!nt)||(((new Date)-nt) > 700)){ 514 | _nameTimes[name] = new Date(); 515 | var tc = document.createElement("span"); 516 | byId("hiddenAudio").appendChild(tc); 517 | tc.innerHTML = ''; 518 | } 519 | } 520 | } 521 | 522 | doh._updateGlobalProgressBar = function(p,success,group){ 523 | var outerContainer=byId("progressOuter"); 524 | 525 | var gdiv=outerContainer.childNodes[doh._runedSuite-1]; 526 | if(!gdiv){ 527 | gdiv=document.createElement('div'); 528 | outerContainer.appendChild(gdiv); 529 | gdiv.className='success'; 530 | gdiv.setAttribute('_target',group); 531 | } 532 | if(!success && !gdiv._failure){ 533 | gdiv._failure=true; 534 | gdiv.className='failure'; 535 | if(group){ 536 | gdiv.setAttribute('title','failed group '+group); 537 | } 538 | } 539 | var tp=parseInt(p*10000)/100; 540 | gdiv.style.width = (tp-doh._currentGlobalProgressBarWidth)+"%"; 541 | return gdiv._failure; 542 | } 543 | doh._testFinished = function(group, fixture, success){ 544 | var fn = getFixtureNode(group, fixture); 545 | var elapsed = fixture.endTime-fixture.startTime; 546 | if(fn){ 547 | fn.getElementsByTagName("td")[3].innerHTML = elapsed+"ms"; 548 | fn.className = (success) ? "success" : "failure"; 549 | fn.getElementsByTagName("td")[2].setAttribute('_target', _loggedMsgLen); 550 | if(!success){ 551 | _playSound("doh"); 552 | var gn = getGroupNode(group); 553 | if(gn){ 554 | gn.className = "failure"; 555 | _getGroupToggler(group)(null, true); 556 | } 557 | } 558 | } 559 | if(doh._inGroup == group){ 560 | var gn = getGroupNode(group); 561 | doh._runed++; 562 | if(gn && doh._curTestCount){ 563 | var p = doh._runed/doh._curTestCount; 564 | var groupfail = this._updateGlobalProgressBar((doh._runedSuite+p-1)/doh._groupCount,success,group); 565 | 566 | var pbar = gn.getElementsByTagName("td")[2].lastChild; 567 | pbar.className = groupfail?"failure":"success"; 568 | pbar.style.width = parseInt(p*100)+"%"; 569 | gn.getElementsByTagName("td")[3].innerHTML = parseInt(p*10000)/100+"%"; 570 | } 571 | } 572 | this._groupTotalTime += elapsed; 573 | this.debug((success ? "PASSED" : "FAILED"), "test:", fixture.name, elapsed, 'ms'); 574 | } 575 | 576 | // FIXME: move implementation to _browserRunner? 577 | doh.registerUrl = function( /*String*/ group, 578 | /*String*/ url, 579 | /*Integer*/ timeout){ 580 | var tg = new String(group); 581 | this.register(group, { 582 | name: url, 583 | setUp: function(){ 584 | doh.currentGroupName = tg; 585 | doh.currentGroup = this; 586 | doh.currentUrl = url; 587 | this.d = new doh.Deferred(); 588 | doh.currentTestDeferred = this.d; 589 | doh.showTestPage(); 590 | byId("testBody").src = url; 591 | }, 592 | timeout: timeout||10000, // 10s 593 | // timeout: timeout||1000, // 10s 594 | runTest: function(){ 595 | // FIXME: implement calling into the url's groups here!! 596 | return this.d; 597 | }, 598 | tearDown: function(){ 599 | doh.currentGroupName = null; 600 | doh.currentGroup = null; 601 | doh.currentTestDeferred = null; 602 | doh.currentUrl = null; 603 | // this.d.errback(false); 604 | // byId("testBody").src = "about:blank"; 605 | doh.showLogPage(); 606 | } 607 | }); 608 | } 609 | 610 | // 611 | // Utility code for runner.html 612 | // 613 | // var isSafari = navigator.appVersion.indexOf("Safari") >= 0; 614 | var tabzidx = 1; 615 | var _showTab = function(toShow, toHide){ 616 | // FIXME: I don't like hiding things this way. 617 | var i; 618 | for(i = 0; i < toHide.length; i++){ 619 | var node = byId(toHide[i]); 620 | if(node){ 621 | node.style.display="none"; 622 | } 623 | } 624 | toShow = byId(toShow); 625 | if(toShow){ 626 | with(toShow.style){ 627 | display = ""; 628 | zIndex = ++tabzidx; 629 | } 630 | } 631 | } 632 | 633 | doh.showTestPage = function(){ 634 | _showTab("testBody", ["logBody", "perfTestsBody"]); 635 | } 636 | 637 | doh.showLogPage = function(){ 638 | _showTab("logBody", ["testBody", "perfTestsBody"]); 639 | } 640 | 641 | doh.showPerfTestsPage = function(){ 642 | _showTab("perfTestsBody", ["testBody", "logBody"]); 643 | } 644 | 645 | var runAll = true; 646 | doh.toggleRunAll = function(){ 647 | // would be easier w/ query...sigh 648 | runAll = !runAll; 649 | if(!byId("testList")){ return; } 650 | var tb = byId("testList").tBodies[0]; 651 | var inputs = tb.getElementsByTagName("input"); 652 | var x=0; var tn; 653 | while((tn=inputs[x++])){ 654 | tn.checked = runAll; 655 | doh._groups[tn.group].skip = (!runAll); 656 | } 657 | } 658 | 659 | var listHeightTimer = null; 660 | var setListHeight = function(){ 661 | if(listHeightTimer){ 662 | clearTimeout(listHeightTimer); 663 | } 664 | var tl = byId("testList"); 665 | if(!tl){ return; } 666 | listHeightTimer = doh.setTimeout(function(){ 667 | tl.style.display = "none"; 668 | tl.style.display = ""; 669 | 670 | }, 10); 671 | } 672 | 673 | _addOnEvt("resize", setListHeight); 674 | _addOnEvt("load", setListHeight); 675 | _addOnEvt("load", function(){ 676 | if(loaded){ return; } 677 | loaded = true; 678 | groupTemplate = byId("groupTemplate"); 679 | if(!groupTemplate){ 680 | // make sure we've got an ammenable DOM structure 681 | return; 682 | } 683 | groupTemplate.parentNode.removeChild(groupTemplate); 684 | groupTemplate.style.display = ""; 685 | testTemplate = byId("testTemplate"); 686 | testTemplate.parentNode.removeChild(testTemplate); 687 | testTemplate.style.display = ""; 688 | doh._updateTestList(); 689 | }); 690 | 691 | _addOnEvt("load", 692 | function(){ 693 | // let robot code run if it gets to this first 694 | var __onEnd = doh._onEnd; 695 | doh._onEnd = function(){ 696 | __onEnd.apply(doh, arguments); 697 | if(doh._failureCount == 0){ 698 | doh.debug("WOOHOO!!"); 699 | _playSound("woohoo"); 700 | }else{ 701 | console.debug("doh._failureCount:", doh._failureCount); 702 | } 703 | if(byId("play")){ 704 | toggleRunning(); 705 | } 706 | } 707 | if(!byId("play")){ 708 | // make sure we've got an amenable DOM structure 709 | return; 710 | } 711 | var isRunning = false; 712 | var toggleRunning = function(){ 713 | // ugg, this would be so much better w/ dojo.query() 714 | if(isRunning){ 715 | byId("play").style.display = byId("pausedMsg").style.display = ""; 716 | byId("playingMsg").style.display = byId("pause").style.display = "none"; 717 | isRunning = false; 718 | }else{ 719 | byId("play").style.display = byId("pausedMsg").style.display = "none"; 720 | byId("playingMsg").style.display = byId("pause").style.display = ""; 721 | isRunning = true; 722 | } 723 | } 724 | doh.run = (function(oldRun){ 725 | return function(){ 726 | if(!doh._currentGroup){ 727 | toggleRunning(); 728 | } 729 | return oldRun.apply(doh, arguments); 730 | } 731 | })(doh.run); 732 | var btns = byId("toggleButtons").getElementsByTagName("span"); 733 | var node; var idx=0; 734 | while((node=btns[idx++])){ 735 | node.onclick = toggleRunning; 736 | } 737 | 738 | //Performance report generating functions! 739 | doh._dojoPlotPerfResults = function(div, name, dataArray) { 740 | var median = doh.median(dataArray); 741 | var medarray = []; 742 | 743 | var i; 744 | for(i = 0; i < dataArray.length; i++){ 745 | medarray.push(median); 746 | } 747 | 748 | var data = { 749 | label: "name", 750 | items: [ 751 | {name: name, trials: dataArray}, 752 | {name: "Median", trials: medarray} 753 | ] 754 | }; 755 | var ifs = new dojo.data.ItemFileReadStore({data: data}); 756 | 757 | var min = Math.floor(doh.min(dataArray)); 758 | var max = Math.ceil(doh.max(dataArray)); 759 | var step = (max - min)/10; 760 | 761 | //Lets try to pad out the bottom and top a bit 762 | //Then recalc the step. 763 | if(min > 0){ 764 | min = min - step; 765 | if(min < 0){ 766 | min = 0; 767 | } 768 | min = Math.floor(min); 769 | } 770 | if(max > 0){ 771 | max = max + step; 772 | max = Math.ceil(max); 773 | } 774 | step = (max - min)/10; 775 | 776 | var chart = new dojox.charting.DataChart(div, { 777 | type: dojox.charting.plot2d.Lines, 778 | displayRange:dataArray.length, 779 | xaxis: {min: 1, max: dataArray.length, majorTickStep: Math.ceil((dataArray.length - 1)/10), htmlLabels: false}, 780 | yaxis: {min: min, max: max, majorTickStep: step, vertical: true, htmlLabels: false} 781 | }); 782 | chart.setStore(ifs, {name:"*"}, "trials"); 783 | }; 784 | 785 | doh._asciiPlotPerfResults = function(){ 786 | //TODO: Implement! 787 | }; 788 | } 789 | ); 790 | }else{ 791 | // we're in an iframe environment. Time to mix it up a bit. 792 | 793 | _doh = window.parent.doh; 794 | var _thisGroup = _doh.currentGroupName; 795 | var _thisUrl = _doh.currentUrl; 796 | if(_thisGroup){ 797 | doh._testRegistered = function(group, tObj){ 798 | _doh._updateTestList(_thisGroup, tObj); 799 | } 800 | doh._onEnd = function(){ 801 | _doh._errorCount += doh._errorCount; 802 | _doh._failureCount += doh._failureCount; 803 | _doh._testCount += doh._testCount; 804 | // should we be really adding raw group counts? 805 | //_doh._groupCount += doh._groupCount; 806 | _doh.currentTestDeferred.callback(true); 807 | } 808 | var otr = doh._getTestObj; 809 | doh._getTestObj = function(){ 810 | var tObj = otr.apply(doh, arguments); 811 | tObj.name = _thisUrl+"::"+arguments[0]+"::"+tObj.name; 812 | return tObj; 813 | } 814 | doh.debug = doh.hitch(_doh, "debug"); 815 | doh.registerUrl = doh.hitch(_doh, "registerUrl"); 816 | doh._testStarted = function(group, fixture){ 817 | _doh._testStarted(_thisGroup, fixture); 818 | } 819 | doh._testFinished = function(g, f, s){ 820 | _doh._testFinished(_thisGroup, f, s); 821 | 822 | //Okay, there may be performance info we need to filter back 823 | //to the parent, so do that here. 824 | if(doh.perfTestResults){ 825 | try{ 826 | gName = g.toString(); 827 | var localFName = f.name; 828 | while(localFName.indexOf("::") >= 0){ 829 | localFName = localFName.substring(localFName.indexOf("::") + 2, localFName.length); 830 | } 831 | if(!_doh.perfTestResults){ 832 | _doh.perfTestResults = {}; 833 | } 834 | if(!_doh.perfTestResults[gName]){ 835 | _doh.perfTestResults[gName] = {}; 836 | } 837 | _doh.perfTestResults[gName][f.name] = doh.perfTestResults[gName][localFName]; 838 | }catch (e){ 839 | doh.debug(e); 840 | } 841 | } 842 | } 843 | doh._groupStarted = function(g){ 844 | if(!this._setParent){ 845 | _doh._curTestCount = this._testCount; 846 | _doh._curGroupCount = this._groupCount; 847 | this._setParent = true; 848 | } 849 | } 850 | doh._report = function(){ 851 | }; 852 | } 853 | } 854 | 855 | })(); 856 | -------------------------------------------------------------------------------- /tests/doh/runner.js: -------------------------------------------------------------------------------- 1 | // package system gunk. 2 | //try{ 3 | // dojo.provide("doh.runner"); 4 | //}catch(e){ 5 | if(!this["doh"]){ 6 | doh = {}; 7 | } 8 | //} 9 | 10 | // 11 | // Utility Functions and Classes 12 | // 13 | 14 | doh.selfTest = false; 15 | 16 | doh.global = this; 17 | 18 | doh.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){ 19 | var args = []; 20 | for(var x=2; x= 0)) { 205 | this._fire(); 206 | } 207 | }, 208 | 209 | _continue: function(res){ 210 | this._resback(res); 211 | this._unpause(); 212 | }, 213 | 214 | _resback: function(res){ 215 | this.fired = ((res instanceof Error) ? 1 : 0); 216 | this.results[this.fired] = res; 217 | this._fire(); 218 | }, 219 | 220 | _check: function(){ 221 | if(this.fired != -1){ 222 | if(!this.silentlyCancelled){ 223 | throw new Error("already called!"); 224 | } 225 | this.silentlyCancelled = false; 226 | return; 227 | } 228 | }, 229 | 230 | callback: function(res){ 231 | this._check(); 232 | this._resback(res); 233 | }, 234 | 235 | errback: function(res){ 236 | this._check(); 237 | if(!(res instanceof Error)){ 238 | res = new Error(res); 239 | } 240 | this._resback(res); 241 | }, 242 | 243 | addBoth: function(cb, cbfn){ 244 | var enclosed = this.getFunctionFromArgs(cb, cbfn); 245 | if(arguments.length > 2){ 246 | enclosed = doh.hitch(null, enclosed, arguments, 2); 247 | } 248 | return this.addCallbacks(enclosed, enclosed); 249 | }, 250 | 251 | addCallback: function(cb, cbfn){ 252 | var enclosed = this.getFunctionFromArgs(cb, cbfn); 253 | if(arguments.length > 2){ 254 | enclosed = doh.hitch(null, enclosed, arguments, 2); 255 | } 256 | return this.addCallbacks(enclosed, null); 257 | }, 258 | 259 | addErrback: function(cb, cbfn){ 260 | var enclosed = this.getFunctionFromArgs(cb, cbfn); 261 | if(arguments.length > 2){ 262 | enclosed = doh.hitch(null, enclosed, arguments, 2); 263 | } 264 | return this.addCallbacks(null, enclosed); 265 | }, 266 | 267 | addCallbacks: function(cb, eb){ 268 | this.chain.push([cb, eb]); 269 | if(this.fired >= 0){ 270 | this._fire(); 271 | } 272 | return this; 273 | }, 274 | 275 | _fire: function(){ 276 | var chain = this.chain; 277 | var fired = this.fired; 278 | var res = this.results[fired]; 279 | var self = this; 280 | var cb = null; 281 | while(chain.length > 0 && this.paused == 0){ 282 | // Array 283 | var pair = chain.shift(); 284 | var f = pair[fired]; 285 | if(f == null){ 286 | continue; 287 | } 288 | try { 289 | res = f(res); 290 | fired = ((res instanceof Error) ? 1 : 0); 291 | if(res instanceof doh.Deferred){ 292 | cb = function(res){ 293 | self._continue(res); 294 | }; 295 | this._pause(); 296 | } 297 | }catch(err){ 298 | fired = 1; 299 | res = err; 300 | } 301 | } 302 | this.fired = fired; 303 | this.results[fired] = res; 304 | if((cb)&&(this.paused)){ 305 | res.addBoth(cb); 306 | } 307 | } 308 | }); 309 | 310 | // 311 | // State Keeping and Reporting 312 | // 313 | 314 | doh._testCount = 0; 315 | doh._groupCount = 0; 316 | doh._errorCount = 0; 317 | doh._failureCount = 0; 318 | doh._currentGroup = null; 319 | doh._currentTest = null; 320 | doh._paused = true; 321 | 322 | doh._init = function(){ 323 | this._currentGroup = null; 324 | this._currentTest = null; 325 | this._errorCount = 0; 326 | this._failureCount = 0; 327 | this.debug(this._testCount, "tests to run in", this._groupCount, "groups"); 328 | } 329 | 330 | // doh._urls = []; 331 | doh._groups = {}; 332 | 333 | // 334 | // Test Registration 335 | // 336 | 337 | doh.registerTestNs = function(/*String*/ group, /*Object*/ ns){ 338 | // summary: 339 | // adds the passed namespace object to the list of objects to be 340 | // searched for test groups. Only "public" functions (not prefixed 341 | // with "_") will be added as tests to be run. If you'd like to use 342 | // fixtures (setUp(), tearDown(), and runTest()), please use 343 | // registerTest() or registerTests(). 344 | for(var x in ns){ 345 | if( (x.charAt(0) != "_") && 346 | (typeof ns[x] == "function") ){ 347 | this.registerTest(group, ns[x]); 348 | } 349 | } 350 | } 351 | 352 | doh._testRegistered = function(group, fixture){ 353 | // slot to be filled in 354 | } 355 | 356 | doh._groupStarted = function(group){ 357 | // slot to be filled in 358 | } 359 | 360 | doh._groupFinished = function(group, success){ 361 | // slot to be filled in 362 | } 363 | 364 | doh._testStarted = function(group, fixture){ 365 | // slot to be filled in 366 | } 367 | 368 | doh._testFinished = function(group, fixture, success){ 369 | // slot to be filled in 370 | } 371 | 372 | doh.registerGroup = function( /*String*/ group, 373 | /*Array||Function||Object*/ tests, 374 | /*Function*/ setUp, 375 | /*Function*/ tearDown, 376 | /*String*/ type){ 377 | // summary: 378 | // registers an entire group of tests at once and provides a setUp and 379 | // tearDown facility for groups. If you call this method with only 380 | // setUp and tearDown parameters, they will replace previously 381 | // installed setUp or tearDown functions for the group with the new 382 | // methods. 383 | // group: 384 | // string name of the group 385 | // tests: 386 | // either a function or an object or an array of functions/objects. If 387 | // an object, it must contain at *least* a "runTest" method, and may 388 | // also contain "setUp" and "tearDown" methods. These will be invoked 389 | // on either side of the "runTest" method (respectively) when the test 390 | // is run. If an array, it must contain objects matching the above 391 | // description or test functions. 392 | // setUp: a function for initializing the test group 393 | // tearDown: a function for initializing the test group 394 | // type: The type of tests these are, such as a group of performance tests 395 | // null/undefied are standard DOH tests, the valye 'perf' enables 396 | // registering them as performance tests. 397 | if(tests){ 398 | this.register(group, tests, type); 399 | } 400 | if(setUp){ 401 | this._groups[group].setUp = setUp; 402 | } 403 | if(tearDown){ 404 | this._groups[group].tearDown = tearDown; 405 | } 406 | } 407 | 408 | doh._getTestObj = function(group, test, type){ 409 | var tObj = test; 410 | if(typeof test == "string"){ 411 | if(test.substr(0, 4)=="url:"){ 412 | return this.registerUrl(group, test); 413 | }else{ 414 | tObj = { 415 | name: test.replace("/\s/g", "_") // FIXME: bad escapement 416 | }; 417 | tObj.runTest = new Function("t", test); 418 | } 419 | }else if(typeof test == "function"){ 420 | // if we didn't get a fixture, wrap the function 421 | tObj = { "runTest": test }; 422 | if(test["name"]){ 423 | tObj.name = test.name; 424 | }else{ 425 | try{ 426 | var fStr = "function "; 427 | var ts = tObj.runTest+""; 428 | if(0 <= ts.indexOf(fStr)){ 429 | tObj.name = ts.split(fStr)[1].split("(", 1)[0]; 430 | } 431 | // doh.debug(tObj.runTest.toSource()); 432 | }catch(e){ 433 | } 434 | } 435 | // FIXME: try harder to get the test name here 436 | } 437 | 438 | //Augment the test with some specific options to make it identifiable as a 439 | //particular type of test so it can be executed properly. 440 | if(type === "perf" || tObj.testType === "perf"){ 441 | tObj.testType = "perf"; 442 | 443 | //Build an object on the root DOH class to contain all the test results. 444 | //Cache it on the test object for quick lookup later for results storage. 445 | if(!doh.perfTestResults){ 446 | doh.perfTestResults = {}; 447 | doh.perfTestResults[group] = {}; 448 | } 449 | if(!doh.perfTestResults[group]){ 450 | doh.perfTestResults[group] = {}; 451 | } 452 | if(!doh.perfTestResults[group][tObj.name]){ 453 | doh.perfTestResults[group][tObj.name] = {}; 454 | } 455 | tObj.results = doh.perfTestResults[group][tObj.name]; 456 | 457 | //If it's not set, then set the trial duration 458 | //default to 100ms. 459 | if(!("trialDuration" in tObj)){ 460 | tObj.trialDuration = 100; 461 | } 462 | 463 | //If it's not set, then set the delay between trial runs to 100ms 464 | //default to 100ms to allow for GC and to make IE happy. 465 | if(!("trialDelay" in tObj)){ 466 | tObj.trialDelay = 100; 467 | } 468 | 469 | //If it's not set, then set number of times a trial is run to 10. 470 | if(!("trialIterations" in tObj)){ 471 | tObj.trialIterations = 10; 472 | } 473 | } 474 | return tObj; 475 | } 476 | 477 | doh.registerTest = function(/*String*/ group, /*Function||Object*/ test, /*String*/ type){ 478 | // summary: 479 | // add the provided test function or fixture object to the specified 480 | // test group. 481 | // group: 482 | // string name of the group to add the test to 483 | // test: 484 | // either a function or an object. If an object, it must contain at 485 | // *least* a "runTest" method, and may also contain "setUp" and 486 | // "tearDown" methods. These will be invoked on either side of the 487 | // "runTest" method (respectively) when the test is run. 488 | // type: 489 | // An identifier denoting the type of testing that the test performs, such 490 | // as a performance test. If null, defaults to regular DOH test. 491 | if(!this._groups[group]){ 492 | this._groupCount++; 493 | this._groups[group] = []; 494 | this._groups[group].inFlight = 0; 495 | } 496 | var tObj = this._getTestObj(group, test, type); 497 | if(!tObj){ return null; } 498 | this._groups[group].push(tObj); 499 | this._testCount++; 500 | this._testRegistered(group, tObj); 501 | return tObj; 502 | } 503 | 504 | doh.registerTests = function(/*String*/ group, /*Array*/ testArr, /*String*/ type){ 505 | // summary: 506 | // registers a group of tests, treating each element of testArr as 507 | // though it were being (along with group) passed to the registerTest 508 | // method. It also uses the type to decide how the tests should 509 | // behave, by defining the type of tests these are, such as performance tests 510 | for(var x=0; x 1) ? "s" : "")+" to run"); 767 | } 768 | 769 | doh._handleFailure = function(groupName, fixture, e){ 770 | // this.debug("FAILED test:", fixture.name); 771 | // mostly borrowed from JUM 772 | this._groups[groupName].failures++; 773 | var out = ""; 774 | if(e instanceof this._AssertFailure){ 775 | this._failureCount++; 776 | if(e["fileName"]){ out += e.fileName + ':'; } 777 | if(e["lineNumber"]){ out += e.lineNumber + ' '; } 778 | out += e+": "+e.message; 779 | this.debug("\t_AssertFailure:", out); 780 | }else{ 781 | this._errorCount++; 782 | } 783 | this.debug(e); 784 | if(fixture.runTest["toSource"]){ 785 | var ss = fixture.runTest.toSource(); 786 | this.debug("\tERROR IN:\n\t\t", ss); 787 | }else{ 788 | this.debug("\tERROR IN:\n\t\t", fixture.runTest); 789 | } 790 | 791 | if(e.rhinoException){ 792 | e.rhinoException.printStackTrace(); 793 | }else if(e.javaException){ 794 | e.javaException.printStackTrace(); 795 | } 796 | } 797 | 798 | //Assume a setTimeout implementation that is synchronous, so that 799 | //the Node and Rhino envs work similar to each other. Node defines 800 | //a setTimeout, so testing for setTimeout is not enough, each environment 801 | //adapter should set this value accordingly. 802 | doh.setTimeout = function(func){ 803 | return func(); 804 | }; 805 | 806 | doh._runPerfFixture = function(/*String*/groupName, /*Object*/fixture){ 807 | // summary: 808 | // This function handles how to execute a 'performance' test 809 | // which is different from a straight UT style test. These 810 | // will often do numerous iterations of the same operation and 811 | // gather execution statistics about it, like max, min, average, 812 | // etc. It makes use of the already in place DOH deferred test 813 | // handling since it is a good idea to put a pause inbetween each 814 | // iteration to allow for GC cleanup and the like. 815 | // 816 | // groupName: 817 | // The test group that contains this performance test. 818 | // fixture: 819 | // The performance test fixture. 820 | var tg = this._groups[groupName]; 821 | fixture.startTime = new Date(); 822 | 823 | //Perf tests always need to act in an async manner as there is a 824 | //number of iterations to flow through. 825 | var def = new doh.Deferred(); 826 | tg.inFlight++; 827 | def.groupName = groupName; 828 | def.fixture = fixture; 829 | 830 | def.addErrback(function(err){ 831 | doh._handleFailure(groupName, fixture, err); 832 | }); 833 | 834 | //Set up the finalizer. 835 | var retEnd = function(){ 836 | if(fixture["tearDown"]){ fixture.tearDown(doh); } 837 | tg.inFlight--; 838 | if((!tg.inFlight)&&(tg.iterated)){ 839 | doh._groupFinished(groupName, !tg.failures); 840 | } 841 | doh._testFinished(groupName, fixture, def.results[0]); 842 | if(doh._paused){ 843 | doh.run(); 844 | } 845 | }; 846 | 847 | //Since these can take who knows how long, we don't want to timeout 848 | //unless explicitly set 849 | var timer; 850 | var to = fixture.timeout; 851 | if(to > 0) { 852 | timer = doh.setTimeout(function(){ 853 | // ret.cancel(); 854 | // retEnd(); 855 | def.errback(new Error("test timeout in "+fixture.name.toString())); 856 | }, to); 857 | } 858 | 859 | //Set up the end calls to the test into the deferred we'll return. 860 | def.addBoth(function(arg){ 861 | if(timer){ 862 | clearTimeout(timer); 863 | } 864 | retEnd(); 865 | }); 866 | 867 | //Okay, now set up the timing loop for the actual test. 868 | //This is down as an async type test where there is a delay 869 | //between each execution to allow for GC time, etc, so the GC 870 | //has less impact on the tests. 871 | var res = fixture.results; 872 | res.trials = []; 873 | 874 | //Try to figure out how many calls are needed to hit a particular threshold. 875 | var itrDef = doh._calcTrialIterations(groupName, fixture); 876 | itrDef.addErrback(function(err){ 877 | fixture.endTime = new Date(); 878 | def.errback(err); 879 | }); 880 | 881 | //Blah, since tests can be deferred, the actual run has to be deferred until after 882 | //we know how many iterations to run. This is just plain ugly. 883 | itrDef.addCallback(function(iterations){ 884 | if(iterations){ 885 | var countdown = fixture.trialIterations; 886 | doh.debug("TIMING TEST: [" + fixture.name + 887 | "]\n\t\tITERATIONS PER TRIAL: " + 888 | iterations + "\n\tTRIALS: " + 889 | countdown); 890 | 891 | //Figure out how many times we want to run our 'trial'. 892 | //Where each trial consists of 'iterations' of the test. 893 | 894 | var trialRunner = function() { 895 | //Set up our function to execute a block of tests 896 | var start = new Date(); 897 | var tTimer = new doh.Deferred(); 898 | var tCountdown = iterations; 899 | 900 | var tState = { 901 | countdown: iterations 902 | }; 903 | var testRunner = function(state){ 904 | while(state){ 905 | try{ 906 | state.countdown--; 907 | if(state.countdown){ 908 | var ret = fixture.runTest(doh); 909 | if(ret instanceof doh.Deferred){ 910 | //Deferreds have to be handled async, 911 | //otherwise we just keep looping. 912 | var atState = { 913 | countdown: state.countdown 914 | }; 915 | ret.addCallback(function(){ 916 | testRunner(atState); 917 | }); 918 | ret.addErrback(function(err) { 919 | doh._handleFailure(groupName, fixture, err); 920 | fixture.endTime = new Date(); 921 | def.errback(err); 922 | }); 923 | state = null; 924 | } 925 | }else{ 926 | tTimer.callback(new Date()); 927 | state = null; 928 | } 929 | }catch(err){ 930 | fixture.endTime = new Date(); 931 | tTimer.errback(err); 932 | } 933 | } 934 | }; 935 | tTimer.addCallback(function(end){ 936 | //Figure out the results and try to factor out function call costs. 937 | var tResults = { 938 | trial: (fixture.trialIterations - countdown), 939 | testIterations: iterations, 940 | executionTime: (end.getTime() - start.getTime()), 941 | average: (end.getTime() - start.getTime())/iterations 942 | }; 943 | res.trials.push(tResults); 944 | doh.debug("\n\t\tTRIAL #: " + 945 | tResults.trial + "\n\tTIME: " + 946 | tResults.executionTime + "ms.\n\tAVG TEST TIME: " + 947 | (tResults.executionTime/tResults.testIterations) + "ms."); 948 | 949 | //Okay, have we run all the trials yet? 950 | countdown--; 951 | if(countdown){ 952 | doh.setTimeout(trialRunner, fixture.trialDelay); 953 | }else{ 954 | //Okay, we're done, lets compute some final performance results. 955 | var t = res.trials; 956 | 957 | 958 | 959 | //We're done. 960 | fixture.endTime = new Date(); 961 | def.callback(true); 962 | } 963 | }); 964 | tTimer.addErrback(function(err){ 965 | fixture.endTime = new Date(); 966 | def.errback(err); 967 | }); 968 | testRunner(tState); 969 | }; 970 | trialRunner(); 971 | } 972 | }); 973 | 974 | //Set for a pause, returned the deferred. 975 | if(def.fired < 0){ 976 | doh.pause(); 977 | } 978 | return def; 979 | }; 980 | 981 | doh._calcTrialIterations = function(/*String*/ groupName, /*Object*/ fixture){ 982 | // summary: 983 | // This function determines the rough number of iterations to 984 | // use to reach a particular MS threshold. This returns a deferred 985 | // since tests can theoretically by async. Async tests aren't going to 986 | // give great perf #s, though. 987 | // The callback is passed the # of iterations to hit the requested 988 | // threshold. 989 | // 990 | // fixture: 991 | // The test fixture we want to calculate iterations for. 992 | var def = new doh.Deferred(); 993 | var calibrate = function () { 994 | var testFunc = fixture.runTest; 995 | 996 | //Set the initial state. We have to do this as a loop instead 997 | //of a recursive function. Otherwise, it blows the call stack 998 | //on some browsers. 999 | var iState = { 1000 | start: new Date(), 1001 | curIter: 0, 1002 | iterations: 5 1003 | }; 1004 | var handleIteration = function(state){ 1005 | while(state){ 1006 | if(state.curIter < state.iterations){ 1007 | try{ 1008 | var ret = testFunc(doh); 1009 | if(ret instanceof doh.Deferred){ 1010 | var aState = { 1011 | start: state.start, 1012 | curIter: state.curIter + 1, 1013 | iterations: state.iterations 1014 | }; 1015 | ret.addCallback(function(){ 1016 | handleIteration(aState); 1017 | }); 1018 | ret.addErrback(function(err) { 1019 | fixture.endTime = new Date(); 1020 | def.errback(err); 1021 | }); 1022 | state = null; 1023 | }else{ 1024 | state.curIter++; 1025 | } 1026 | }catch(err){ 1027 | fixture.endTime = new Date(); 1028 | def.errback(err); 1029 | return; 1030 | } 1031 | }else{ 1032 | var end = new Date(); 1033 | var totalTime = (end.getTime() - state.start.getTime()); 1034 | if(totalTime < fixture.trialDuration){ 1035 | var nState = { 1036 | iterations: state.iterations * 2, 1037 | curIter: 0 1038 | } 1039 | state = null; 1040 | doh.setTimeout(function(){ 1041 | nState.start = new Date(); 1042 | handleIteration(nState); 1043 | }, 50); 1044 | }else{ 1045 | var itrs = state.iterations; 1046 | doh.setTimeout(function(){def.callback(itrs)}, 50); 1047 | state = null; 1048 | } 1049 | } 1050 | } 1051 | }; 1052 | handleIteration(iState); 1053 | }; 1054 | doh.setTimeout(calibrate, 10); 1055 | return def; 1056 | }; 1057 | 1058 | doh._runRegFixture = function(/*String*/groupName, /*Object*/fixture){ 1059 | // summary: 1060 | // Function to run a generic doh test. These are not 1061 | // specialized tests, like performance groups and such. 1062 | // 1063 | // groupName: 1064 | // The groupName of the test. 1065 | // fixture: 1066 | // The test fixture to execute. 1067 | var tg = this._groups[groupName]; 1068 | fixture.startTime = new Date(); 1069 | var ret = fixture.runTest(this); 1070 | fixture.endTime = new Date(); 1071 | // if we get a deferred back from the test runner, we know we're 1072 | // gonna wait for an async result. It's up to the test code to trap 1073 | // errors and give us an errback or callback. 1074 | if(ret instanceof doh.Deferred){ 1075 | tg.inFlight++; 1076 | ret.groupName = groupName; 1077 | ret.fixture = fixture; 1078 | 1079 | ret.addErrback(function(err){ 1080 | doh._handleFailure(groupName, fixture, err); 1081 | }); 1082 | 1083 | var retEnd = function(){ 1084 | if(fixture["tearDown"]){ fixture.tearDown(doh); } 1085 | tg.inFlight--; 1086 | if((!tg.inFlight)&&(tg.iterated)){ 1087 | doh._groupFinished(groupName, !tg.failures); 1088 | } 1089 | doh._testFinished(groupName, fixture, ret.results[0]); 1090 | if(doh._paused){ 1091 | doh.run(); 1092 | } 1093 | } 1094 | 1095 | var timer = doh.setTimeout(function(){ 1096 | // ret.cancel(); 1097 | // retEnd(); 1098 | ret.errback(new Error("test timeout in "+fixture.name.toString())); 1099 | }, fixture["timeout"]||1000); 1100 | 1101 | ret.addBoth(function(arg){ 1102 | clearTimeout(timer); 1103 | retEnd(); 1104 | }); 1105 | if(ret.fired < 0){ 1106 | doh.pause(); 1107 | } 1108 | return ret; 1109 | } 1110 | }; 1111 | 1112 | doh._runFixture = function(groupName, fixture){ 1113 | var tg = this._groups[groupName]; 1114 | this._testStarted(groupName, fixture); 1115 | var threw = false; 1116 | var err = null; 1117 | // run it, catching exceptions and reporting them 1118 | try{ 1119 | // let doh reference "this.group.thinger..." which can be set by 1120 | // another test or group-level setUp function 1121 | fixture.group = tg; 1122 | // only execute the parts of the fixture we've got 1123 | 1124 | if(fixture["setUp"]){ fixture.setUp(this); } 1125 | if(fixture["runTest"]){ // should we error out of a fixture doesn't have a runTest? 1126 | if(fixture.testType === "perf"){ 1127 | //Always async deferred, so return it. 1128 | return doh._runPerfFixture(groupName, fixture); 1129 | }else{ 1130 | //May or may not by async. 1131 | var ret = doh._runRegFixture(groupName, fixture); 1132 | if(ret){ 1133 | return ret; 1134 | } 1135 | } 1136 | } 1137 | if(fixture["tearDown"]){ fixture.tearDown(this); } 1138 | }catch(e){ 1139 | threw = true; 1140 | err = e; 1141 | if(!fixture.endTime){ 1142 | fixture.endTime = new Date(); 1143 | } 1144 | } 1145 | var d = new doh.Deferred(); 1146 | doh.setTimeout(this.hitch(this, function(){ 1147 | if(threw){ 1148 | this._handleFailure(groupName, fixture, err); 1149 | } 1150 | this._testFinished(groupName, fixture, !threw); 1151 | 1152 | if((!tg.inFlight)&&(tg.iterated)){ 1153 | doh._groupFinished(groupName, !tg.failures); 1154 | }else if(tg.inFlight > 0){ 1155 | doh.setTimeout(this.hitch(this, function(){ 1156 | doh.runGroup(groupName); // , idx); 1157 | }), 100); 1158 | this._paused = true; 1159 | } 1160 | if(doh._paused){ 1161 | doh.run(); 1162 | } 1163 | }), 30); 1164 | doh.pause(); 1165 | return d; 1166 | } 1167 | 1168 | doh._testId = 0; 1169 | doh.runGroup = function(/*String*/ groupName, /*Integer*/ idx){ 1170 | // summary: 1171 | // runs the specified test group 1172 | 1173 | // the general structure of the algorithm is to run through the group's 1174 | // list of doh, checking before and after each of them to see if we're in 1175 | // a paused state. This can be caused by the test returning a deferred or 1176 | // the user hitting the pause button. In either case, we want to halt 1177 | // execution of the test until something external to us restarts it. This 1178 | // means we need to pickle off enough state to pick up where we left off. 1179 | 1180 | // FIXME: need to make fixture execution async!! 1181 | 1182 | var tg = this._groups[groupName]; 1183 | if(tg.skip === true){ return; } 1184 | if(this._isArray(tg)){ 1185 | if(idx<=tg.length){ 1186 | if((!tg.inFlight)&&(tg.iterated == true)){ 1187 | if(tg["tearDown"]){ tg.tearDown(this); } 1188 | doh._groupFinished(groupName, !tg.failures); 1189 | return; 1190 | } 1191 | } 1192 | if(!idx){ 1193 | tg.inFlight = 0; 1194 | tg.iterated = false; 1195 | tg.failures = 0; 1196 | } 1197 | doh._groupStarted(groupName); 1198 | if(!idx){ 1199 | this._setupGroupForRun(groupName, idx); 1200 | if(tg["setUp"]){ tg.setUp(this); } 1201 | } 1202 | for(var y=(idx||0); y"); 1438 | } 1439 | */ 1440 | } 1441 | } 1442 | }catch(e){ 1443 | print("\n"+doh._line); 1444 | print("The Dojo Unit Test Harness, $Rev: 20389 $"); 1445 | print("Copyright (c) 2009, The Dojo Foundation, All Rights Reserved"); 1446 | print(doh._line, "\n"); 1447 | 1448 | try{ 1449 | var dojoUrl = "../../dojo/dojo.js"; 1450 | var testUrl = ""; 1451 | var testModule = "dojo.tests.module"; 1452 | var dohBase = ""; 1453 | for(x=0; x