lundi 5 octobre 2020

Create React App with eject using component from submodule repository: Jest test fail.( SyntaxError: Unexpected token 'export')

I'm using Create React App that is ejected. I included my component repository as git submodule. My app run fine on local, and able to generate production build successfully. But when I run Jest test. I'm getting this error. code in submodule repository is not transpiling. and getting this error.

`import { STToastContainer } from 'design/atoms/Toast';`

I package.json file, this is my jest setting

"jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/**/*.d.ts"
    ],
    "resolver": "jest-pnp-resolver",
    "setupFiles": [
      "react-app-polyfill/jsdom"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/src/setupTests.js"
    ],
    "testMatch": [
    "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
    "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}",
    "<rootDir>/src/*.{js,jsx,ts,tsx}"
    ],
    "testEnvironment": "jsdom",
    "testURL": "http://localhost",
    "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)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
      "^util/(.*)$": "<rootDir>/src/util/$1",
      "^tests/*/*(.*)$": "<rootDir>/src/tests/$1",
      "^modules/*/*(.*)$": "<rootDir>/src/modules/$1",
      "^auth(.*)$": "<rootDir>/src/auth$1",
      "^store(.*)$": "<rootDir>/src/store$1",
      "^shared/*/*(.*)$": "<rootDir>/src/shared/$1"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  },

my babel.config.js

 module.exports = {
  presets: [["react-app",  { flow: false, typescript: true }]]
};

I'm using alias for submodule repository

    "_moduleAliases": {
    "design": "sastaticket-dsm/src"
  },

Aucun commentaire:

Enregistrer un commentaire