Skip to content

Commit

Permalink
fix(Tests, AMD:Plugins): Fixes normalize to use a proper ID
Browse files Browse the repository at this point in the history
The normalize function was using a qualified ID based only on the node,
not it's parent. This fixes the normalize function to behave as expected.
It likely broke when all the other branches were merged into the bower
preparation branch.
  • Loading branch information
jakobo committed Nov 19, 2013
1 parent ce8575e commit 7956833
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 64 deletions.
75 changes: 45 additions & 30 deletions dist/recent/inject.js
Expand Up @@ -951,7 +951,6 @@ var Analyzer;
*/

stripBuiltins: function (modules) {

var strippedModuleList = [],
len = modules.length,
i = 0;
Expand Down Expand Up @@ -1047,6 +1046,7 @@ var Communicator;
(function () {
var AsStatic = Fiber.extend(function () {

var alreadyListening = false;
var socket;
var socketInProgress;
var socketQueue = [];
Expand All @@ -1070,31 +1070,38 @@ var Communicator;
}
}

listenFor(window, 'message', function(e) {
var commands, command, params;

if (!userConfig.xd.relayFile) {
function beginListening() {
if (alreadyListening) {
return;
}
alreadyListening = true;

if (getDomainName(e.origin) !== getDomainName(userConfig.xd.relayFile)) {
return;
}
listenFor(window, 'message', function(e) {
var commands, command, params;

if (!userConfig.xd.relayFile) {
return;
}

if (getDomainName(e.origin) !== getDomainName(userConfig.xd.relayFile)) {
return;
}

commands = e.data.split(/:/);
command = commands.shift();
commands = e.data.split(/:/);
command = commands.shift();

switch (command) {
case 'ready':
socketInProgress = false;
resolveSocketQueue();
break;
case 'fetchFail':
case 'fetchOk':
params = JSON.parse(commands.join(':'));
resolveCompletedFile(params.url, params.status, params.responseText);
}
});
switch (command) {
case 'ready':
socketInProgress = false;
resolveSocketQueue();
break;
case 'fetchFail':
case 'fetchOk':
params = JSON.parse(commands.join(':'));
resolveCompletedFile(params.url, params.status, params.responseText);
}
});
}

/**
* Clear the records to socket connections and
Expand Down Expand Up @@ -1179,7 +1186,8 @@ var Communicator;
* @param {string} url - url where the content is located
* @private
*/
function sendViaIframe(url) {
function sendViaIframe(url) {
beginListening();
if (socket && !socketInProgress) {
sendMessage(socket.contentWindow, userConfig.xd.relayFile, 'fetch', {
url: url
Expand Down Expand Up @@ -2382,11 +2390,18 @@ var RequireContext = Fiber.extend(function () {
* @param {Function} callback - a function called when the module tree is downloaded and processed
* @private
*/
process: function(id, dependencies, callback) {
if (typeof id !== 'string') {
callback = dependencies;
dependencies = id;
process: function(possibleId) {
var id, dependencies, callback;

if (typeof possibleId !== 'string') {
id = this.id;
dependencies = arguments[0];
callback = arguments[1];
}
else {
id = arguments[0];
dependencies = arguments[1];
callback = arguments[2];
}

var root = new TreeNode();
Expand Down Expand Up @@ -2423,7 +2438,7 @@ var RequireContext = Fiber.extend(function () {
resolveCount();
continue;
}
else if (Executor.getModule(RequireContext.qualifiedId(node))) {
else if (Executor.getModule(RequireContext.qualifiedId(RulesEngine.resolveModule(node.data.originalId, root.data.resolvedId), node))) {
resolveCount();
continue;
}
Expand Down Expand Up @@ -3474,7 +3489,7 @@ var RulesEngine;
});
};

if (requires.length === 0) {
if (!requires.length) {
return downloadComplete();
}

Expand Down Expand Up @@ -3937,7 +3952,7 @@ context.Inject = {
// the contents of this are good
next(null, contents);
};

plugin.load(normalized, pluginRequire, onload, {});
});
});
Expand Down Expand Up @@ -4125,5 +4140,5 @@ context.require = context.Inject.require;
@public
*/
context.define = context.Inject.define;
;context.Inject.version = "0.5.2-7-ge922ef7";
;context.Inject.version = "0.5.2-10-gce8575e";
})(this);
4 changes: 2 additions & 2 deletions dist/recent/inject.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions server.js
Expand Up @@ -52,6 +52,10 @@ app.use('/examples/dependencies/addrule/jqueryui/jquery.ui.widget.min.js', delay
app.use('/tests/spec/modules-1.1.1/includes/bugs/bug_56_a.js', delay(300));
app.use('/tests/spec/amd/includes/bugs/bug_56_a.js', delay(300));

app.get('/inject.js', function(req, res) {
return res.redirect('/dist/recent/inject.js');
});

app.use(express.static(path.normalize(__dirname)));
app.use(express.static(path.normalize(path.join(__dirname, './', 'dist/recent'))));

Expand Down
1 change: 0 additions & 1 deletion src/analyzer.js
Expand Up @@ -41,7 +41,6 @@ var Analyzer;
*/

stripBuiltins: function (modules) {

var strippedModuleList = [],
len = modules.length,
i = 0;
Expand Down
51 changes: 30 additions & 21 deletions src/communicator.js
Expand Up @@ -26,6 +26,7 @@ var Communicator;
(function () {
var AsStatic = Fiber.extend(function () {

var alreadyListening = false;
var socket;
var socketInProgress;
var socketQueue = [];
Expand All @@ -49,31 +50,38 @@ var Communicator;
}
}

listenFor(window, 'message', function(e) {
var commands, command, params;

if (!userConfig.xd.relayFile) {
function beginListening() {
if (alreadyListening) {
return;
}
alreadyListening = true;

if (getDomainName(e.origin) !== getDomainName(userConfig.xd.relayFile)) {
return;
}
listenFor(window, 'message', function(e) {
var commands, command, params;

if (!userConfig.xd.relayFile) {
return;
}

commands = e.data.split(/:/);
command = commands.shift();
if (getDomainName(e.origin) !== getDomainName(userConfig.xd.relayFile)) {
return;
}

commands = e.data.split(/:/);
command = commands.shift();

switch (command) {
case 'ready':
socketInProgress = false;
resolveSocketQueue();
break;
case 'fetchFail':
case 'fetchOk':
params = JSON.parse(commands.join(':'));
resolveCompletedFile(params.url, params.status, params.responseText);
}
});
switch (command) {
case 'ready':
socketInProgress = false;
resolveSocketQueue();
break;
case 'fetchFail':
case 'fetchOk':
params = JSON.parse(commands.join(':'));
resolveCompletedFile(params.url, params.status, params.responseText);
}
});
}

/**
* Clear the records to socket connections and
Expand Down Expand Up @@ -158,7 +166,8 @@ var Communicator;
* @param {string} url - url where the content is located
* @private
*/
function sendViaIframe(url) {
function sendViaIframe(url) {
beginListening();
if (socket && !socketInProgress) {
sendMessage(socket.contentWindow, userConfig.xd.relayFile, 'fetch', {
url: url
Expand Down
2 changes: 1 addition & 1 deletion src/includes/context.js
Expand Up @@ -183,7 +183,7 @@ context.Inject = {
// the contents of this are good
next(null, contents);
};

plugin.load(normalized, pluginRequire, onload, {});
});
});
Expand Down
17 changes: 12 additions & 5 deletions src/requirecontext.js
Expand Up @@ -315,11 +315,18 @@ var RequireContext = Fiber.extend(function () {
* @param {Function} callback - a function called when the module tree is downloaded and processed
* @private
*/
process: function(id, dependencies, callback) {
if (typeof id !== 'string') {
callback = dependencies;
dependencies = id;
process: function(possibleId) {
var id, dependencies, callback;

if (typeof possibleId !== 'string') {
id = this.id;
dependencies = arguments[0];
callback = arguments[1];
}
else {
id = arguments[0];
dependencies = arguments[1];
callback = arguments[2];
}

var root = new TreeNode();
Expand Down Expand Up @@ -356,7 +363,7 @@ var RequireContext = Fiber.extend(function () {
resolveCount();
continue;
}
else if (Executor.getModule(RequireContext.qualifiedId(node))) {
else if (Executor.getModule(RequireContext.qualifiedId(RulesEngine.resolveModule(node.data.originalId, root.data.resolvedId), node))) {
resolveCount();
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/treerunner.js
Expand Up @@ -222,7 +222,7 @@ var TreeRunner = Fiber.extend(function () {
});
};

if (requires.length === 0) {
if (!requires.length) {
return downloadComplete();
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/communicator.html
Expand Up @@ -30,6 +30,7 @@
<div id="qunit"></div>
<script type="text/javascript" src="../../src/includes/constants.js"></script>
<script type="text/javascript" src="../../src/includes/globals.js"></script>
<script type="text/javascript" src="../../src/xd/postmessage.js"></script>
<script type="text/javascript" src="../../src/lib/fiber.js"></script>
<script type="text/javascript" src="../../src/communicator.js"></script>
<script type="text/javascript">
Expand Down
4 changes: 1 addition & 3 deletions tests/src/treerunner.html
Expand Up @@ -158,9 +158,7 @@
exports: {}
});

stubGetModule.returns({
exports: {}
});
stubGetModule.returns(null);

stubRunModule.returns({
exports: {}
Expand Down

0 comments on commit 7956833

Please sign in to comment.