はじめに
Mac + React + Jestでテストが動作しない場合の対応方法。
現象
npm test
でテストを実行しようとすると以下のようなメッセージが表示される。
Watchman crawl failed. Retrying once with node crawler.
Usually this happens when watchman isn't running. Create an empty `.watchmanconfig` file
in your project's root folder or initialize a git or hg repository in your project.
Error: Watchman error: std::__1::system_error: open: /Users/xxxxx/Documents/xxxxx/src: Operation not permitted. Make sure watchman is running for this project. See https://facebook.github.io/watchman/docs/troubleshooting.
対策
メッセージにあるように、プロジェクトディレクトリに.watchmanconfig
を作成する。
→改善せず
ネットで調べると、どうやらwatchmanがプロジェクトディレクトリにアクセスできないことが原因のようす。
まずは、watchmanがインストールされているかを確認。
brew list watchman
/usr/local/Cellar/watchman/2021.10.04.00/bin/watchman
/usr/local/Cellar/watchman/2021.10.04.00/bin/watchman-diag
/usr/local/Cellar/watchman/2021.10.04.00/bin/watchman-make
/usr/local/Cellar/watchman/2021.10.04.00/bin/watchman-replicate-subscription
/usr/local/Cellar/watchman/2021.10.04.00/bin/watchman-wait
/usr/local/Cellar/watchman/2021.10.04.00/bin/watchmanctl
/usr/local/Cellar/watchman/2021.10.04.00/lib/python3.9/ (13 files)
うん。インストールはされている。
次のMacのシステム環境設定を変更する。
-
システム環境設定を起動し、「セキュリティとプライバシー」を選択。
-
左側のメニューから「フルディスクアクセス」を選択。
-
左下の鍵アイコンをクリックして、パスワードを入力。
-
右側のリストの「+」アイコンを押す。
-
右上の検索ウィンドウで、command + shift + .(ピリオド)を入力。←このオペレーションがわからず、すごい苦労した
-
先程のbrewの結果を確認し、watchmanを探す(私は/usr/local/Cellar/watchman/2021.10.04.00/binにあった)。
-
チェックが入っていることを確認して、左下のロックをクリック。
では再びnpm test
を実行。
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
解決ー!