UGA Boxxx

つぶやきの延長のつもりで、知ったこと思ったこと書いてます

【Jest】テストは全てsuccessなのにexit statusが 1

JESTでテストを書いていて全てのテストが通るようになったのだが、最後npm run jestのexit statusが1で終了してしまう

Snapshot Summary
 › 1 snapshot file obsolete from 1 test suite. To remove it, run `npm run jest -- -u`.

Test Suites: 23 passed, 23 total
Tests:       50 passed, 50 total
Snapshots:   1 file obsolete, 0 total
Time:        10.776s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.0.0 jest: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.0.0 jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ugaboxxx/.npm/_logs/2020-07-22T03_09_44_486Z-debug.log

同様のIssueが上がっていて、まだOPENしているため未解決な事象かなと思ったのだが

github.com

上のコメントの中にobsoleteというのが原因なので消せばエラーが消えるというのがあったので

Snapshots: 3 obsolete, 26 passed, 26 total
obsolete - are the cause of the error, after their removal, the error is gone.

以下のコマンドで消してみたところエラーが解消された

$ npm run jest -- -u

-uはスナップショットテスト実行中に失敗した全てのスナップショットを再取得する場合に指定するオプション

覚えはないが過去にやったスナップショットテストの残りが悪さをしていたみたい