mardi 29 octobre 2019

Jest can't run a standalone test

When running all the tests at once, everything is good, but when I try to run only one file from the terminal like jest Header.test.js it throws an error - like this My package.json

{
  "name": "bmiq-widget",
  "version": "0.1.0",
  "private": true,
  "main": "lib/index.js",
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.0",
    "@testing-library/react": "^9.3.0",
    "bmiq-style-guide": "*",
    "react": "^16.8.6",
    "react-app-polyfill": "^1.0.1",
    "react-dev-utils": "^9.0.1",
    "react-dom": "^16.8.6"
  },
  "devDependencies": {
    "npm-run-all": "*",
    "cross-env": "^5.2.0",
    "@babel/core": "7.4.3",
    "babel-eslint": "^10.0.1",
    "babel-jest": "^24.8.0",
    "babel-loader": "8.0.5",
    "babel-plugin-named-asset-import": "^0.3.2",
    "babel-preset-react-app": "^9.0.0",
    "eslint": "5.16.0",
    "eslint-config-react-app": "^4.0.1",
    "eslint-loader": "^2.1.2",
    "eslint-plugin-flowtype": "^2.50.1",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-hooks": "1.6.0",
    "eslint-config-airbnb": "^18.0.1",
    "@svgr/webpack": "4.1.0",
    "webpack": "4.29.6",
    "webpack-cli": "^3.3.0",
    "jest": "24.7.1",
    "jest-environment-jsdom-fourteen": "0.1.0",
    "jest-resolve": "24.7.1",
    "jest-watch-typeahead": "0.3.0"
  },
  "scripts": {
    "build": "npm-run-all build:widget build:lib",
    "build:widget": "cross-env NODE_ENV=production webpack --mode production --config webpack-widget.config.js",
    "build:lib": "cross-env NODE_ENV=production webpack --mode production --config webpack-main.config.js",
    "test": "jest --coverage --b --config jest.config.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

My .babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": [
    "@babel/plugin-proposal-class-properties"
  ]
}

My jest.config.js

module.exports = {
  roots: [
    '<rootDir>/src',
  ],
  collectCoverageFrom: [
    'src/**/*.{js,jsx,ts,tsx}',
    '!src/**/*.d.ts',
  ],
  setupFiles: [
    'react-app-polyfill/jsdom',
  ],
  setupFilesAfterEnv: [],
  testMatch: [
    '<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
    '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
  ],
  testEnvironment: 'jest-environment-jsdom-fourteen',
  transform: {
    '^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/babel-jest',
    '^.+\\.css$': '<rootDir>/config/jest/cssTransform.js',
    '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '<rootDir>/config/jest/fileTransform.js',
  },
  transformIgnorePatterns: [
    '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$',
    '^.+\\.module\\.(css|sass|scss)$',
  ],
  modulePaths: [],
  moduleNameMapper: {
    '^react-native$': 'react-native-web',
    '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
  },
  moduleFileExtensions: [
    'web.js',
    'js',
    'web.ts',
    'ts',
    'web.tsx',
    'tsx',
    'json',
    'web.jsx',
    'jsx',
    'node',
  ],
  watchPlugins: [
    'jest-watch-typeahead/filename',
    'jest-watch-typeahead/testname',
  ],
};

Any idea what's the problem? I've tried to change babel presets, also tried to change transformIgnorePatterns in the jest config file I have done researching for hours and no method helped. The strange fact is that when I running all the tests no error encounter, the error pop up when running only one file. Thanks beforehand.

Aucun commentaire:

Enregistrer un commentaire