Open tsuchiyama-araya opened 1 month ago
テストを動かすとnode_modulesのエラーが表示されます。
Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
node_modulesの対策をしてみましたがまた新しいエラーが表示されました。
Test suite failed to run
Cannot find module '/Users/tsuchiyama/Developer/barebone-studio/frontend/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault.js' from 'src/components/Workspace/FlowChart/TreeView.tsx'
Require stack:
src/components/Workspace/FlowChart/TreeView.tsx
src/components/Workspace/FlowChart/__tests__/TreeView.test.tsx
1 | import { memo, useCallback, useEffect } from "react"
2 | import { useDrag } from "react-dnd"
> 3 | import { useSelector, useDispatch } from "react-redux"
| ^
4 |
5 | import AddIcon from "@mui/icons-material/Add"
6 | import ChevronRightIcon from "@mui/icons-material/ChevronRight"
【行なった対策】 https://zenn.dev/t_yng/scraps/d701cdae1071fd https://qiita.com/miyuc/items/a5cae6252231e224f57f https://qiita.com/Sicut_study/items/ba23e8b8a22a3b5b0b3e https://zenn.dev/s_takashi/articles/72d864681aab1d https://stackoverflow.com/questions/71058618/to-have-some-of-your-node-modules-files-transformed-you-can-specify-a-custom
以下の指定を試したが、機能しているようだが、動作が不安定であるようなため、他の対処方法を追加調査
react-app-rewired test --transformIgnorePatterns "node_modules/(?!react-dnd)/"
対策
Add the common javascript libraries to your project I'm using yarn
yarn add react-dnd-cjs
yarn add react-dnd-html5-backend-cjs
Then in your package.json add..."jest": { "moduleNameMapper": { "react-dnd": "react-dnd-cjs", "react-dnd-html5-backend": "react-dnd-html5-backend-cjs", "dnd-core": "dnd-core-cjs" }
上記の対策は機能している模様。 ただし、対策後も transformIgnorePatterns 指定版と同様のエラーが出ているため、 このエラーが引き続き環境構築起因のものか、単にテストコードの不備に起因するものか、確認を要継続。
・Jestの環境に関する問題で時間が大幅にかかってしまいました。そのため、実際に1週間ほどかかりました。 ・現在、Jestの問題は解決しましたが、テストがまだすべて通過していないため、環境が完全に整っているかどうかはまだ確信が持てません。
8月30日 ・テストの書き方に問題があったことが確認できたため、環境構築は一旦解決しました。
FE自動テストの環境構築
【完了条件】