Skip to content

Getting Jest tests to ignore module  #146

@LukasDeco

Description

@LukasDeco

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions