Esm: Integration issue with jest and mock-require

Created on 11 Jan 2018  路  5Comments  路  Source: standard-things/esm

Originally reported by @pahund on https://github.com/JLHwung/postcss-font-family-system-ui/issues/37.

The mock-require spies on Module._load to return mocked modules and passthrough the other request. However, when integrated with jest and esm, an error is thrown on the generated source of esm

/* 0 */
/***/ (function(module, exports) {

module.exports = require("path");

/***/ }),

the Module._load is then called with "path", undefined which panic the spy. I don't think this should be undefined here so I post to this repo.

馃 Interestingly, both jest and esm are required to produce this bug, when either of them is removed, the issue can not be reproduced.

I have constructed a minimal gist for reproduction. Please see https://gist.github.com/JLHwung/281f004baa1c40f28cc444f8e49e604f.

bug

Most helpful comment

Author of mock-require here, this bug should be fixed in version 3.0.0

All 5 comments

Thanks @JLHwung!

I know the root cause! I recently switched to using mod.require if I detect a mocked system since I can grab an unmocked require but in doing so I forgot to bind it mod.require.bind(mod).

The bug on mock-require is that Module._load should support passing an undefined or null parent.

馃槃
Ah I should have figured it out

const stdReq = useBuiltins ? require : stdMod.require

is the culprit and work on a hotfix.

Looking forward to a new patch release.

Author of mock-require here, this bug should be fixed in version 3.0.0

v0.19.2 is released 馃帀

馃挴 I can confirm that the issue is fixed, my Jest tests run as smoothly as ever. Thank you very much, and keep up the great work! 馃挴

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OmgImAlexis picture OmgImAlexis  路  3Comments

pvdlg picture pvdlg  路  3Comments

bensampaio picture bensampaio  路  3Comments

dnalborczyk picture dnalborczyk  路  3Comments

StphamZ picture StphamZ  路  3Comments