Skip to content

Commit 6a33ec8

Browse files
committed
Replace diagnostics with a more proper dry-run
This is "more proper" in the sense that it's still executing tests an actual Cypress environments, while still being reasonably quick. This is related to #1120 [1]. This closes #1129 [2]. [1] #1120 [2] #1129
1 parent c226178 commit 6a33ec8

40 files changed

+1381
-1200
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Breaking changes:
1010

1111
- User of `@badeball/cypress-cucumber-preprocessor/browserify` should change their Cypress config in accordance with the related [examples](examples).
1212

13-
- The executable `cypress-cucumber-diagnostics` no longer respect flags such as `--project` or `--env`. The long-term plan is to rewamp dry run altogether, and run it in a Cypress environment.
13+
- The executable `cypress-cucumber-diagnostics` has been replaced by a [`dryRun` option](docs/dry-run.md).
1414

15-
- `esbuild` is now an optional peer dependency. This is relevant for users using `esbuild` as their bundler, as well as users of `cypress-cucumber-diagnostics`.
15+
- `esbuild` is now an optional peer dependency. This is relevant for users using `esbuild` as their bundler.
1616

1717
Other changees:
1818

augmentations.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import messages from "@cucumber/messages";
22

33
import { Registry } from "./lib/registry";
44

5+
import { MochaGlobals } from "mocha";
6+
57
declare module "@cucumber/cucumber" {
68
interface IWorld {
79
tmpDir: string;
@@ -25,6 +27,10 @@ declare global {
2527
var __cypress_cucumber_preprocessor_registry_dont_use_this:
2628
| Registry
2729
| undefined;
30+
31+
var __cypress_cucumber_preprocessor_mocha_dont_use_this:
32+
| Pick<MochaGlobals, "before" | "beforeEach" | "after" | "afterEach">
33+
| undefined;
2834
}
2935

3036
interface Window {

docs/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ Every configuration option has a similar key which can be use to override it, sh
8080
| `json.output` | `jsonOutput` | `cucumber-report.json` |
8181
| `html.enabled` | `htmlEnabled` | `true`, `false` |
8282
| `html.output` | `htmlOutput` | `cucumber-report.html` |
83+
| `usage.enabled` | `usageEnabled` | `true`, `false` |
84+
| `usage.output` | `usageOutput` | `stdout` |
8385
| `pretty.enabled` | `prettyEnabled` | `true`, `false` |
8486
| `filterSpecsMixedMode` | `filterSpecsMixedMode` | `hide`, `show`, `empty-set` |
8587
| `filterSpecs` | `filterSpecs` | `true`, `false` |
8688
| `omitFiltered` | `omitFiltered` | `true`, `false` |
89+
| `dryRun` | `dryRun` | `true`, `false` |
8790

8891
## Test configuration
8992

docs/diagnostics.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

docs/dry-run.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[← Back to documentation](readme.md)
2+
3+
# Dry run
4+
5+
Dry run is a run mode in which no steps or any type of hooks are executed. A few examples where this is useful:
6+
7+
- Finding unused step definitions with [usage reports](usage-report.md)
8+
- Generating snippets for all undefined steps
9+
- Checking if your path, tag expression, etc. matches the scenarios you expect it to
10+
11+
Dry run can be enabled using `dryRun`, like seen below.
12+
13+
```
14+
$ cypress run --env dryRun=true
15+
```

docs/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
* [Step definitions](step-definitions.md)
88
* [Tags](tags.md)
99
* [Pretty output](pretty-output.md)
10+
* [Source maps](source-maps.md)
11+
* [Dry run](dry-run.md)
1012
* Reports
1113
* [Messages report](messages-report.md)
1214
* [JSON report](json-report.md)
1315
* [HTML report](html-report.md)
16+
* [Usage report](usage-report.md)
1417
* [Localisation](localisation.md)
1518
* [Configuration](configuration.md)
1619
* [Test configuration](test-configuration.md)
1720
* CLI utilities
18-
* [Diagnostics / dry run](diagnostics.md)
1921
* [JSON formatter](json-formatter.md)
2022
* [HTML formatter](html-formatter.md)
2123
* [Parallelization using Cypress Cloud & merging reports](merging-reports.md)

docs/source-maps.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[← Back to documentation](readme.md)
2+
3+
# Source maps
4+
5+
How to enable source maps for each bundler is shown below.
6+
7+
## esbuild
8+
9+
```js
10+
const { defineConfig } = require("cypress");
11+
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
12+
const {
13+
addCucumberPreprocessorPlugin,
14+
} = require("@badeball/cypress-cucumber-preprocessor");
15+
const {
16+
createEsbuildPlugin,
17+
} = require("@badeball/cypress-cucumber-preprocessor/esbuild");
18+
19+
async function setupNodeEvents(on, config) {
20+
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
21+
await addCucumberPreprocessorPlugin(on, config);
22+
23+
on(
24+
"file:preprocessor",
25+
createBundler({
26+
plugins: [createEsbuildPlugin(config)],
27+
sourcemap: "inline"
28+
})
29+
);
30+
31+
// Make sure to return the config object as it might have been modified by the plugin.
32+
return config;
33+
}
34+
35+
module.exports = defineConfig({
36+
e2e: {
37+
baseUrl: "https://duckduckgo.com",
38+
specPattern: "**/*.feature",
39+
setupNodeEvents,
40+
},
41+
});
42+
```
43+
44+
## Webpack
45+
46+
Source maps are enabled by default.
47+
48+
## Browserify
49+
50+
Source maps are enabled by default.

docs/usage-report.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[← Back to documentation](readme.md)
2+
3+
# Usage reports
4+
5+
> :warning: This requires you to have [source maps](source-maps.md) enabled.
6+
7+
The usage report lists your step definitions and tells you about usages in your scenarios, including the duration of each usage, and any unused steps. Here's an example of the output:
8+
9+
```
10+
┌───────────────────────────────────────┬──────────┬─────────────────────────────────┐
11+
│ Pattern / Text │ Duration │ Location │
12+
├───────────────────────────────────────┼──────────┼─────────────────────────────────┤
13+
│ an empty todo list │ 760.33ms │ support/steps/steps.ts:6 │
14+
│ an empty todo list │ 820ms │ features/empty.feature:4 │
15+
│ an empty todo list │ 761ms │ features/adding-todos.feature:4 │
16+
│ an empty todo list │ 700ms │ features/empty.feature:4 │
17+
├───────────────────────────────────────┼──────────┼─────────────────────────────────┤
18+
│ I add the todo {string} │ 432.00ms │ support/steps/steps.ts:10 │
19+
│ I add the todo "buy some cheese" │ 432ms │ features/adding-todos.feature:5 │
20+
├───────────────────────────────────────┼──────────┼─────────────────────────────────┤
21+
│ my cursor is ready to create a todo │ 53.00ms │ support/steps/steps.ts:27 │
22+
│ my cursor is ready to create a todo │ 101ms │ features/empty.feature:10 │
23+
│ my cursor is ready to create a todo │ 5ms │ features/adding-todos.feature:8 │
24+
├───────────────────────────────────────┼──────────┼─────────────────────────────────┤
25+
│ no todos are listed │ 46.00ms │ support/steps/steps.ts:15 │
26+
│ no todos are listed │ 46ms │ features/empty.feature:7 │
27+
├───────────────────────────────────────┼──────────┼─────────────────────────────────┤
28+
│ the todos are: │ 31.00ms │ support/steps/steps.ts:21 │
29+
│ the todos are: │ 31ms │ features/adding-todos.feature:6 │
30+
├───────────────────────────────────────┼──────────┼─────────────────────────────────┤
31+
│ I remove the todo {string} │ UNUSED │ support/steps/steps.ts:33 │
32+
└───────────────────────────────────────┴──────────┴─────────────────────────────────┘
33+
```
34+
35+
Usage reports can be enabled using the `usage.enabled` property. The preprocessor uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig), which means you can place configuration options in EG. `.cypress-cucumber-preprocessorrc.json` or `package.json`. An example configuration is shown below.
36+
37+
```json
38+
{
39+
"usage": {
40+
"enabled": true
41+
}
42+
}
43+
```
44+
45+
The report is outputted to stdout (your console) by default, but can be configured to be written to a file through the `usage.output` property.

0 commit comments

Comments
 (0)