如何让CodeceptJS在所有测试结束后正常退出进程?
CodeceptJS测试失败后进程无法自动终止的问题
我遇到了和某GitHub Issue里相同的问题,但其中给出的mocha: {bail: true}配置对我无效。
CodeceptJS会运行所有测试并输出成功/失败的最终结果,但进程无法自动终止:当最后一个测试失败时,必须手动关闭进程;若所有测试通过,进程可正常退出。这种情况无法在CI脚本中使用,因为服务器需要自动终止进程。
我尝试使用afterSuite钩子,但它仅对单个测试套件生效,而我的测试用例来自不同文件。
我的配置代码如下:
require('ts-node/register'); require('puppeteer'); require('dotenv').config({ path: '.env' }); exports.config = { // define the `after` hook to run after all tests have completed plugins: { tryTo: { enabled: true }, allure: { enabled: true, outputDir: './allure-results' }, stepByStepReport: { enabled: true, output: './allure-results' }, }, tests: './tests/*/*.test.ts', globals: './globals.ts', helpers: { Puppeteer: { url: '', browser: 'chrome', chrome: { args: [ '--window-size=1920,1080', '--no-sandbox', '--no-zygote ', '--disable-zero-browsers-open-for-tests', '--ignore-certificate-errors', '--ignore-certificate-errors-spki-list', '--disable-setuid-sandbox', ], defaultViewport: null, ignoreHTTPSErrors: true, }, waitForAction: 1000, waitForTimeout: 30000, fullPageScreenShots: true, show: false, restart: true, windowSize: '1920x1080', keepCookies: true, waitForNavigation: ['networkidle2', 'domcontentloaded', 'load'] }, REST: { endpoint: process.env.EMS_DOMAIN, defaultHeaders: { 'Accept': 'application/json', }, timeout: 20000 } }, bootstrap: null, mocha: {}, rerun: { minSuccess:2, maxReruns: 2, }, name: 'autotests-ems-js' };
运行命令:yarn codeceptjs run
内容的提问来源于stack exchange,提问作者Alena Sapronova
相关产品推荐
相关产品推荐

