Skip to content

Commit

Permalink
feat(createtestfromscenario.js): add feature to hide pending scenario…
Browse files Browse the repository at this point in the history
…s from test run

This change allows you to control whether or not you want to hide pending scenarios. If you set the
env var to hide pending scenarios, then any scenario that should not be run will not get a mocha
test case. In other words, only tests that will actually be run will appear in the cypress test run.
  • Loading branch information
rbcasperson committed Nov 20, 2020
1 parent 021010d commit 37f52bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You can follow the documentation below, or if you prefer to hack on a working ex
* [Smart tagging](#smart-tagging)
* [How to run the tests](#excluding-tests)
* [Running tagged tests](#running-tagged-tests)
* [Hiding Pending Scenarios](#hiding-pending-scenarios)
* [Ignoring specific scenarios using tags when executing test runner](#ignoring-specific-scenarios-using-tags-when-executing-test-runner)
* [Output](#output)
* [IDE support](#ide-support)
Expand Down Expand Up @@ -385,6 +386,17 @@ The trick consists in adding the "env" property with the "TAGS" subproperty in t
Then, any scenarios tagged with @ignore will be skipped when running the tests using the cypress test runner
### Hiding Pending Scenarios
By default, every defined scenario will get a test that Cypress can run,
even if the tags determine that the test should be skipped or considered "pending".
If you would like to hide those scenarios from appearing in your test run,
set the `CYPRESS_HIDE_PENDING_SCENARIOS` environment variable:
```shell
CYPRESS_HIDE_PENDING_SCENARIOS=true ./node_modules/.bin/cypress run
```
### Limiting to a subset of feature files
You can use a glob expression to select which feature files should be included.
Expand Down
6 changes: 5 additions & 1 deletion lib/createTestFromScenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const stepTest = function (state, stepDetails, exampleRowData) {
.then(() => state.onFinishStep(stepDetails, statuses.PASSED));
};

const hidePendingScenarios = function () {
return !!Cypress.env("HIDE_PENDING_SCENARIOS");
};

const runTest = (scenario, stepsToRun, rowData) => {
const indexedSteps = stepsToRun.map((step, index) => ({ ...step, index }));

Expand All @@ -58,7 +62,7 @@ const runTest = (scenario, stepsToRun, rowData) => {
)
.then(() => state.onFinishScenario(scenario));
});
} else {
} else if (!hidePendingScenarios()) {
// eslint-disable-next-line func-names,prefer-arrow-callback
it(scenario.name, function () {
// register this scenario with the cucumber data collector
Expand Down

1 comment on commit 37f52bd

@modugu789
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its just awesome working as expected but can you help me push this change to pipeline since the file is under node modules

Please sign in to comment.