急にjest --watch
ができなくなったので、調べてみた。
現象
❯ yarn test:watch
yarn run v1.22.10
$ cross-env NODE_ENV=test jest --config=jest.config.json --watch
2021-03-23 20:35 node[59503] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2021-03-23 20:35 node[59503] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2021-03-23 20:35 node[59503] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:292
throw er; // Unhandled 'error' event
^
Error: EMFILE: too many open files, watch
at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:178:28)
Emitted 'error' event on FSWatcher instance at:
at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:184:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
環境
ProductName: Mac OS X
ProductVersion: 10.13.6
BuildVersion: 17G14033
❯ node -v
v14.15.4
❯ yarn -v
1.22.10
❯ yarn jest --version
v20.0.4
最初はwatchmanはない。
yarnだとwatchmonがあるので間違いに注意。
❯ which watchman
watchman not found
❯ brew install watchman
長い更新時間
❯ which watchman
/usr/local/bin/watchman
実行結果
❯ yarn test:watch
yarn run v1.22.10
$ cross-env NODE_ENV=test jest --config=jest.config.json --watch
PASS src/tests/components/Header.test.js
PASS src/tests/components/ExpenseDashboardPage.test.js
PASS src/tests/components/AddExpensePage.test.js
PASS src/tests/actions/expenses.test.js
PASS src/tests/components/EditExpensePage.test.js
PASS src/tests/components/ConfModal.test.js
PASS src/tests/components/LoginPage.test.js
PASS src/tests/actions/auth.test.js
Test Suites: 8 passed, 8 total
Tests: 25 passed, 25 total
Snapshots: 6 passed, 6 total
Time: 7.874s, estimated 8s
Ran all test suites related to changed files.
✨ Done in 240.85s.
確かに実行できるようになった。
参考
JestのwatchがError watching file for changes: EMFILE でコケるときの対処
macOS Sierra #1767でウォッチモードが機能しなくなりました