Skip to content

Commit

Permalink
Fixing debug module option-setting code.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jul 25, 2011
1 parent aad8d48 commit c6d7bd9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 10 additions & 5 deletions nobleModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@

el.addEventListener("load", onScriptLoad, false);
el.addEventListener("error", onScriptError, false);

// If in debug mode, we want to prevent caching, so append a timestamp to the URI. Separate it with underscores so that when
// debugging you can visually separate the filename (which you care about) from the timestamp (which you don't care about).
el.src = debugOptions.disableCaching ? uri + "?___________________________________" + Date.now() : uri;
Expand Down Expand Up @@ -583,16 +583,16 @@
// A special debugging module with access to our internal state.
var debugModule = Object.freeze({
setDebugOptions: function (options) {
if (options.enableCaching === !!options.enableCaching) {
debugOptions.enableCaching = options.enableCaching;
if (options.disableCaching === !!options.disableCaching) {
debugOptions.disableCaching = options.disableCaching;
}
if (options.warnAboutUndeclaredDependencies === !!options.warnAboutUndeclaredDependencies) {
debugOptions.warnAboutUndeclaredDependencies = options.warnAboutUndeclaredDependencies;
}
},
reset: reset,
listModules: function () {
console.dir(Object.keys(requireMemo).concat(Object.keys(pendingDeclarations)));
return Object.keys(requireMemo).concat(Object.keys(pendingDeclarations));
}
});

Expand All @@ -602,8 +602,13 @@
throw new TypeError("mainModuleDir must be a string.");
}

// Reset debug options.
debugOptions = {};
Object.keys(DEFAULT_DEBUG_OPTIONS).forEach(function (optionName) {
debugOptions[optionName] = DEFAULT_DEBUG_OPTIONS[optionName];
});

// Reset shared state.
debugOptions = DEFAULT_DEBUG_OPTIONS;
requireMemo = {};
pendingDeclarations = {};
scriptTagDeclareStorage = null;
Expand Down
14 changes: 8 additions & 6 deletions test/debugModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ asyncTest("By default, scripts are cached", function () {
debugModule.reset();

window.module.declare(["demos/math"], function (require, exports, module) {
var mathScriptEl = document.head.querySelector("script[src='demos/math.js']");

notStrictEqual(mathScriptEl, null, "In non-debug mode, the <script /> element was included directly");
var debugScriptEl = document.head.querySelector("script[src^='demos/math.js?']");
var directlyIncludedScriptEl = document.head.querySelector("script[src='demos/math.js']");

notStrictEqual(directlyIncludedScriptEl, null, "In non-debug mode, the <script /> element was included directly");
strictEqual(debugScriptEl, null, "In non-debug mode, the <script /> element was not included with a query string");

start();
});
Expand All @@ -28,11 +30,11 @@ asyncTest("If requested, caching is prevented", function () {
debugModule.setDebugOptions({ disableCaching: true });

window.module.declare(["demos/math"], function (require, exports, module) {
var mathScriptEl = document.head.querySelector("script[src^='demos/math.js']");
var directlyIncludedScriptEl = document.head.querySelector("script[src$='demos/math.js?']");
var debugScriptEl = document.head.querySelector("script[src^='demos/math.js?']");
var directlyIncludedScriptEl = document.head.querySelector("script[src='demos/math.js']");

strictEqual(directlyIncludedScriptEl, null, "In debug mode, the <script /> element was not included directly");
notStrictEqual(mathScriptEl, null, "In debug mode, the <script /> element was included with a query string");
notStrictEqual(debugScriptEl, null, "In debug mode, the <script /> element was included with a query string");

start();
});
Expand Down

0 comments on commit c6d7bd9

Please sign in to comment.