Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch all versions of mocha loaded, not just the first one discovered. #25

Merged
merged 1 commit into from
Dec 15, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions mocha-as-promised.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(function (mochaAsPromised) {
"use strict";

function findNodeJSMocha(moduleToTest, suffix) {
function findNodeJSMocha(moduleToTest, suffix, acc) {
if (!acc) { acc = []; }

if (moduleToTest.id.indexOf(suffix, moduleToTest.id.length - suffix.length) !== -1 && moduleToTest.exports) {
return moduleToTest.exports;
acc.push(moduleToTest.exports);
}

for (var i = 0; i < moduleToTest.children.length; ++i) {
var found = findNodeJSMocha(moduleToTest.children[i], suffix);

if (found) {
return found;
}
findNodeJSMocha(moduleToTest.children[i], suffix, acc);
}

return acc;
}

// Module systems magic dance.
Expand Down Expand Up @@ -46,7 +46,11 @@
}
}

mochaAsPromised(mocha);
if (!Array.isArray(mocha)) {
mocha = [mocha];
}

mocha.forEach(mochaAsPromised);
};
} else if (typeof define === "function" && define.amd) {
// AMD
Expand All @@ -69,13 +73,11 @@
}
}

var duckPunchedAlready = false;

return function mochaAsPromised(mocha) {
if (duckPunchedAlready) {
if (mocha._mochaAsPromisedLoadedAlready) {
return;
}
duckPunchedAlready = true;
mocha._mochaAsPromisedLoadedAlready = true;

// Soooo this is an awesome hack.

Expand Down