Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 19 commits
  • 25 files changed
  • 0 commit comments
  • 4 contributors
Commits on Apr 24, 2012
@chaozhang chaozhang get error line number for module js
5f66497
Commits on Apr 28, 2012
Yevgeniy Brikman Make sure named amd modules are handled correctly.
7fe7cbe
Commits on Apr 30, 2012
@Jakobo added unit tests for #106
bc72d5b
@Jakobo test refactoring, split bugs into their own QUnit files for maintaina…
…bility
b3ce77c
Commits on May 03, 2012
@chaozhang chaozhang Merge branch 'master' of github.com:linkedin/inject
ebbfa2f
@chaozhang chaozhang prototype solution for FF/Chrome
c08f784
@chaozhang chaozhang clean up
8cfe2a4
Commits on May 07, 2012
Yevgeniy Brikman Make sure query string params are handled properly in pointcut paths.
3fd28fa
@jleppert jleppert Added inject test to ensure proper handling of query string params in…
… pointcut paths
694c51c
@Jakobo Fixes #110. Fixes #109. Fixes #108. Merges Jim and Johnathan's change…
…s together to provide test coverage for fix. Supports query string in URL paths when using manifest and addRule syntax.
034dfc1
Commits on May 16, 2012
@Jakobo Update README.markdown
baba3b2
@Jakobo Updated README with minor typo fix
62f5fb9
@Jakobo Merge remote-tracking branch 'chaozhang/master' into line_num
ae525d3
@Jakobo This combines the work of several people: #105 and #112
152fcf9
Commits on May 17, 2012
@Jakobo adds further support for the error reporting in FF/Chrome. Requires I…
…E test
5c9b2dc
@Jakobo massive test refactor to support localtunnel. Makes it easier to veri…
…fy IE
3c25432
@Jakobo added second type of syntax error, added support for end-of-file case…
…, simplified exception handling to passthrough with a later throw
55419cb
Commits on May 18, 2012
@Jakobo Merge pull request #114 from Jakobo/line_num
Line Number Support in Errors Fixes #105 #112
d306628
@Jakobo updated test for #1114 to better test the exception handling
e7d141a
View
4 README.markdown
@@ -47,6 +47,10 @@ exports.duck = waterfowl
If you injected this file, you could then say `var duck = new moduleName.duck()` and instantiate your object.
+Modifying your Library to Work with Inject
+===
+Sometimes, you have a library (jQuery, or Modernizr for example) which isn't CommonJS compliant. We've put together a [page of recipes](https://github.com/linkedin/inject/wiki/addRule-and-Your-Favorite-Library) for using the addRule() API with your favorite library.
+
JavaScript Minifiers
===
If you're using a JS Minifier for your module files (and you probably should), there are some important compilation options you need. Many minifiers obfuscate and optimize variables inside of functions, which will affect the ability of inject to identify your dependencies before runtime. For the greatest in-browser optimization, we recommend using [UglifyJS](https://github.com/mishoo/UglifyJS) since it allows you to protect specific reserved names while still mazimixing the amount of compression you can do. If running node isn't an option, YUI and Google compressors can also be used with the following options:
View
29 examples/deps/errors/rangeerror.js
@@ -0,0 +1,29 @@
+/*
+Inject
+Copyright 2011 Jakob Heuser
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS
+IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+express or implied. See the License for the specific language
+governing permissions and limitations under the License.
+*/
+
+// this file contains a type error
+
+function outOfRange() {
+ var foo = 'foo';
+}
+
+outOfRange();
+
+//range error, line 27
+outOfRange.error = new Array(Number.MAX_VALUE);
+
+exports.test = true
View
1  examples/deps/errors/referenceerror.js
@@ -28,6 +28,7 @@ var bar = function() {
// this is some more code
foo();
+// undefined function, error line 32
baz();
exports.biz = "boz";
View
7 examples/deps/errors/syntaxerror.js
@@ -27,10 +27,11 @@ function itemOne() {
var use = true;
+// syntax error, line 33/34 or 37 for end of input
var barTwo = function() {
- // here is the syntax error
+ // here is the error
if (use) {
- // no closing semi colon
+ // no semi colon
};
-exports.test = true
+exports.test = true
View
44 examples/deps/errors/syntaxerrorb.js
@@ -0,0 +1,44 @@
+/*
+Inject
+Copyright 2011 Jakob Heuser
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS
+IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+express or implied. See the License for the specific language
+governing permissions and limitations under the License.
+*/
+
+if (console && typeof(console.log) === "function") {
+ console.log("error file executing");
+}
+// this file contains a syntax error
+// it's used to show how line numbers are preserved for errors
+
+var use = true;
+
+function padding() {
+ var str = "";
+ str += "this is a string to change the line numbers";
+ str += "it should put the line number to a unique location";
+ str += "1";
+ str += "2";
+ str += "3";
+ str += "4";
+}
+
+// syntax error, line 39/40 or 44 for end of input
+var barTwo = function() {
+ // here is the error
+ if (use {
+ true;
+ }
+};
+
+exports.test = true
View
32 examples/deps/errors/typeerror.js
@@ -0,0 +1,32 @@
+/*
+Inject
+Copyright 2011 Jakob Heuser
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS
+IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+express or implied. See the License for the specific language
+governing permissions and limitations under the License.
+*/
+
+// this file contains a type error
+
+function typeError() {
+ this.date = null;
+ this.error = null;
+}
+
+var errorObj = new typeError();
+
+errorObj.date = new Date();
+
+// type error, line 30
+errorObj.error = 'error' in true;
+
+exports.test = true
View
4 examples/deps/named-module-customer.js
@@ -0,0 +1,4 @@
+// This module is defined inline in named-amd.html and should *NOT* result in a call to the server to download any file
+var NamedModule = require('named-module');
+
+console.log(NamedModule);
View
2  examples/index.html
@@ -40,6 +40,8 @@
<dd>how to use the addRule() syntax to support supplemental libraries such as jQuery UI</dd>
<dt><a href="versioning.html">addRule() for versioning</a>:</dt>
<dd>how to use the addRule() syntax to support versioning</dd>
+ <dt><a href="named-amd.html">Named AMD Module</a>:</dt>
+ <dd>Use a named AMD module as a way to package server-side generated JS code or as a way to override "require" statements that you don't want to make calls to your server.</dd>
</dl>
</body>
</html>
View
52 examples/named-amd.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <!--
+ Inject
+ Copyright 2011 Jakob Heuser
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an "AS
+ IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ express or implied. See the License for the specific language
+ governing permissions and limitations under the License.
+ -->
+ <!--[if lte IE 7]>
+ <script src="/ie-localstorage-json-shim.js" type="text/javascript" id="ie-localstorage-shim"></script>
+ <![endif]-->
+ <script type="text/javascript" src="/inject.js"></script>
+ <script type="text/javascript">
+ require.setModuleRoot("/examples/deps");
+ </script>
+</head>
+<body>
+<h1>Named AMD</h1>
+<p>Create a named module with AMD and then require it later on. Very useful for defining modules in the HTML from server-side rendered data. Also a handy way to work around require statements in modules that you want to "override".</p>
+
+<p><a href="index.html">Back to examples</a></p>
+
+<button id="clearit">Clear Cache</button>
+
+<script type="text/javascript">
+document.getElementById("clearit").onclick = function() {
+ require.clearCache();
+};
+
+// Define a named module in-line. This is a great way for a server-side rendered template to provide data to your JavaScript code.
+define('named-module', function() {
+ return {
+ foo: "bar"
+ };
+});
+
+// Any JS module that "requires" named-module will now get the data above instead of trying to load named-module.js
+require.run('named-module-customer');
+</script>
+</body>
+</html>
View
7 examples/syntax.html
@@ -35,9 +35,16 @@
require.clearCache();
};
+if (console && console.log && typeof(console.log) === "function") {
+ console.log("expected line numbers:\nsyntax: 31/37\nsyntaxb: 39/40\nreference: 32\nrange: 27\ntype: 30");
+}
+
require.setModuleRoot("/examples/deps");
require.run("errors/syntaxerror");
+require.run("errors/syntaxerrorb");
require.run("errors/referenceerror");
+require.run("errors/rangeerror");
+require.run("errors/typeerror");
</script>
</body>
</html>
View
149 src/inject.coffee
@@ -47,6 +47,9 @@ For more details, check out the github: https://github.com/Jakobo/inject
Constants and Registries used
###
isIE = eval("/*@cc_on!@*/false") # a test to determine if this is the IE engine (needed for source in eval commands)
+docHead = null # document.head reference
+onErrorOffset = 0 # offset for onerror calls
+funcCount = 0 # functions initialized to date
userConfig = {} # user configuration options (see reset)
undef = undef # undefined
schemaVersion = 1 # version of inject()'s localstorage schema
@@ -58,7 +61,7 @@ fileStorageToken = "FILEDB" # a storagetoken identifier we use (lscache)
fileStore = "Inject FileStorage" # file store to use
namespace = "Inject" # the namespace for inject() that is publicly reachable
userModules = {} # any mappings for module => handling defined by the user
-fileSuffix = /.*?\.(js|txt)$/ # Regex for identifying things that end in *.js or *.txt
+fileSuffix = /.*?\.(js|txt)(\?.*)?$/# Regex for identifying things that end in *.js or *.txt
hostPrefixRegex = /^https?:\/\// # prefixes for URLs that begin with http/https
hostSuffixRegex = /^(.*?)(\/.*|$)/ # suffix for URLs used to capture everything up to / or the end of the string
iframeName = "injectProxy" # the name for the iframe proxy created (Porthole)
@@ -86,12 +89,12 @@ these bookend the included code and insulate the scope so that it doesn't impact
or anything else.
###
commonJSHeader = '''
-(function() {
+__INJECT_NS__.execute.__FUNCTION_ID__ = function() {
with (window) {
var __module = __INJECT_NS__.createModule("__MODULE_ID__", "__MODULE_URI__"),
__require = __INJECT_NS__.require,
__exe = null;
- __INJECT_NS__.setModuleExports("__MODULE_ID__", __module.exports)
+ __INJECT_NS__.setModuleExports("__MODULE_ID__", __module.exports);
__exe = function(require, module, exports) {
__POINTCUT_BEFORE__
'''
@@ -99,12 +102,50 @@ commonJSFooter = '''
__POINTCUT_AFTER__
};
__INJECT_NS__.defineAs(__module.id);
- __exe.call(__module, __require, __module, __module.exports);
+ try {
+ __exe.call(__module, __require, __module, __module.exports);
+ }
+ catch (__EXCEPTION__) {
+ __module.error = __EXCEPTION__;
+ }
__INJECT_NS__.undefineAs();
return __module;
}
-})();
+};
+'''
+
+createEvalScript = (code) ->
+ if !docHead then docHead = document.getElementsByTagName("head")[0]
+ scr = document.createElement("script")
+ # attempt to set its content for injection
+ try
+ scr.text = code
+ catch innerTextException
+ try
+ scr.innerHTML = code
+ catch innerHTMLException
+ return false
+ return scr
+
+###
+Test the onError offset for debugging purposes
+Addresses the needs in #105 and #112
+###
+testScript = '''
+function Inject_Test_Known_Error() {
+ function nil() {}
+ nil("Known Syntax Error Line 3";
+}
'''
+testScriptNode = createEvalScript(testScript)
+oldError = context.onerror
+context.onerror = (err, where, line) ->
+ onErrorOffset = 3 - line
+ window.setTimeout () -> docHead.removeChild(testScriptNode)
+ return true
+docHead.appendChild(testScriptNode)
+context.onerror = oldError
+
db = {
###
@@ -797,6 +838,9 @@ downloadTree = (tree, callback) ->
else
sendToXhr(moduleId, processCallbacks)
+ # see if this module has already been loaded and processed
+ if db.module.getExports(moduleId) then return callback()
+
# queue our results when the file completes
db.queue.file.add(moduleId, onDownloadComplete)
@@ -940,8 +984,10 @@ executeFile = (moduleId) ->
cuts = getFormattedPointcuts(moduleId)
path = db.module.getPath(moduleId)
text = db.module.getFile(moduleId)
+ functionId = "exec#{funcCount++}"
header = commonJSHeader.replace(/__MODULE_ID__/g, moduleId)
.replace(/__MODULE_URI__/g, path)
+ .replace(/__FUNCTION_ID__/g, functionId)
.replace(/__INJECT_NS__/g, namespace)
.replace(/__POINTCUT_BEFORE__/g, cuts.before)
footer = commonJSFooter.replace(/__INJECT_NS__/g, namespace)
@@ -950,21 +996,89 @@ executeFile = (moduleId) ->
runHeader = header + "\n"
runCmd = [runHeader, text, ";", footer, sourceString].join("\n")
-
+
# todo: circular dependency resolution
- try
- module = context.eval(runCmd)
- catch err
- filePath = db.module.getPath(moduleId)
- message = "(inject module eval) #{err.message}\n in #{path}"
- newErr = new Error(message)
- newErr.name = err.name
- newErr.type = err.type
- newErr.origin = err
- throw newErr
+ module = evalModule({
+ moduleId: moduleId
+ cmd: runCmd
+ url: path
+ functionId: functionId
+ preamble: header,
+ originalCode: text
+ })
+
# save exports
db.module.setExports(module.id, module.exports)
+evalModule = (options) ->
+ ###
+ ## evalModule(moduleId, callback) ##
+ _internal_ eval js module code, also try to get error line number from orignal file
+ Webkit: we can use window.onerror() safely. Line - preamble gives us the correct line
+ Firefox: we need to subtract inject.js up until the onerror call
+ ###
+ moduleId = options.moduleId
+ code = options.cmd
+ url = options.url
+ functionId = options.functionId
+ preamble = options.preamble
+ originalCode = options.originalCode
+
+ oldError = context.onerror
+ errorObject = null
+ preambleLines = preamble.split(/\n/).length + 1
+ newError = (err, where, line) ->
+ actualErrorLine = onErrorOffset - preambleLines + line
+ linesOfCode = code.split("\n").length
+ originalLinesOfCode = originalCode.split("\n").length
+
+ # unexpected end of input handling
+ if line is linesOfCode then actualErrorLine = originalLinesOfCode
+
+ message = "Parse error in #{moduleId} (#{url}) on line #{actualErrorLine}:\n #{err}"
+ errorObject = new Error(message)
+ return true
+ getLineNumberFromException = (e) ->
+ # firefox
+ if typeof e.lineNumber isnt "undefined" and e.lineNumber isnt null then return e.lineNumber
+ # webkit
+ if e.stack
+ lines = e.stack.split("\n")
+ phrases = lines[1].split(":")
+ return parseInt(phrases[phrases.length - 2], 10)
+ return 0
+
+ context.onerror = newError
+
+ scr = createEvalScript(code)
+ if scr
+ docHead.appendChild(scr)
+ window.setTimeout () -> docHead.removeChild(scr)
+
+ if !errorObject
+ # at this point, the global function should be created
+ # if there was a parse error, we got juicy details
+ # execute the function, which will use onerror() again if we hit a
+ # problem
+ module = Inject.execute[functionId]()
+ if module.error
+ actualErrorLine = onErrorOffset - preambleLines + getLineNumberFromException(module.error)
+ message = "Parse error in #{moduleId} (#{url}) on line #{actualErrorLine}:\n #{module.error.message}"
+ errorObject = new Error(message)
+
+ # okay, clean up our mess
+ context.onerror = oldError
+ if Inject?.execute[functionId] then delete Inject.execute[functionId]
+
+ # throw a proper error if we failed somewhere
+ # get rid of all localstorage cache
+ if errorObject
+ require.clearCache();
+ throw errorObject
+
+ # yay, module!
+ return module
+
sendToXhr = (moduleId, callback) ->
###
## sendToXhr(moduleId, callback) ##
@@ -1039,6 +1153,7 @@ createModule = (id, uri, exports) ->
module["id"] = id || null
module["uri"] = uri || null
module["exports"] = exports || db.module.getExports(id) || {}
+ module["error"] = null
module["setExports"] = (xobj) ->
for own name in module["exports"]
throw new Error("cannot setExports when exports have already been set")
@@ -1276,6 +1391,7 @@ define = (moduleId, deps, callback) ->
# ensureModule should now contain everything we need in order to save this module
db.module.setExports(moduleId, module.exports)
+ db.module.setExecuted(moduleId, true)
db.module.setLoading(moduleId, false)
amdCallbackQueue = db.queue.amd.get(moduleId)
for amdCallback in amdCallbackQueue
@@ -1308,6 +1424,7 @@ context['Inject'] = {
'require': require,
'define': define,
'reset': reset,
+ 'execute': {},
'debug': () ->
console?.dir(_db)
}
View
18 tests/amd/amd.js
@@ -30,7 +30,7 @@ module("AMD Specification", {
});
asyncTest("Anon - simple", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/anon");
+ require.setModuleRoot("/tests/amd/includes/spec/anon");
require(["a","b"], function(a, b) {
equal("a", a.name);
equal("b", b.name);
@@ -40,7 +40,7 @@ asyncTest("Anon - simple", 3, function() {
});
asyncTest("Anon - circular", 6, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/anon");
+ require.setModuleRoot("/tests/amd/includes/spec/anon");
require(["require", "two", "funcTwo", "funcThree"], function(require, two, funcTwo, funcThree) {
var args = two.doSomething(),
twoInst = new funcTwo("TWO"),
@@ -57,7 +57,7 @@ asyncTest("Anon - circular", 6, function() {
});
asyncTest("Anon - relativeModuleId", 4, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/anon");
+ require.setModuleRoot("/tests/amd/includes/spec/anon");
require.addRule("array", {path:"impl/array"});
require(["require", "array"], function(require, array) {
equal("impl/array", array.name);
@@ -69,7 +69,7 @@ asyncTest("Anon - relativeModuleId", 4, function() {
});
asyncTest("Basic - defineAmd", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/basic");
+ require.setModuleRoot("/tests/amd/includes/spec/basic");
require.ensure(["one/defineAmd"], function() {
equal("object", typeof define.amd)
start();
@@ -77,7 +77,7 @@ asyncTest("Basic - defineAmd", 1, function() {
});
asyncTest("Basic - simple", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/basic");
+ require.setModuleRoot("/tests/amd/includes/spec/basic");
require(["a", "b"], function(a, b) {
equal("a", a.name);
equal("b", b.name);
@@ -87,7 +87,7 @@ asyncTest("Basic - simple", 3, function() {
});
asyncTest("Basic - circular", 6, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/basic");
+ require.setModuleRoot("/tests/amd/includes/spec/basic");
require(["require", "two", "funcTwo", "funcThree"], function(require, two, funcTwo, funcThree) {
var args = two.doSomething(),
twoInst = new funcTwo("TWO"),
@@ -104,7 +104,7 @@ asyncTest("Basic - circular", 6, function() {
});
asyncTest("Function String - funcString", 8, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/funcstring");
+ require.setModuleRoot("/tests/amd/includes/spec/funcstring");
require(["one", "two", "three"], function(one, two, three) {
var args = two.doSomething(),
oneMod = two.getOneModule();
@@ -122,7 +122,7 @@ asyncTest("Function String - funcString", 8, function() {
});
asyncTest("Named Wrapped - basic", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/namewrapped");
+ require.setModuleRoot("/tests/amd/includes/spec/namewrapped");
require(["car"], function(car) {
equal("car", car.name);
equal("wheels", car.wheels.name);
@@ -132,7 +132,7 @@ asyncTest("Named Wrapped - basic", 3, function() {
});
asyncTest("Require - basic", 4, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/spec/require");
+ require.setModuleRoot("/tests/amd/includes/spec/require");
require.ensure(["require", "a"], function(require) {
require(["b", "c"], function(b, c) {
equal("a", require('a').name);
View
66 tests/amd/bugs.js
@@ -0,0 +1,66 @@
+/*
+Inject
+Copyright 2011 Jakob Heuser
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS
+IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+express or implied. See the License for the specific language
+governing permissions and limitations under the License.
+*/
+
+module("AMD Bugs", {
+ setup: function() {
+ if (localStorage) {
+ localStorage.clear();
+ }
+ Inject.reset();
+ },
+ teardown: function() {
+ if (localStorage) {
+ localStorage.clear();
+ }
+ }
+});
+
+asyncTest("#56 require.ensure with delay", 5, function() {
+ require.setModuleRoot("/tests/amd/includes/original");
+ require.ensure(["increment.delay"], function(require) {
+ var delayInc = require("increment.delay");
+ equal(delayInc.inc(5), 6, "increments");
+ equal(delayInc.delayedBy, 2000, "delayedBy");
+ start();
+ });
+});
+
+asyncTest("#91 module.exports should be able to have a function assigned to it in AMD mode", 1, function() {
+ require.setModuleRoot("/tests/amd/includes/bugs");
+ require.ensure(["bug_91"], function(require) {
+ var f = require('bug_91');
+ equal(f("Bob"), "hello Bob");
+ start();
+ });
+});
+
+asyncTest("#106 inline define() calls make module.exports available to later require() calls", 1, function() {
+ require.setModuleRoot("/tests/amd/includes/bugs");
+
+ // manually define a module
+ define("bug_106_pre", function() {
+ return {
+ foo: "foo"
+ };
+ });
+
+ require.ensure(["bug_106"], function(require) {
+ var mod = require('bug_106');
+ equal(mod.foo, "foo");
+ start();
+ });
+});
View
3  tests/amd/includes/bugs/bug_106.js
@@ -0,0 +1,3 @@
+
+var NamedModule = require('bug_106_pre');
+exports.foo = NamedModule.foo;
View
29 tests/amd/interface.js
@@ -30,7 +30,7 @@ module("AMD Interface", {
});
asyncTest("define(name, object)", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/original");
+ require.setModuleRoot("/tests/amd/includes/original");
require.ensure(["a"], function(require) {
var a = require("a");
equal(a.name, "a", "get a name");
@@ -39,7 +39,7 @@ asyncTest("define(name, object)", 1, function() {
});
asyncTest("define(name, dependencies (empty), function)", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/original");
+ require.setModuleRoot("/tests/amd/includes/original");
require.ensure(["b"], function(require) {
var b = require("b");
equal(b.name, "b", "get b name");
@@ -48,7 +48,7 @@ asyncTest("define(name, dependencies (empty), function)", 1, function() {
});
asyncTest("define(name, dependencies, function)", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/original");
+ require.setModuleRoot("/tests/amd/includes/original");
require.ensure(["c"], function(require) {
var c = require("c");
equal(c.name, "c", "get c name");
@@ -57,7 +57,7 @@ asyncTest("define(name, dependencies, function)", 1, function() {
});
asyncTest("define(name, dependencies (with exports), functio)n", 2, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/original");
+ require.setModuleRoot("/tests/amd/includes/original");
require.ensure(["d"], function(require) {
var d = require("d");
equal(d.name, "d", "get d name");
@@ -67,28 +67,9 @@ asyncTest("define(name, dependencies (with exports), functio)n", 2, function() {
});
asyncTest("define(dependencies (with exports), function)", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/original");
+ require.setModuleRoot("/tests/amd/includes/original");
require.ensure(["e"], function() {
ok(true, "anon define ensure callback executed");
start();
});
});
-
-asyncTest("#56 require.ensure with delay", 5, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/original");
- require.ensure(["increment.delay"], function(require) {
- var delayInc = require("increment.delay");
- equal(delayInc.inc(5), 6, "increments");
- equal(delayInc.delayedBy, 2000, "delayedBy");
- start();
- });
-});
-
-asyncTest("#91 module.exports should be able to have a function assigned to it in AMD mode", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/amd/includes/bugs");
- require.ensure(["bug_91"], function(require) {
- var f = require('bug_91');
- equal(f("Bob"), "hello Bob");
- start();
- });
-});
View
6 tests/index.html
@@ -22,13 +22,14 @@
<link rel="stylesheet" href="/tests/qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="/tests/qunit/qunit.js"></script>
<script type="text/javascript">
- QUnit.config.testTimeout = 1500;
+ QUnit.config.testTimeout = 3000;
</script>
<script type="text/javascript" src="/inject.js"></script>
<script type="text/javascript" src="/tests/modules-1.0/modules-1.0.js"></script>
<script type="text/javascript" src="/tests/modules-1.0/alternate-domain.js"></script>
+ <script type="text/javascript" src="/tests/modules-1.0/bugs.js"></script>
<script type="text/javascript" src="/tests/modules-1.1/modules-1.1.js"></script>
<script type="text/javascript" src="/tests/modules-1.1/async-a.js"></script>
@@ -38,8 +39,11 @@
<script type="text/javascript" src="/tests/amd/amd.js"></script>
<script type="text/javascript" src="/tests/amd/interface.js"></script>
+ <script type="text/javascript" src="/tests/amd/bugs.js"></script>
<script type="text/javascript" src="/tests/manifest/manifest.js"></script>
+ <script type="text/javascript" src="/tests/inject/inject.js"></script>
+
</head>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
View
9 tests/inject/includes/bugs/bug_105.js
@@ -0,0 +1,9 @@
+// test 105
+// this file contains a syntax error
+function showAlert() {
+ alert('Hello World!';
+}
+
+function okay() {
+ alert("everything is okay");
+}
View
44 tests/inject/inject.js
@@ -0,0 +1,44 @@
+module("Inject Tests", {
+ setup: function() {
+ if (localStorage) {
+ localStorage.clear();
+ }
+ Inject.reset();
+ },
+ teardown: function() {
+ if (localStorage) {
+ localStorage.clear();
+ }
+ }
+});
+
+asyncTest("Make sure query string params are handled properly in pointcut paths", 1, function() {
+ require.setModuleRoot("/examples/deps");
+
+ require.manifest({
+ "jQuery": {
+ path: "./jquery-1.6.4.min.js?foo=1&bar=2",
+ after: function(module) {
+ var a = document.createElement('a');
+ a.href = module.uri;
+ ok(a.search == "?foo=1&bar=2", "Query string parameters were properly preserved");
+ }
+ }
+ });
+
+ require.ensure(["jQuery"], function(require) {
+ start();
+ });
+});
+
+asyncTest("#105 exceptions surfaced correctly in console", 1, function() {
+ var oldError = window.onerror;
+ window.onerror = function(err, where, line) {
+ ok(/Parse error/.test(err), "raised syntax error exception");
+ window.onerror = oldError;
+ start();
+ return true;
+ };
+ require.setModuleRoot("/tests/inject/includes/bugs");
+ require.run("bug_105");
+});
View
24 tests/modules-1.0/alternate-domain.js
@@ -35,16 +35,18 @@ module("Multiple domain tests (based on Modules 1.0)", {
}
});
-asyncTest("same domain (baseline)", EXPECTATIONS, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/spec");
- require.run("program");
-});
-
-asyncTest("alternate domain", EXPECTATIONS, function() {
- require.setModuleRoot("http://localhost:4001/tests/modules-1.0/includes/spec");
- require.setCrossDomain("http://localhost:4000/relay.html",
- "http://localhost:4001/relay.html");
- require.run("program");
-});
+if (/localhost/.test(location.host)) {
+ asyncTest("same domain (baseline)", EXPECTATIONS, function() {
+ require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/spec");
+ require.run("program");
+ });
+
+ asyncTest("alternate domain", EXPECTATIONS, function() {
+ require.setModuleRoot("http://localhost:4001/tests/modules-1.0/includes/spec");
+ require.setCrossDomain("http://localhost:4000/relay.html",
+ "http://localhost:4001/relay.html");
+ require.run("program");
+ });
+}
})();
View
48 tests/modules-1.0/bugs.js
@@ -0,0 +1,48 @@
+/*
+Inject
+Copyright 2011 Jakob Heuser
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS
+IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+express or implied. See the License for the specific language
+governing permissions and limitations under the License.
+*/
+
+module("CommonJS: Modules 1.0 Bugs", {
+ setup: function() {
+ if (localStorage) {
+ localStorage.clear();
+ }
+ Inject.reset();
+ },
+ teardown: function() {
+ if (localStorage) {
+ localStorage.clear();
+ }
+ }
+});
+
+// requiring a module that has commented lines- those lines should not run
+asyncTest("#59 require() statements in commented lines should be ignored", 1, function() {
+ require.setModuleRoot("/tests/modules-1.0/includes/bugs");
+ require.run("bug_59");
+});
+
+// circular dependencies
+asyncTest("#65 circular dependencies should be resolved", 4, function() {
+ require.setModuleRoot("/tests/modules-1.0/includes/bugs");
+ require.run("bug_65");
+});
+
+// requiring a module that has commented lines- those lines should not run
+asyncTest("#88 require() statements with no space before them should still run", 2, function() {
+ require.setModuleRoot("/tests/modules-1.0/includes/bugs");
+ require.run("bug_88");
+});
View
26 tests/modules-1.0/modules-1.0.js
@@ -30,42 +30,24 @@ module("CommonJS: Modules 1.0", {
});
asyncTest("Sample Code", 4, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/spec");
+ require.setModuleRoot("/tests/modules-1.0/includes/spec");
require.run("program");
});
asyncTest("Compliance", 8, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/spec");
+ require.setModuleRoot("/tests/modules-1.0/includes/spec");
require.run("compliance");
});
// require math twice, the second time after a reset (simulate page reload)
asyncTest("#57 require from cache simulates an OK 200", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/spec");
+ require.setModuleRoot("/tests/modules-1.0/includes/spec");
require.ensure(["math"], function() {
Inject.reset();
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/spec");
+ require.setModuleRoot("/tests/modules-1.0/includes/spec");
require.ensure(["math"], function() {
ok(true, "module loaded from localStorage cache correctly");
start();
});
});
});
-
-// requiring a module that has commented lines- those lines should not run
-asyncTest("#59 require() statements in commented lines should be ignored", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/bugs");
- require.run("bug_59");
-});
-
-// circular dependencies
-asyncTest("#65 circular dependencies should be resolved", 4, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/bugs");
- require.run("bug_65");
-});
-
-// requiring a module that has commented lines- those lines should not run
-asyncTest("#88 require() statements with no space before them should still run", 2, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.0/includes/bugs");
- require.run("bug_88");
-});
View
8 tests/modules-1.1.1/modules-1.1.1.js
@@ -30,17 +30,17 @@ module("CommonJS: Modules 1.1.1", {
});
asyncTest("Compliance", 13, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1.1/includes/spec");
+ require.setModuleRoot("/tests/modules-1.1.1/includes/spec");
require.run("compliance");
});
asyncTest("Compliance - Module Identifiers", 8, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1.1/includes/spec/identifiers");
+ require.setModuleRoot("/tests/modules-1.1.1/includes/spec/identifiers");
require.run("terms");
});
asyncTest("Sample Code", 5, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1.1/includes/spec");
+ require.setModuleRoot("/tests/modules-1.1.1/includes/spec");
require.run("program");
});
@@ -49,7 +49,7 @@ asyncTest("#56 require.ensure should handle overlapping dependencies as pending"
foo depends on bar
bar has a delay of 3 seconds built in
*/
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1.1/includes/bugs");
+ require.setModuleRoot("/tests/modules-1.1.1/includes/bugs");
// this test has 2 asynchronous threads
var calls = 2;
require.ensure(["bug_56", "bug_56_a"], function(require) {
View
6 tests/modules-1.1/async-a.js
@@ -30,7 +30,7 @@ module("CommonJS: Modules 1.1 Extension - Async/A", {
});
asyncTest("require.ensure", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1/includes/spec");
+ require.setModuleRoot("/tests/modules-1.1/includes/spec");
require.ensure(['increment'], function(require) {
var inc = require('increment').increment;
var a = 1;
@@ -41,7 +41,7 @@ asyncTest("require.ensure", 3, function() {
// require.ensure was running dependencies at compile time
asyncTest("#58 require.ensure runtime dependencies only (false)", 1, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1/includes/bugs");
+ require.setModuleRoot("/tests/modules-1.1/includes/bugs");
require.ensure(["bug_58"], function(require) {
var runner = require("bug_58");
runner.runTest(false); // do not include subfile
@@ -49,7 +49,7 @@ asyncTest("#58 require.ensure runtime dependencies only (false)", 1, function()
});
asyncTest("#58 require.ensure runtime dependencies only (true)", 3, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1/includes/bugs");
+ require.setModuleRoot("/tests/modules-1.1/includes/bugs");
require.ensure(["bug_58"], function(require) {
var runner = require("bug_58");
runner.runTest(true); // include subfile
View
4 tests/modules-1.1/modules-1.1.js
@@ -30,11 +30,11 @@ module("CommonJS: Modules 1.1", {
});
asyncTest("Compliance", 13, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1/includes/spec");
+ require.setModuleRoot("/tests/modules-1.1/includes/spec");
require.run("compliance");
});
asyncTest("Sample Code", 5, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1/includes/spec");
+ require.setModuleRoot("/tests/modules-1.1/includes/spec");
require.run("program");
});
View
2  tests/modules-1.1/setexports.js
@@ -30,7 +30,7 @@ module("CommonJS: Modules 1.1 Extension - setExports", {
});
asyncTest("setExports proposal", 2, function() {
- require.setModuleRoot("http://localhost:4000/tests/modules-1.1/includes/proposal");
+ require.setModuleRoot("/tests/modules-1.1/includes/proposal");
require.ensure(["setexports"], function(require) {
var add = require("setexports");
equal(add(2), 3, "add function available");

No commit comments for this range

Something went wrong with that request. Please try again.