報錯:
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was
not invoked within the 5000ms timeout specified by jest.setTimeout.
at mapper (node_modules/_jest-jasmine2@24.9.0@jest-jasmine2/build/queueRunner.js:25:45)
描述:
運行測試組件是提示超時,即使skip的組件也超時,甚至運行成功的組件也超時;其他測試用例不超時,只有這個超時
解決過程:
- 看了提示的的API 沒有頭緒
- 懷疑這句導致了問題,但是其他地方也用了,沒有類似超時報錯: const erpText = await page.$$eval(css5, eles=>eles.map(ele=>ele.textContent.replace(/\s+/g,"")))
- 查看了配置文件,取消了 puppeteer.launch() 中的 timeout 參數無果
- 運行其他腳本,正常執行
- 對比兩個腳本,發現 beforeAll() 模塊異常,有區別,比正常的腳本多了2行代碼;而執行時間,沒有設定,默認 5000s, 增加到10000之后,問題解決
總結
原則:緊緊的扣住報錯內容,從報錯內容中找線索。
報錯內容,提示超時,那肯定是哪里超時了;接下來就是超時的地方;腳本中,各個組件都設置了時間 (35000),一般足夠用了,不會發生集體超時(排除了網絡問題),所以只能是
beforeAll() 這種地方了。