https://cypress.io logo
Changing status/result of a spec through plugin
# i-need-help
h
Is there a way of changing spec result from a plugin? we're working on a test quarantine plugin to skips tests that meet certain critereas
b
hmmm, @gray-kilobyte-89541 any solutions for a fellow plugin creator here? 😀
g
Well, I use https://github.com/bahmutov/cypress-expect if I expect failing tests, but in general, no, you should not be changing test results
h
Thanks
b
@hundreds-library-57018 if you're looking to skip tests based on a dynamic criteria, https://github.com/cypress-io/cypress/blob/develop/npm/grep/src/support.js might be some good inspiration on how to do that
h
That's what I'm planning @bland-salesclerk-62828 . We're building a 'system' to quarantine tests that are too flaky or being flaky for too long.
e
I build this small, custom, command for feature flagging a few years ago to skip tests conditionally based on the state of a feature flag. You could probably reuse this and add it in a before/beforeEach and refactor it so it works with whatever flake quarantining you are doing.
Copy code
/**
 * Action that skips tests based on a given flag
 * @param {Boolean} enabled represents a conditional, typically the value of a feature flag
 */
Cypress.Commands.add('onlyOn', (enabled) => {
  if (enabled !== true) {
    cy.state('runnable').ctx.skip();
  }
});
Copy code
beforeEach(() => {
  // All tests will only run if some criteria is equivalent to true
  cy.onlyOn(someCriteria)
})
4 Views