Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Question: Is there any way to use local jest configuration ? #396

Closed
somarlyonks opened this issue Sep 10, 2018 · 3 comments
Closed

Question: Is there any way to use local jest configuration ? #396

somarlyonks opened this issue Sep 10, 2018 · 3 comments

Comments

@somarlyonks
Copy link

somarlyonks commented Sep 10, 2018

Is this a bug report?

No

I mean, a jest.config.js in rootDir, it looks like the createJestConfig just ignore the local configuration, and if I run it with

react-scripts-ts test --coverage --config=jest.config.js --env=jsdom

It complains that argv.config.match is not a function.

Env

  • node 8.10

  • dependecies

  "dependencies": {
    "bootstrap": "^4.1.1",
    "react": "^16.4.0",
    "react-dom": "^16.4.0"
  },
  "devDependencies": {
    "@types/jest": "^23.0.0",
    "@types/node": "^10.3.0",
    "@types/react": "^16.3.16",
    "@types/react-dom": "^16.0.5",
    "node-sass-chokidar": "^1.3.0",
    "react-scripts-ts": "2.17.0",
    "npm-run-all": "^4.1.3",
    "coveralls": "^3.0.2",
    "node-fetch": "^2.2.0",
    "typescript": "^3.0.3"
  }
@cjduncana
Copy link

I just encountered this problem as well, but I'm using Microsoft's repo.

@r3nya
Copy link
Contributor

r3nya commented Sep 28, 2018

Hey @somarlyonks!

Just change your npm task for running jest w/o react-scripts-ts, e.g.

"test": "jest --no-cache -w 2",

And don't forget to add some extra rules into your jest config (or package.json).

E.g. my jest config:

"jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!**/*.d.ts",
      "!**/*.test.api.ts"
    ],
    "setupFiles": [
      "<rootDir>/config/jest/setup.js",
      "<rootDir>/config/polyfills.js",
      "jest-localstorage-mock"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.ts?(x)",
      "<rootDir>/src/**/?(*.)(spec|test).ts?(x)"
    ],
    "testEnvironment": "jsdom",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.tsx?$": "ts-jest",
      "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$"
    ],
    "moduleNameMapper": {
      "^.+\\.css$": "identity-obj-proxy",
      "^react-native$": "react-native-web",
      "^src/([^\\.]*)$": "<rootDir>/src/$1"
    },
    "moduleFileExtensions": [
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "web.js",
      "js",
      "web.jsx",
      "jsx",
      "json",
      "node",
      "mjs"
    ],
    "globals": {
      "ts-jest": {
        "tsConfig": "./tsconfig.test.json"
      }
    },
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ]
},

Please let me know if you will have any problems. 😉

@somarlyonks
Copy link
Author

@r3nya Thanks a lot. It works.

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

No branches or pull requests

3 participants