infosum / cypress-tags

Use custom tags to slice up Cypress test runs
83 stars 20 forks source link

Feature request: mark skipped nodes as pending #238

Open GrayedFox opened 1 year ago

GrayedFox commented 1 year ago

Thanks for the awesome plugin :)

If I understand correctly, this line replaces test nodes that are not part of the bundled/tagged tests to be run with a semicolon, effectively skipping those tests:

https://github.com/infosum/cypress-tags/blob/master/src/index.ts#L232-L237

Would you consider adding a flag that, instead of replacing said nodes with a semicolon, replaces them with a call to the equivalent pending Mocha method? Something like:

if (skipNode && !markAsPending) {
  // Replaces node with semi-colon, effectively skipping node and any children
  returnNode = factory.createOmittedExpression();
}

if (skipNode && markAsPending) {
  // Replaces node with equivalent, pending Mocha method (if it isn't already xdescribe, xcontext, or xit)
  returnNode = convertToPending(nodeExpression);
} else {
  returnNode = ts.visitEachChild(returnNode, (node) => visit(node, tags), context);
}

The convert to pending method would just need to make sure it isn't prepending an extra x to methods already named xdescribe, and instead only mark tests that aren't included in the run to their equivalent pending version, i.e.

describe(() => {}) /** >> **/ xdescribe(() => {})

context(() => {})  /** >> **/  xcontext(() => {})

it(() => {})       /** >> **/       xit(() => {})

Could maybe pass in something like CYPRESS_EXCLUDE_AS_PENDING=true or something similar 👍🏾