thlorenz / proxyquire

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.
MIT License
2.75k stars 100 forks source link

updating from 1.7.4 to 1.7.7 breaking changes #122

Closed DanielZlotin closed 8 years ago

DanielZlotin commented 8 years ago

1.7.4 everything worked. broken test suite as a result from the update: (1.7.5 and 1.7.6 same issue)

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Module._extensions..js (module.js:422:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/danielzl/dev/wix-one-app/node_modules/babel-register/lib/node.js:138:7)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/danielzl/dev/wix-one-app/node_modules/proxyquire/lib/proxyquire.js:255:43)
    at Object.require.extensions.(anonymous function) (/Users/danielzl/dev/wix-one-app/node_modules/proxyquire/lib/proxyquire.js:255:43)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Proxyquire._require (/Users/danielzl/dev/wix-one-app/node_modules/proxyquire/lib/proxyquire.js:166:19)
    at require (internal/module.js:16:19)
bendrucker commented 8 years ago

Without your source code we can't look

DanielZlotin commented 8 years ago

@bendrucker What source do you need? this is my usage:

const rootPath = require('app-root-path');
const proxyquireLib = require('proxyquire');
...
test = {
proxyquire: (path, imports) => {
    return proxyquireLib.noCallThru().noPreserveCache()(rootPath.resolve(path), imports);
  }

...

const uut = test.proxyquire('src/reducers/session/actions', {
      'my-module': {}, ...
});
...

inside src/reducers/session/actions the first line is import _ from 'lodash'; before the update to 1.7.5 everything worked.

now it seems babel is not working with modules imported with proxyquire.

bendrucker commented 8 years ago

now it seems babel is not working with modules imported with proxyquire

As of 1.7.5 the noPreserveCache behavior deletes additional modules from the cache to resolve a bug: #102. We don't formally support transpilation right now even if it worked before. In order to get it working again and supported, we'll need a failing test and some investigation. Since I don't use Babel this is a relatively low priority for me. If you want to work on a PR I can review it, otherwise I'll come back to this and address it sometime.

bendrucker commented 8 years ago

For right now, just pin your version to 1.7.4