| 1 |
/* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */ |
| 2 |
import decache from 'decache'; |
| 3 |
import path from 'path'; |
| 4 |
|
| 5 |
function assertModule(t, filename, expected) { |
| 6 |
const absFilename = path.join(__dirname, '../fixture', filename); |
| 7 |
decache(absFilename); |
| 8 |
|
| 9 |
return t.is(require(absFilename), expected); |
| 10 |
} |
| 11 |
|
| 12 |
function makeNonPiratesHook(macro, value) { |
| 13 |
const oldLoader = require.extensions['.js']; |
| 14 |
require.extensions['.js'] = function loader(mod, filename) { |
| 15 |
const { _compile } = mod; |
| 16 |
mod._compile = function newCompile(code) { |
| 17 |
if (path.resolve(filename, '..') === __dirname) |
| 18 |
return _compile.call(mod, code, filename); |
| 19 |
return _compile.call(mod, code.replace(macro, value), filename); |
| 20 |
}; |
| 21 |
oldLoader(mod, filename); |
| 22 |
}; |
| 23 |
} |
| 24 |
|
| 25 |
export { assertModule, makeNonPiratesHook }; |