-
Notifications
You must be signed in to change notification settings - Fork 13
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
Fix usage with test suites that mocks require #14
Conversation
Can you add a bit of detail here as to what's going on?
|
@ronkorving I have this error when I have require of le_node in my tests, I use Jest with mocha.
|
@bertho-zero And in your debugging that led you to this fix, what caused the issue? Can you show me the code in either Mocha or Jest that causes this problem? (I'm very willing to helping you land this PR, but I do really want to understand the problem that this solves) |
It's due to a simple require of le_node in my test, that use codependency.register (here), because Jest mocks all require. |
I still don't understand how this PR solves that. I was hoping for an explanation along the lines of:
If you catch my drift :) |
The parents of the module are crossed until we reach the mocked module. This does not include a require. What I do is just to check if the require method exists so as not to go up too high. |
To make me understand better, and to be able to create a unit test for this in the future, could you please share a small code sample that demonstrates the issue? |
My {
"name": "codependency-test",
"version": "1.0.0",
"main": "src/index.js",
"scripts": {
"build": "babel src -d lib -s",
"test": "jest",
"test:cov": "npm test -- --coverage",
"test:watch": "npm test -- --watch --coverage",
"cov:watch": "reload -d coverage/lcov-report -p 3300 -b"
},
"directories": {
"lib": "lib"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-runtime": "^6.26.0",
"le_node": "^1.7.1",
"winston": "^2.3.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-jest": "^21.0.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"jest": "^21.1.0",
"mocha": "^3.5.3",
"reload": "^2.2.2"
}
} And my import LE from 'le_node';
describe( 'un test bidon', () => {
it( 'empty test', () => {
console.log( 'ok' );
} );
} ); And when I run
|
Do you plan to merge this pull-request? it completely blocks my production |
I've tried to recreate your sample. I created a folder called I cannot run this with import statements.
Please give clear instructions. I also get the feeling it contains way more in package.json than you need to show the problem. Please go as minimalistic as you can, so I can focus on the problem (not 10 packages I don't know are relevant to this problem or not). Do you really need import statements, babel, etc? Minimalism would be most appreciated. |
|
Thank you, that gives me something to work with :) |
@ronkorving What do your investigations say? |
@ronkorving Hi! Any update on this? It is a bit problematic for me as its a dependency used by a module we have running in production. Cheers |
Sorry, not yet. I've not had much time to spend on any Open Source for the past weeks. I'm not forgetting, but I'm sorry to say I am unable to give this a very high priority. Very busy right now, private and at work. |
The reproduction given in #14 (comment) is fixed in the current beta version of jest |
BTW I've got this same error, and changing my code locally to this fixes my error. Essentially it fails because without this change baseMod.require is not a function:
|
Is this still an issue in the latest version of jest? If so, we should fix it there regardless of whether this change lands or not |
@SimenB I've updated to 22.4.2 of jest and that seems to have resolved the issue thanks. |
Then I will close this issue/PR. Thanks everyone for your patience and for dealing with this in Jest. If the issue is not gone for anyone, or on a different test platform, please open a new issue (and reference this one). Thanks! |
No description provided.