Skip to content

Commit f5175cb

Browse files
authored
[WIP] Dry-run mode (#1825)
* dry-run basic implementation * added tests and docs for dry-run * added bootstrap option * added --bootstrap to dry-run docs
1 parent cf9ec0a commit f5175cb

File tree

10 files changed

+444
-39
lines changed

10 files changed

+444
-39
lines changed

bin/codecept.js

+16
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ program.command('run-multiple [suites...]')
143143

144144
.action(require('../lib/command/run-multiple'));
145145

146+
program.command('dry-run [test]')
147+
.description('Executes tests multiple')
148+
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
149+
.option('--bootstrap', 'enable bootstrap script for dry-run')
150+
.option('-c, --config [file]', 'configuration file to be used')
151+
.option('--all', 'run all suites')
152+
.option('--features', 'run only *.feature files and skip tests')
153+
.option('--tests', 'run only JS test files and skip features')
154+
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
155+
.option('-f, --fgrep <string>', 'only run tests containing <string>')
156+
.option('-i, --invert', 'inverts --grep and --fgrep matches')
157+
.option('--steps', 'show step-by-step execution')
158+
.option('--verbose', 'output internal logging information')
159+
.option('--debug', 'output additional information')
160+
.action(require('../lib/command/dryRun'));
161+
146162
program.on('command:*', (cmd) => {
147163
console.log(`\nUnknown command ${cmd}\n`);
148164
program.outputHelp();

docs/commands.md

+51-25
Original file line numberDiff line numberDiff line change
@@ -13,152 +13,178 @@ Executes tests. Requires `codecept.conf.js` config to be present in provided pat
1313
Run all tests from current dir
1414

1515
```sh
16-
codeceptjs run
16+
npx codeceptjs run
1717
```
1818

1919
Load config and run tests from `test` dir
2020

2121
```sh
22-
codeceptjs run -c test
22+
npx codeceptjs run -c test
2323
```
2424

2525
Run only tests with "signin" word in name
2626

2727
```sh
28-
codeceptjs run --grep "signin"
28+
npx codeceptjs run --grep "signin"
2929
```
3030

3131
Run all tests without "@IEOnly" word in name
3232

3333
```sh
34-
codeceptjs run --grep "@IEOnly" --invert
34+
npx codeceptjs run --grep "@IEOnly" --invert
3535
```
3636

3737
Run single test [path to codecept.js] [test filename]
3838

3939
```sh
40-
codeceptjs run github_test.js
40+
npx codeceptjs run github_test.js
4141
```
4242

4343
Run single test with steps printed
4444

4545
```sh
46-
codeceptjs run github_test.js --steps
46+
npx codeceptjs run github_test.js --steps
4747
```
4848

4949
Run single test in debug mode
5050

5151
```sh
52-
codeceptjs run github_test.js --debug
52+
npx codeceptjs run github_test.js --debug
5353
```
5454

5555
Run test with internal logs printed (global promises, and events).
5656

5757
```sh
58-
codeceptjs run github_test.js --verbose
58+
npx codeceptjs run github_test.js --verbose
5959
```
6060

6161
Select config file manually (`-c` or `--config` option)
6262

6363
```sh
64-
codeceptjs run -c my.codecept.conf.js
65-
codeceptjs run --config path/to/codecept.json
64+
npx codeceptjs run -c my.codecept.conf.js
65+
npx codeceptjs run --config path/to/codecept.json
6666
```
6767

6868
Override config on the fly. Provide valid JSON which will be merged into current config:
6969

7070
```sh
71-
codeceptjs run --override '{ "helpers": {"WebDriver": {"browser": "chrome"}}}'
71+
npx codeceptjs run --override '{ "helpers": {"WebDriver": {"browser": "chrome"}}}'
7272
```
7373

7474
Run tests and produce xunit report:
7575

7676
```sh
77-
codeceptjs run --reporter xunit
77+
npx codeceptjs run --reporter xunit
7878
```
7979

8080
Use any of [Mocha reporters](https://github.com/mochajs/mocha/tree/master/lib/reporters) used.
8181

82+
## Dry Run
83+
84+
Prints test scenarios without executing them
85+
86+
```
87+
npx codeceptjs dry-run
88+
```
89+
90+
When passed `--steps` or `--debug` option runs tests, disabling all plugins and helpers, so you can get step-by-step report with no tests actually executed.
91+
92+
```
93+
npx codeceptjs dry-run --steps
94+
```
95+
96+
If a plugin needs to be enabled in `dry-run` mode, pass its name in `-p` option:
97+
98+
```
99+
npx codeceptjs dry-run --steps -p allure
100+
```
101+
102+
To enable bootstrap script in dry-run mode, pass in `--bootstrap` option when running with `--steps` or `--debug`
103+
104+
```
105+
nox codeceptjs dry-run --steps --bootstrap
106+
```
107+
82108
## Run multiple
83109

84110
Run multiple suites.
85111

86112
```sh
87-
codeceptjs run-multiple smoke:chrome regression:firefox
113+
npx codeceptjs run-multiple smoke:chrome regression:firefox
88114
```
89115

90116
## Init
91117

92118
Creates `codecept.conf.js` file in current directory:
93119

94120
```sh
95-
codeceptjs init
121+
npx codeceptjs init
96122
```
97123

98124
Or in provided path
99125

100126
```sh
101-
codecept init test
127+
npx codecept init test
102128
```
103129

104130
## Migrate
105131

106132
Migrate your current `codecept.json` to `codecept.conf.js`
107133

108134
```sh
109-
codeceptjs migrate
135+
npx codeceptjs migrate
110136
```
111137

112138
## Shell
113139

114140
Interactive shell. Allows to try `I.` commands in runtime
115141

116142
```sh
117-
codeceptjs shell
143+
npx codeceptjs shell
118144
```
119145

120146
## Generators
121147

122148
Create new test
123149

124150
```sh
125-
codeceptjs generate:test
151+
npx codeceptjs generate:test
126152
```
127153

128154
Create new pageobject
129155

130156
```sh
131-
codeceptjs generate:pageobject
157+
npx codeceptjs generate:pageobject
132158
```
133159

134160
Create new helper
135161

136162
```sh
137-
codeceptjs generate:helper
163+
npx codeceptjs generate:helper
138164
```
139165

140166
## TypeScript Definitions
141167

142168
TypeScript Definitions allows IDEs to provide autocompletion when writing tests.
143169

144170
```sh
145-
codeceptjs def
146-
codeceptjs def --config path/to/codecept.json
171+
npx codeceptjs def
172+
npx codeceptjs def --config path/to/codecept.json
147173
```
148174

149175
After doing that IDE should provide autocompletion for `I` object inside `Scenario` and `within` blocks.
150176

151177
Add optional parameter `output` (or shortcat `-o`), if you want to place your definition file in specific folder:
152178

153179
```sh
154-
codeceptjs def --output ./tests/typings
155-
codeceptjs def -o ./tests/typings
180+
npx codeceptjs def --output ./tests/typings
181+
npx codeceptjs def -o ./tests/typings
156182
```
157183

158184
## List Commands
159185

160186
Prints all available methods of `I` to console
161187

162188
```sh
163-
codeceptjs list
189+
npx codeceptjs list
164190
```

docs/reports.md

+68-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ title: Reporters
55

66
## Cli
77

8-
(default)
9-
108
By default CodeceptJS provides cli reporter with console output.
119
Test names and failures will be printed to screen.
1210

@@ -31,9 +29,15 @@ GitHub --
3129

3230

3331
Run with --verbose flag to see NodeJS stacktrace
32+
33+
```
34+
npx codeceptjs run --stepsutput add `--steps` option to `run` command:
35+
```
36+
```
37+
npx codeceptjs run --steps
3438
```
3539
36-
For dynamic step-by-step output add `--steps` option to `run` command:
40+
Output:
3741
3842
```sh
3943
GitHub --
@@ -65,10 +69,22 @@ GitHub --
6569
✖ FAILED in 1260ms
6670
```
6771

68-
To get additional information about test execution use `--debug` option. This will show execution steps
72+
To get additional information about test execution use `--debug` option.
73+
74+
75+
```
76+
npx codeceptjs run --debug
77+
```
78+
79+
80+
This will show execution steps
6981
as well as notices from test runner. To get even more information with more technical details like error stack traces,
7082
and global promises, or events use `--verbose` mode.
7183

84+
```
85+
npx codeceptjs run --verbose
86+
```
87+
7288
```sh
7389
GitHub --
7490
register
@@ -86,19 +102,54 @@ GitHub --
86102

87103
Please use verbose output when reporting issues to GitHub.
88104

105+
### Dry Run
89106

90-
## Allure
107+
There is a way to list all tests and their steps without actually executing them. Execute tests in `dry-run` mode to see all available tests:
91108

92-
(recommended)
109+
```
110+
npx codeceptjs dry-run
111+
```
93112

113+
Output:
114+
115+
```
116+
Tests from /home/davert/projects/codeceptjs/examples:
117+
118+
Business rules --
119+
☐ do something
120+
Google --
121+
☐ test @123
122+
GitHub -- /home/davert/projects/codeceptjs/examples/github_test.js
123+
☐ Visit Home Page @retry
124+
☐ search @grop
125+
☐ signin @normal @important @slow
126+
☐ signin2
127+
☐ register
128+
129+
Total: 3 suites | 7 tests
130+
131+
--- DRY MODE: No tests were executed ---
132+
```
133+
134+
Pass `--steps` or `--debug` option as in `run` command to also get steps and substeps to be printed. In this mode **tests will be executed** but all helpers and plugins disabled, so no real actions will be performed.
135+
136+
```
137+
npx codecepjs dry-run --debug
138+
```
139+
140+
> ℹ If you use custom JavaScript code inside tests, or rely on values from `grab*` commands, dry-run may produce error output.
141+
142+
## Allure
143+
144+
> ℹ We recommend using Allure reports on CI. Allure is one of the best open-source reporters designed to collect and show test reports in nicest way.
94145
95146
[Allure reporter](http://allure.qatools.ru/#) is a tool to store and display test reports.
96147
It provides nice web UI which contains all important information on test execution.
97148
CodeceptJS has built-in support for Allure reports. Inside reports you will have all steps, substeps and screenshots.
98149

99150
![](https://user-images.githubusercontent.com/220264/45676511-8e052800-bb3a-11e8-8cbb-db5f73de2add.png)
100151

101-
*Disclaimer: Allure is a standalone tool. Please refer to [Allure documentation](https://docs.qameta.io/allure/) to learn more about using Allure reports.*
152+
> Allure is a standalone tool. Please refer to [Allure documentation](https://docs.qameta.io/allure/) to learn more about using Allure reports.
102153
103154
Allure requires **Java 8** to work. Then Allure can be installed via NPM:
104155

@@ -109,16 +160,16 @@ npm install -g allure-commandline --save-dev
109160
Add [Allure plugin](https://codecept.io/plugins/#allure) in config under `plugins` section.
110161

111162
```js
112-
"plugins": {
113-
"allure": {
114-
}
163+
plugins: {
164+
allure: {
165+
}
115166
}
116167
```
117168

118169
Run tests with allure plugin enabled:
119170

120171
```
121-
codeceptjs run --plugins allure
172+
npx codeceptjs run --plugins allure
122173
```
123174

124175
(optionally) To enable allure plugin permanently include `"enabled": true` into plugin config:
@@ -140,6 +191,11 @@ allure serve output
140191

141192
Allure reporter aggregates data from other plugins like [*stepByStepReport*](https://codecept.io/plugins/#stepByStepReport) and [*screenshotOnFail*](https://codecept.io/plugins/#screenshotOnFail)
142193

194+
Allure reports can also be generated for `dry-run` command. So you can get the first report with no tests actually being executed. Enable allure plugin in dry-run options, and pass `--debug` option to print all tests on screen.
195+
196+
```
197+
npx codeceptjs dry-run --debug -p allure
198+
```
143199

144200
## XML
145201

@@ -301,7 +357,7 @@ Configure mocha-multi with reports that you want:
301357
Execute CodeceptJS with mocha-multi reporter:
302358

303359
```sh
304-
codeceptjs run --reporter mocha-multi
360+
npx codeceptjs run --reporter mocha-multi
305361
```
306362

307363
This will give you cli with steps in console and HTML report in `output` directory.

0 commit comments

Comments
 (0)