Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewire tests passed when code requires self. #148

Open
gabe0x02 opened this issue Sep 25, 2018 · 0 comments
Open

Rewire tests passed when code requires self. #148

gabe0x02 opened this issue Sep 25, 2018 · 0 comments

Comments

@gabe0x02
Copy link

I recently had a production issue when a require('./thisFile') got merged into a piece of code. The code passed tests using rewire but totally crashed without it. Here's an example:

Node: 8.10.0
Rewire: ^4.0.1

// code.js
const t = require('./code');

const mod = {};

mod.a = function a() {
	console.log('a');
	t.b();
};

mod.b = function b() {
	console.log('b');
};

module.exports = mod;
// require.js
const t = require('./code');
t.a();
// rewire.js
const rewire = require('rewire');
const t = rewire('./code');

t.a();
$ node require.js 
a
/code.js:7
	t.b();
	  ^

TypeError: t.b is not a function
    at Object.a (/code.js:7:4)
    at Object.<anonymous> (/require.js:2:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
$ node rewire.js 
a
b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant