一旦测试失败,是否有可靠的方法让赛普拉斯退出?

我们有一个在 CI 服务器上运行的大型测试套件,如果测试失败,似乎无法告诉 Cypress 退出。它始终运行整个套件。

有一些讨论,在这里,但没有可行的解决方案。

一旦测试失败,是否有可靠的方法让赛普拉斯退出?


哔哔one
浏览 238回答 2
2回答

LEATH

您也可以使用这个 Cypress 插件,同时 Cypress 本身不支持此功能:https : //www.npmjs.com/package/cypress-fail-fast将插件添加到 devDependencies:npm i --save-dev cypress-fail-fast在 cypress/plugins/index.js 里面:module.exports = (on, config) => {  require("cypress-fail-fast/plugin")(on, config);  return config;};在 cypress/support/index.js 的顶部:import "cypress-fail-fast";

RISEBY

正如您所提到的,它还没有得到官方支持(从 3.6.0 开始)。这是我对 hack 的看法(不使用 cookie 等来保持状态):// cypress/plugins/index.jslet shouldSkip = false;module.exports = ( on ) => {  on('task', {    resetShouldSkipFlag () {      shouldSkip = false;      return null;    },    shouldSkip ( value ) {      if ( value != null ) shouldSkip = value;      return shouldSkip;    }  });}// cypress/support/index.jsfunction abortEarly () {  if ( this.currentTest.state === 'failed' ) {    return cy.task('shouldSkip', true);  }  cy.task('shouldSkip').then( value => {    if ( value ) this.skip();  });}beforeEach(abortEarly);afterEach(abortEarly);before(() => {  if ( Cypress.browser.isHeaded ) {    // Reset the shouldSkip flag at the start of a run, so that it     //  doesn't carry over into subsequent runs.    // Do this only for headed runs because in headless runs,    //  the `before` hook is executed for each spec file.    cy.task('resetShouldSkipFlag');  }});一旦遇到故障,将跳过所有进一步的测试。输出将如下所示:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript