Fails when proxyquire identifier used but not as a function #29

spudly opened this Issue Dec 22, 2016 · 4 comments


None yet

2 participants

spudly commented Dec 22, 2016

In my old tests, there are a lot of palces where proxyquire.noCallThru() is called (once per test usually), but this causes an exception in jest-codemods (switching from ava to jest).

ERR test/utils/zipPackageTest.js Transformation error
TypeError: Cannot read property '0' of undefined
  at NodePath.ast.find.forEach.p (/Users/ssorense/.nvm/versions/node/v7.0.0/lib/node_modules/jest-codemods/dist/utils/proxyquire.js:46:37)

I poked around the code a little bit and it seems that this happens because the proxyquire util expects the proxyquire variable to be used only as a function. In this case, it's not used as a function and so the util fails when i tries to get the function args that don't exist.

It's easy enough to workaround - just remove the function call from tests before running the codemod, but I though you guys would want to know it's breaking in this instance (and other people might be interested in the workaround).

skovhus commented Dec 23, 2016

Thanks for reporting this. I'll have a look at fixing this.

Can you give me a snall code example and maybe what you expect the transformed output to look like?

spudly commented Dec 23, 2016

In the transformed code, the call to noCallThru should simply be removed. It has no equivalent in jest and is not needed. I would expect some (very basic) code with proxyquire to be transformed as follows:


import proxyquire from 'proxyquire';
const a = proxyquire('a', {b: 'c'});


jest.mock('b', () => 'c');
const a = require('a');
skovhus commented Dec 23, 2016

Thanks! 👍

@skovhus skovhus closed this in 1d34f66 Dec 23, 2016
skovhus commented Dec 24, 2016

Bug fix released as 0.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment