I've done a good amount of research on this and have found a decent amount of solutions. I have found what feels like a workaround and would like to get the transform and transformIgnorePatterns working. It seems the only thing I can get working however is to manually add some mock modules inside of my __mocks__ folder.
Not sure if this is due to using Nextjs with Jest or not?
Here is my jest.config.js
const nextJest = require("next/jest");
const esModules = ["react-markdown", "rehype-raw", "remark-gfm"].join("|");
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
"^@/components/(.*)$": "<rootDir>/components/$1",
"^@/pages/(.*)$": "<rootDir>/pages/$1",
},
testEnvironment: "jest-environment-jsdom",
transform: {
[`(${esModules}).+\\.js$`]: "babel-jest",
},
transformIgnorePatterns: [
`[/\\\\]node_modules[/\\\\](?!${esModules}).+\\.(js|jsx|mjs|cjs|ts|tsx)$`,
],
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);
I have read that I will need a babel.config.js as well. Here is that file:
module.exports = {
presets: ["next/babel", "@babel/preset-env"],
};