-
Notifications
You must be signed in to change notification settings - Fork 31
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
TypeError: Cannot read property 'filename' of undefined #96
Comments
|
Hey thanks. :) No, I'm not wrapping rewiremock. I just put that line in because in the readme it said "this is important" so I just figured it was really important. Interestingly, when I switch to rewiremock version 3.12.3 it does work even with the "overrideEntryPoint" line. Also, it's not very clear wat this means, "I would recommend not to importing rewiremock directly from tests, but create a rewiremock.js file and require it - that way, you can preconfigure rewiremock for all tests." Huh?? Require it where? In app.js? In any random test? In the config of something? Imo it would be nice to have a clearer recommended spot to put this setup code. Other than that it's a pretty nice lib. 😁 thanks! |
Create |
I was running into this problem too, and was indeed confused by it. Tried to do as directed in the README, but it didn't work due to the exception. Then tried switching over to guided mocks, but had to change too much stuff, so gave up. May want to change some of the wording there, or make it less prominent, or add a FAQ section, or something. |
This is an example from my sources that ended up resolving the issue for me and is the sort of example that would benefit the README. I am using ava with the esm module. The test files are common js and the files being tested are es6 kpwe_activetabmsg.spec.js const rewiremock = require('rewiremock/node');
test('getactivetab, should return active tab', t => {
const kpwe_activetabmsg = rewiremock.proxy('../src/kpwe_activetabmsg.js', {
'../src/kpwe_webapi.js': {
tabs: {
query: (opts, fn) => params.push([ opts, fn ])
}
}
}).default;
kpwe_activetabmsg.getactivetab(() => {});
t.deepEqual( params[0][0], {
active : true,
currentWindow : true
});
}); rewiremock is kpwe_activetabmsg.js import kpwe_webapi from './kpwe_webapi.js'; |
@theKashey this is package is a terrific help to me and there is nothing else out there that handles this situation for me. This package should be more well-known. The README would benefit from editing/simplification. Humbly, thank you. |
Thanks for the kind words @iambumblehead. But I still haven't learned how to write clear and simple READMEs 😭 |
hey I can't solve this problem! Same error with helper/rewiremock.js
test.js
Someone can help me? |
patch version released - v3.14.3 @mi-mazouz - thank you for spotting the problem. |
Issue came back with mocha@9 |
To repro:
install rewiremock
put this is any js file or test:
Throws error:
TypeError: Cannot read property 'filename' of undefined
at getModuleName (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/module.js:99:24)
at Function.overrideEntryPoint (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/index.js:56:50)
at Function.overrideEntryPoint (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/index.js:57:18)
at Function.overrideEntryPoint (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/index.js:57:18)
at Function.overrideEntryPoint (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/index.js:57:18)
at Function.overrideEntryPoint (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/index.js:57:18)
at Function.overrideEntryPoint (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/rewiremock/lib/index.js:57:18)
at Object. (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/routes/users.test.js:5:12)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at /Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/mocha.js:334:36
at Array.forEach ()
at Mocha.loadFiles (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/mocha.js:331:14)
at Mocha.run (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/mocha.js:811:10)
at loadAndRun (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/cli/watch-run.js:46:22)
at module.exports (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/cli/watch-run.js:61:3)
at exports.runMocha (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/cli/run-helpers.js:140:5)
at Object.exports.handler.argv [as handler] (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/cli/run.js:292:3)
at Object.runCommand (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/yargs/lib/command.js:242:26)
at Object.parseArgs [as _parseArgs] (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/yargs/yargs.js:1087:28)
at Object.parse (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/yargs/yargs.js:566:25)
at Object.exports.main (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/lib/cli/cli.js:68:6)
at Object. (/Users/loaner/Git-Projects/NodeJS-Mocking-Deps-ofDeps-Example/node_modules/mocha/bin/mocha:154:29)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)
at bootstrap_node.js:617:3
The text was updated successfully, but these errors were encountered: