-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Jest transform cache breaks tests using native code #3552
Comments
Do you have any pointers as to what might be causing this? |
Same as @jmurzy I'd be curious to know, also is this definitely happening with all native packages ? |
@alvinsight Looks like the issue with native modules is pretty much the same as #2826, nodejs/node#5016. Also, when |
A summary of why this change was required is discussed in the following issues: jestjs/jest#3552 jestjs/jest#3550 nodejs/node#5016
Discussion on why this change was required can be found in the following issues: jestjs/jest#3552 jestjs/jest#3550 nodejs/node#5016
Discussion on why this change was required can be found in the following issues: jestjs/jest#3552 jestjs/jest#3550 nodejs/node#5016
Discussion on why this change was required can be found in the following issues: jestjs/jest#3552 jestjs/jest#3550 nodejs/node#5016
Another one important thing needed for |
Adding
so it seems that it's impossible to debug tests with native. What's worse I need to run my tests serially and right now I can't do it because of that error. Does somebody know any workaround to do it? |
…n Jest Summary: Use jest's functionality for mocking modules to always return an empty object when `oniguruma` is required. This can be removed when jestjs/jest#3552 is addressed. Reviewed By: aaronabramov Differential Revision: D7422795 fbshipit-source-id: c5a25511a058499ab2ad494a86f8772d7f4bc802
…n Jest Summary: Use jest's functionality for mocking modules to always return an empty object when `oniguruma` is required. This can be removed when jestjs/jest#3552 is addressed. Reviewed By: aaronabramov Differential Revision: D7422795 fbshipit-source-id: c5a25511a058499ab2ad494a86f8772d7f4bc802
Facing this issue. It's annoying to have to use --no-cache completely because of this :/ |
Note that in my case,
To reproduce: git clone https://github.com/phenomic/phenomic.git
cd phenomic
git checkout 7adbf7dcac95f2f2de60e6111b97a3d06444d6fa
yarn
yarn tests You should get something like this
You will see that errors come from |
With Nodegit, the Is there any hope this will be resolved soon? |
Unable to use Jest reliably to test an Electron app with native modules because of this. Jest 24.8.0 and this kind of bug:
|
I was unable to fix this issue with the suggested comments unfortunately, setting the workers worked sometimes, but other times didn't, not sure why. I'm working around the issue by mocking the module that is causing the issue, which in my case is the 'ref-napi' sub-module of another module im using. Hopefully this could work for someone if that's possible in their use case as it was in mine. Jest 23.5.0 and i get ```FAIL tests/unit/libs/test.ts
|
@sbousamra I'm running into the same issue--how did you go about mocking the module? Thanks! |
@prurph In my case I have a __ mocks __ folder with mocks of certain modules I don't want to test, because I don't want my tests to fail if their module doesn't work for the purpose of unit tests. A mock of the file that was using ref-napi it looked something like this:
Then wherever I use said module, I call Hopefully this helps, let me know if you have any more questions, happy to try assist :). |
Cool--I get that, but what functions are you mocking in I was doing:
but that just causes Jest to die creating more workers:
Also simply mocking init and destroy as you've shown blows up in files that require modules that have Do you mind sharing your actual mocked |
Sorry I've re-read my post, and I realised since I made that post I changed my approach slightly haha. I'm not mocking ref-napi directly, I'm mocking the library I'm using that uses ref-napi. I tried mocking ref-napi too and ran into issues as well. Is it possible you're calling other functions of ref-napi in your project that you're not mocking there in your example? You might need to make sure you're not calling a single real function of theirs in your tests, and only mocks. I'm not sure what you're calling exactly, but that would be my first thing to check if it were me. Mocking argon2-ffi should work though if I'm understanding correctly, as I've definitely been able to mock a module that has ref-napi as a dependency. My mock file looks almost identical to what I linked in the previous post, so possibly something else going on that might be causing the issue. Sorry if that's not much help, if you can link more context I could try have a go at mocking it successfully for you, let me know if you make any progress. |
To anyone else who finds themselves with this issue, I ended up stubbing out // __mocks__/argon2-ffi.js
const hash = async function hash(buf, salt) {
return Promise.resolve(buf);
};
module.exports = {
argon2i: {
verify: async (hashed, buf) => {
return Promise.resolve(hashed === buf.toString());
},
hash,
},
}; |
I have a workaround that seems to work pretty well. It seems the issue only occurs when there are multiple test files that ultimately require the same problematic native module. Instead of letting Jest discover a bunch of files, you can give it a single entry point and require/import your files from there. In my Jest config:
test/index.js: require('./one.test');
require('./two.test');
// ... You could even glob for them and |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
Curious if there are any plans to address this issue in the next version of Jest when we have better/native ESM support? |
Can someone put together a minimal repository using Jest 27? The linked issues in the OP is 5+ years old. Also, no idea why "transform cache" has anything to do with this, seems like a red herring? |
Actually, seems fixed. I cloned https://github.com/stukalin/jest-nodegit-issue, updated to latest So if this is still an issue, I ask people to open up a new issue with a reproduction |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Tests pass on first run or with
--no-cache
flag, otherwise one of them fails.Repro
See following issues for details:
The text was updated successfully, but these errors were encountered: