LoginSignup
2
1

More than 1 year has passed since last update.

Mac+React+Jestで、watchmanが動かない場合の対応

Posted at

はじめに

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のシステム環境設定を変更する。

  • システム環境設定を起動し、「セキュリティとプライバシー」を選択。
  • 左側のメニューから「フルディスクアクセス」を選択。
  • 左下の鍵アイコンをクリックして、パスワードを入力。
  • 右側のリストの「+」アイコンを押す。
  • ダイヤログが開く。
    スクリーンショット 2021-11-25 10.37.13.png

  • 右上の検索ウィンドウで、command + shift + .(ピリオド)を入力。←このオペレーションがわからず、すごい苦労した

  • 先程のbrewの結果を確認し、watchmanを探す(私は/usr/local/Cellar/watchman/2021.10.04.00/binにあった)。

  • 「開く」を押して選択
    スクリーンショット 2021-11-25 10.40.04.png

  • チェックが入っていることを確認して、左下のロックをクリック。

では再び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.

解決ー!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1