Skip to content

Commit

Permalink
Also reapply the test framework patch when a parent module of index.j…
Browse files Browse the repository at this point in the history
…s is retrieved from require's cache.

Fixes the scenario described in #205 when there's an unexpected-with-plugins.js or similar construct involved.
  • Loading branch information
papandreou committed Oct 14, 2015
1 parent 06f2211 commit c86281e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/*global __filename*/
var testFrameworkPatch = require('./testFrameworkPatch');
if (testFrameworkPatch.applyPatch() && typeof require === 'function' && require.cache) {
// Make sure that the 'it' global gets patched in every context where Unexpected is required,
// but prevent rereading index.js from disc each time:
Object.defineProperty(require.cache, __filename, {

function applyTestFrameworkPatchWhenLoaded(mod) {
Object.defineProperty(require.cache, mod.id, {
get: function () {
testFrameworkPatch.applyPatch();
return module;
return mod;
}
});
}

if (testFrameworkPatch.applyPatch() && typeof require === 'function' && require.cache) {
// Make sure that the 'it' global gets patched in every context where Unexpected is required,
// but prevent rereading index.js from disc each time:

for (var mod = module ; mod ; mod = mod.parent) {
applyTestFrameworkPatchWhenLoaded(mod);
}
}

module.exports = require('./Unexpected').create()
.use(require('./styles'))
.use(require('./types'))
Expand Down

0 comments on commit c86281e

Please sign in to comment.