-
Notifications
You must be signed in to change notification settings - Fork 28
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
🐛 Bug: Failing in Jest #88
Comments
Similar issue after update (v1.0.1), but with ESLint
What resolved this for me was adding a Adding
|
@marsidev thanks for the quick response! I wanted to add to this thread that it was still failing after I upgraded (which fixed the original error, so thank you for updating it!) with an esm import error. Traced it back to my nextjs app and I had to add this to the config:
Related issue: vercel/next.js#35634 |
@smol-honk Thanks for sharing! I understand the problem occurs when we use Jest with Since the v1.0.0 we ship esm-only code, so that explains why it didn't happen before. To summarize, some solutions are:
// jest.config.js
const nextJest = require("next/jest");
const createJestConfig = nextJest({ dir: "./" });
const customJestConfig = {
testEnvironment: "jsdom",
};
async function jestConfig() {
const nextJestConfig = await createJestConfig(customJestConfig)();
nextJestConfig.transformIgnorePatterns[0] = "/node_modules/(?!@marsidev/react-turnstile)/";
return nextJestConfig;
}
module.exports = jestConfig;
// jest.config.ts
import type { Config } from "jest";
import nextJest from "next/jest";
import { createDefaultEsmPreset } from "ts-jest";
const createJestConfig = nextJest({ dir: "./" });
const defaultEsmPreset = createDefaultEsmPreset();
const config: Config = {
...defaultEsmPreset,
testEnvironment: "jsdom",
};
export default createJestConfig(config);
|
Bug Report Checklist
main
branch of the repository.Expected
Jest tests should be able to locate the react-turnstile library without failing.
Actual
I isolated it to this specific library. Our jest tests work inside a monorepo and we were originally using the other
react-turnstile
library fine but when I tried to switch to this one I get this error:Cannot find module '@marsidev/react-turnstile' from '../my-repo/CaptchaWidget/CaptchaWidget.tsx'
It stack traces from
at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/resolver.js:427:11)
Package Version
"^1.0.1"
Browsers
Chrome, Firefox, Safari, Microsoft Edge, Other
Additional Info
I originally thought it was our jest implementation, but after a bit of troubleshooting and trying to do resolvers I noticed it only reacted with this library.
How to reproduce
packages/components
)return <Turnstile siteKey={...} />
packages/app
packages/app
that import the turnstile component frompackages/components
The text was updated successfully, but these errors were encountered: