【发布时间】:2023-03-13 05:00:01
【问题描述】:
由于未知原因,我的 Jest 测试似乎在我的 CI 结束时通过 Travis 阻塞。
Travis 日志如下:
测试套件:5 个通过,总共 5 个
测试:31 次通过,总共 31 次
快照:共 0 个
时间:21.993sJest 在测试运行完成后一秒没有退出。
这通常意味着在您的测试中存在未停止的异步操作。考虑使用
--detectOpenHandles运行 Jest 来解决此问题。
请注意,--detectOpenHandles 不显示任何内容。
您可以看到我的测试通过但没有退出,即使我执行了以下操作:
describe('[INTEGRATION] Index.test.js', () => {
beforeAll(async () => {
const rootDir = resolve(__dirname, '../..');
let config = {};
// ... config
nuxt = new Nuxt(config);
new Builder(nuxt).build();
await nuxt.listen(3000, 'localhost');
homePage = await nuxt.renderAndGetWindow('http://localhost:3000/');
}, 30000);
// This is called after every suite (even during the CI process)
afterAll(() => {
nuxt.close();
});
// ... my tests
});
我的测试在本地运行良好,但仅在 CI 过程中通过 Travis 进行。
这是我的 Jest 配置文件的内容:
module.exports = {
verbose: true,
moduleFileExtensions: ['js', 'vue', 'json'],
transform: {
'^.+\\.js$': 'babel-jest',
'.*\\.(vue)$': 'jest-vue-preprocessor',
},
setupTestFrameworkScriptFile: './jest.setup.js',
silent: true,
};
jest.setup.js 包含 jest.setTimeout(30000);。
最后,这是我的.travis.yml 配置文件:
language: 'node_js'
node_js: '8'
cache:
directories:
- 'node_modules'
before_script:
- npm run build
- npm run lint
- npm install
- npm run generate
什么可能导致这个问题?超时不应该是它,因为它是执行我的所有集成测试所必需的,我在集成测试套件之后关闭了我的nuxtsession。
从昨天开始工作到今天,没有发生重大变化。
【问题讨论】: