Skip to content
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

Getting Jest tests to ignore module #146

Open
LukasDeco opened this issue Sep 23, 2022 · 0 comments
Open

Getting Jest tests to ignore module #146

LukasDeco opened this issue Sep 23, 2022 · 0 comments

Comments

@LukasDeco
Copy link

I am trying to get jest tests to run that utilize this library in a nextjs application.

I am getting this error about es modules:

/home/user/Repos/project/realm-app/hosting/node_modules/rescript-apollo-client/src/@apollo/client/react/hooks/ApolloClient__React_Hooks_UseQuery.bs.js:3
    import * as Curry from "rescript/lib/es6/curry.js";
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

Has anyone been able to get this to work? Here is my jest.config.js:

const nextJest = require('next/jest')

const createJestConfig = nextJest({
  // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
  dir: './',
})

const customJestConfig = {
  testEnvironment: "jsdom",
  setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
  testPathIgnorePatterns: ["<rootDir>/.next/", "<rootDir>/node_modules/"],
  setupFiles: ["dotenv/config"],
  moduleNameMapper: {
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
      "<rootDir>/__mocks__/fileMock",
    "\\.(css|less)$": "<rootDir>/jest/__mocks__/styleMock",
    "^uuid$": "uuid",
    "rescript/lib/es6/(.*)": "<rootDir>/node_modules/rescript/lib/js/$1",
    "^rescript-apollo-client$": "rescript-apollo-client"
  },
  transformIgnorePatterns: ["/node_modules/(?!(@apollo|cropperjs|react|rescript|rescript-apollo-client)/)", "/node_modules/(?!(rescript-apollo-client)).+\\.bs\\.js$"],
  preset: "ts-jest",
  transform: {
    "^.+\\.(ts|tsx)?$": ["ts-jest", { "tsConfig": { jsx: "react" } }],
    "^.+\\.(js|jsx)$": "babel-jest",
  },
};

module.exports = createJestConfig(customJestConfig)

and . babelrc

{
  "presets": ["next/babel", "@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
  "plugins": []
}

Any ideas? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant