[英]jest mockgoose - jest did not exit one second after the test run has completed
[英]How can I solve the Jest message “Jest did not exit one second after the test run has completed.”?
我們使用frisby.js
進行自動API測試, frisby.js
使用Jest
作為測試運行器。 現在在我們的例子中,我們在執行所有API測試之前進行全局設置,並且在測試執行之后我們進行全局拆解。
我在jest.conf.js
設置了這個全局設置和拆解:
globalSetup: './jest.globalSetup.js',
globalTeardown: './jest.globalTeardown.js',
因此,全局拆解會導出一個異步函數,該函數在所有測試套件之后觸發一次。 在我們的全球拆解中,我們使用外部報告引擎生成測試覆蓋率和測試報告:
const coverage = require('./test-coverage-generator');
const XunitViewerCli = require('xunit-viewer/cli');
module.exports = async function() {
await coverage.generateTestCoverage();
await XunitViewerCli({
results: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.xml',
ignore: [],
output: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.html',
title: 'Test Report API Tests for ' + process.env.API_TEST_FOLDER,
port: false,
watch: false,
color: true,
filter: {}
});
}
報告生成是Jest
生成消息的原因, Jest
Jest did not exit one second after the test run has completed.
在測試結束時,因為報告生成需要一秒鍾以上。
所以,我不想再看到這個消息,因為這個消息很混亂。 也許可以在全局范圍內增加默認的Jest超時一秒,還是有其他可能的解決方案來阻止此消息?
我遇到類似的問題,解決方案是從globalTeardown
模塊導出的函數返回一個promise。 這樣的事情可以解決這個問題:
module.exports = async function() {
await coverage.generateTestCoverage();
// returns a promise
return XunitViewerCli({
results: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.xml',
ignore: [],
output: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.html',
title: 'Test Report API Tests for ' + process.env.API_TEST_FOLDER,
port: false,
watch: false,
color: true,
filter: {}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.