codeceptjs 3.7.0-beta.4 → 3.7.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +9 -10
  2. package/bin/codecept.js +7 -0
  3. package/lib/actor.js +47 -92
  4. package/lib/command/check.js +173 -0
  5. package/lib/command/definitions.js +2 -0
  6. package/lib/command/run-workers.js +1 -1
  7. package/lib/command/workers/runTests.js +112 -109
  8. package/lib/container.js +9 -0
  9. package/lib/effects.js +218 -0
  10. package/lib/heal.js +10 -0
  11. package/lib/helper/Appium.js +27 -16
  12. package/lib/helper/Playwright.js +15 -0
  13. package/lib/helper/Puppeteer.js +5 -0
  14. package/lib/helper/WebDriver.js +9 -1
  15. package/lib/listener/emptyRun.js +2 -5
  16. package/lib/listener/globalTimeout.js +15 -3
  17. package/lib/listener/steps.js +3 -0
  18. package/lib/mocha/cli.js +22 -5
  19. package/lib/mocha/featureConfig.js +13 -0
  20. package/lib/mocha/scenarioConfig.js +11 -0
  21. package/lib/mocha/test.js +15 -0
  22. package/lib/mocha/types.d.ts +6 -0
  23. package/lib/output.js +74 -73
  24. package/lib/pause.js +3 -7
  25. package/lib/plugin/heal.js +30 -0
  26. package/lib/plugin/retryTo.js +18 -126
  27. package/lib/plugin/stepTimeout.js +1 -1
  28. package/lib/plugin/tryTo.js +13 -111
  29. package/lib/recorder.js +1 -1
  30. package/lib/step/base.js +180 -0
  31. package/lib/step/config.js +50 -0
  32. package/lib/step/helper.js +47 -0
  33. package/lib/step/meta.js +91 -0
  34. package/lib/step/record.js +74 -0
  35. package/lib/step/retry.js +11 -0
  36. package/lib/step/timeout.js +42 -0
  37. package/lib/step.js +15 -348
  38. package/lib/steps.js +23 -0
  39. package/lib/store.js +2 -0
  40. package/lib/utils.js +58 -0
  41. package/lib/within.js +2 -2
  42. package/lib/workers.js +2 -12
  43. package/package.json +9 -7
  44. package/typings/index.d.ts +5 -4
  45. package/typings/promiseBasedTypes.d.ts +520 -6
  46. package/typings/types.d.ts +562 -44
  47. package/lib/step/section.js +0 -25
package/lib/output.js CHANGED
@@ -1,6 +1,6 @@
1
- const colors = require('chalk');
2
- const figures = require('figures');
3
- const { maskSensitiveData } = require('invisi-data');
1
+ const colors = require('chalk')
2
+ const figures = require('figures')
3
+ const { maskSensitiveData } = require('invisi-data')
4
4
 
5
5
  const styles = {
6
6
  error: colors.bgRed.white.bold,
@@ -10,11 +10,12 @@ const styles = {
10
10
  debug: colors.cyan,
11
11
  log: colors.grey,
12
12
  bold: colors.bold,
13
- };
13
+ section: colors.white.dim.bold,
14
+ }
14
15
 
15
- let outputLevel = 0;
16
- let outputProcess = '';
17
- let newline = true;
16
+ let outputLevel = 0
17
+ let outputProcess = ''
18
+ let newline = true
18
19
 
19
20
  /**
20
21
  * @alias output
@@ -28,7 +29,7 @@ module.exports = {
28
29
  stepShift: 0,
29
30
 
30
31
  standWithUkraine() {
31
- return `#${colors.bold.yellow('StandWith')}${colors.bold.cyan('Ukraine')}`;
32
+ return `#${colors.bold.yellow('StandWith')}${colors.bold.cyan('Ukraine')}`
32
33
  },
33
34
 
34
35
  /**
@@ -37,8 +38,8 @@ module.exports = {
37
38
  * @returns {number}
38
39
  */
39
40
  level(level) {
40
- if (level !== undefined) outputLevel = level;
41
- return outputLevel;
41
+ if (level !== undefined) outputLevel = level
42
+ return outputLevel
42
43
  },
43
44
 
44
45
  /**
@@ -48,9 +49,9 @@ module.exports = {
48
49
  * @returns {string}
49
50
  */
50
51
  process(process) {
51
- if (process === null) return (outputProcess = '');
52
- if (process) outputProcess = String(process).length === 1 ? `[0${process}]` : `[${process}]`;
53
- return outputProcess;
52
+ if (process === null) return (outputProcess = '')
53
+ if (process) outputProcess = String(process).length === 1 ? `[0${process}]` : `[${process}]`
54
+ return outputProcess
54
55
  },
55
56
 
56
57
  /**
@@ -58,9 +59,9 @@ module.exports = {
58
59
  * @param {string} msg
59
60
  */
60
61
  debug(msg) {
61
- const _msg = isMaskedData() ? maskSensitiveData(msg) : msg;
62
+ const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
62
63
  if (outputLevel >= 2) {
63
- print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`));
64
+ print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`))
64
65
  }
65
66
  },
66
67
 
@@ -69,9 +70,9 @@ module.exports = {
69
70
  * @param {string} msg
70
71
  */
71
72
  log(msg) {
72
- const _msg = isMaskedData() ? maskSensitiveData(msg) : msg;
73
+ const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
73
74
  if (outputLevel >= 3) {
74
- print(' '.repeat(this.stepShift), styles.log(truncate(` ${_msg}`, this.spaceShift)));
75
+ print(' '.repeat(this.stepShift), styles.log(truncate(` ${_msg}`, this.spaceShift)))
75
76
  }
76
77
  },
77
78
 
@@ -80,7 +81,7 @@ module.exports = {
80
81
  * @param {string} msg
81
82
  */
82
83
  error(msg) {
83
- print(styles.error(msg));
84
+ print(styles.error(msg))
84
85
  },
85
86
 
86
87
  /**
@@ -88,7 +89,7 @@ module.exports = {
88
89
  * @param {string} msg
89
90
  */
90
91
  success(msg) {
91
- print(styles.success(msg));
92
+ print(styles.success(msg))
92
93
  },
93
94
 
94
95
  /**
@@ -97,7 +98,7 @@ module.exports = {
97
98
  * @param {string} msg
98
99
  */
99
100
  plugin(pluginName, msg = '') {
100
- this.debug(`<${pluginName}> ${msg}`);
101
+ this.debug(`<${pluginName}> ${msg}`)
101
102
  },
102
103
 
103
104
  /**
@@ -105,26 +106,26 @@ module.exports = {
105
106
  * @param {CodeceptJS.Step} step
106
107
  */
107
108
  step(step) {
108
- if (outputLevel === 0) return;
109
- if (!step) return;
109
+ if (outputLevel === 0) return
110
+ if (!step) return
110
111
  // Avoid to print non-gherkin steps, when gherkin is running for --steps mode
111
112
  if (outputLevel === 1) {
112
113
  if (typeof step === 'object' && step.hasBDDAncestor()) {
113
- return;
114
+ return
114
115
  }
115
116
  }
116
117
 
117
- let stepLine = step.toCliStyled();
118
+ let stepLine = step.toCliStyled()
118
119
  if (step.metaStep && outputLevel >= 1) {
119
120
  // this.stepShift += 2;
120
- stepLine = colors.dim(truncate(stepLine, this.spaceShift));
121
+ stepLine = colors.dim(truncate(stepLine, this.spaceShift))
121
122
  }
122
123
  if (step.comment) {
123
- stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)));
124
+ stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)))
124
125
  }
125
126
 
126
- const _stepLine = isMaskedData() ? maskSensitiveData(stepLine) : stepLine;
127
- print(' '.repeat(this.stepShift), truncate(_stepLine, this.spaceShift));
127
+ const _stepLine = isMaskedData() ? maskSensitiveData(stepLine) : stepLine
128
+ print(' '.repeat(this.stepShift), truncate(_stepLine, this.spaceShift))
128
129
  },
129
130
 
130
131
  /** @namespace */
@@ -133,9 +134,9 @@ module.exports = {
133
134
  * @param {Mocha.Suite} suite
134
135
  */
135
136
  started: suite => {
136
- if (!suite.title) return;
137
- print(`${colors.bold(suite.title)} --`);
138
- if (suite.comment) print(suite.comment);
137
+ if (!suite.title) return
138
+ print(`${colors.bold(suite.title)} --`)
139
+ if (suite.comment) print(suite.comment)
139
140
  },
140
141
  },
141
142
 
@@ -145,25 +146,25 @@ module.exports = {
145
146
  * @param {Mocha.Test} test
146
147
  */
147
148
  started(test) {
148
- print(` ${colors.magenta.bold(test.title)}`);
149
+ print(` ${colors.magenta.bold(test.title)}`)
149
150
  },
150
151
  /**
151
152
  * @param {Mocha.Test} test
152
153
  */
153
154
  passed(test) {
154
- print(` ${colors.green.bold(figures.tick)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`);
155
+ print(` ${colors.green.bold(figures.tick)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`)
155
156
  },
156
157
  /**
157
158
  * @param {Mocha.Test} test
158
159
  */
159
160
  failed(test) {
160
- print(` ${colors.red.bold(figures.cross)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`);
161
+ print(` ${colors.red.bold(figures.cross)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`)
161
162
  },
162
163
  /**
163
164
  * @param {Mocha.Test} test
164
165
  */
165
166
  skipped(test) {
166
- print(` ${colors.yellow.bold('S')} ${test.title}`);
167
+ print(` ${colors.yellow.bold('S')} ${test.title}`)
167
168
  },
168
169
  },
169
170
 
@@ -174,38 +175,38 @@ module.exports = {
174
175
  */
175
176
 
176
177
  started(test) {
177
- if (outputLevel < 1) return;
178
- print(` ${colors.dim.bold('Scenario()')}`);
178
+ if (outputLevel < 1) return
179
+ print(` ${colors.dim.bold('Scenario()')}`)
179
180
  },
180
181
 
181
182
  /**
182
183
  * @param {Mocha.Test} test
183
184
  */
184
185
  passed(test) {
185
- print(` ${colors.green.bold(`${figures.tick} OK`)} ${colors.grey(`in ${test.duration}ms`)}`);
186
- print();
186
+ print(` ${colors.green.bold(`${figures.tick} OK`)} ${colors.grey(`in ${test.duration}ms`)}`)
187
+ print()
187
188
  },
188
189
  /**
189
190
  * @param {Mocha.Test} test
190
191
  */
191
192
  failed(test) {
192
- print(` ${colors.red.bold(`${figures.cross} FAILED`)} ${colors.grey(`in ${test.duration}ms`)}`);
193
- print();
193
+ print(` ${colors.red.bold(`${figures.cross} FAILED`)} ${colors.grey(`in ${test.duration}ms`)}`)
194
+ print()
194
195
  },
195
196
  },
196
197
 
197
198
  hook: {
198
199
  started(hook) {
199
- if (outputLevel < 1) return;
200
- print(` ${colors.dim.bold(hook.toCode())}`);
200
+ if (outputLevel < 1) return
201
+ print(` ${colors.dim.bold(hook.toCode())}`)
201
202
  },
202
203
  passed(hook) {
203
- if (outputLevel < 1) return;
204
- print();
204
+ if (outputLevel < 1) return
205
+ print()
205
206
  },
206
207
  failed(hook) {
207
- if (outputLevel < 1) return;
208
- print(` ${colors.red.bold(hook.toCode())}`);
208
+ if (outputLevel < 1) return
209
+ print(` ${colors.red.bold(hook.toCode())}`)
209
210
  },
210
211
  },
211
212
 
@@ -217,9 +218,9 @@ module.exports = {
217
218
  */
218
219
  say(message, color = 'cyan') {
219
220
  if (colors[color] === undefined) {
220
- color = 'cyan';
221
+ color = 'cyan'
221
222
  }
222
- if (outputLevel >= 1) print(` ${colors[color].bold(message)}`);
223
+ if (outputLevel >= 1) print(` ${colors[color].bold(message)}`)
223
224
  },
224
225
 
225
226
  /**
@@ -229,54 +230,54 @@ module.exports = {
229
230
  * @param {number|string} duration
230
231
  */
231
232
  result(passed, failed, skipped, duration, failedHooks = 0) {
232
- let style = colors.bgGreen;
233
- let msg = ` ${passed || 0} passed`;
234
- let status = style.bold(' OK ');
233
+ let style = colors.bgGreen
234
+ let msg = ` ${passed || 0} passed`
235
+ let status = style.bold(' OK ')
235
236
  if (failed) {
236
- style = style.bgRed;
237
- status = style.bold(' FAIL ');
238
- msg += `, ${failed} failed`;
237
+ style = style.bgRed
238
+ status = style.bold(' FAIL ')
239
+ msg += `, ${failed} failed`
239
240
  }
240
241
 
241
242
  if (failedHooks > 0) {
242
- style = style.bgRed;
243
- status = style.bold(' FAIL ');
244
- msg += `, ${failedHooks} failedHooks`;
243
+ style = style.bgRed
244
+ status = style.bold(' FAIL ')
245
+ msg += `, ${failedHooks} failedHooks`
245
246
  }
246
- status += style.grey(' |');
247
+ status += style.grey(' |')
247
248
 
248
249
  if (skipped) {
249
- if (!failed) style = style.bgYellow;
250
- msg += `, ${skipped} skipped`;
250
+ if (!failed) style = style.bgYellow
251
+ msg += `, ${skipped} skipped`
251
252
  }
252
- msg += ' ';
253
- print(status + style(msg) + colors.grey(` // ${duration}`));
253
+ msg += ' '
254
+ print(status + style(msg) + colors.grey(` // ${duration}`))
254
255
  },
255
- };
256
+ }
256
257
 
257
258
  function print(...msg) {
258
259
  if (outputProcess) {
259
- msg.unshift(outputProcess);
260
+ msg.unshift(outputProcess)
260
261
  }
261
262
  if (!newline) {
262
- console.log();
263
- newline = true;
263
+ console.log()
264
+ newline = true
264
265
  }
265
266
 
266
- console.log.apply(this, msg);
267
+ console.log.apply(this, msg)
267
268
  }
268
269
 
269
270
  function truncate(msg, gap = 0) {
270
271
  if (msg.indexOf('\n') > 0 || outputLevel >= 3) {
271
- return msg; // don't cut multi line steps or on verbose log level
272
+ return msg // don't cut multi line steps or on verbose log level
272
273
  }
273
- const width = (process.stdout.columns || 200) - gap - 4;
274
+ const width = (process.stdout.columns || 200) - gap - 4
274
275
  if (msg.length > width) {
275
- msg = msg.substr(0, width - 1) + figures.ellipsis;
276
+ msg = msg.substr(0, width - 1) + figures.ellipsis
276
277
  }
277
- return msg;
278
+ return msg
278
279
  }
279
280
 
280
281
  function isMaskedData() {
281
- return global.maskSensitiveData === true || false;
282
+ return global.maskSensitiveData === true || false
282
283
  }
package/lib/pause.js CHANGED
@@ -2,7 +2,6 @@ const colors = require('chalk')
2
2
  const readline = require('readline')
3
3
  const ora = require('ora-classic')
4
4
  const debug = require('debug')('codeceptjs:pause')
5
- const Fuse = require('fuse.js')
6
5
 
7
6
  const container = require('./container')
8
7
  const history = require('./history')
@@ -11,7 +10,7 @@ const aiAssistant = require('./ai')
11
10
  const recorder = require('./recorder')
12
11
  const event = require('./event')
13
12
  const output = require('./output')
14
- const { methodsOfObject } = require('./utils')
13
+ const { methodsOfObject, searchWithFusejs } = require('./utils')
15
14
 
16
15
  // npm install colors
17
16
  let rl
@@ -218,15 +217,12 @@ function completer(line) {
218
217
  return [completions, line]
219
218
  }
220
219
 
221
- // Initialize Fuse with completions
222
- const fuse = new Fuse(completions, {
220
+ // Search using Fuse.js
221
+ const searchResults = searchWithFusejs(completions, line, {
223
222
  threshold: 0.3,
224
223
  distance: 100,
225
224
  minMatchCharLength: 1,
226
225
  })
227
-
228
- // Search using Fuse.js
229
- const searchResults = fuse.search(line)
230
226
  const hits = searchResults.map(result => result.item)
231
227
 
232
228
  return [hits, line]
@@ -5,6 +5,7 @@ const event = require('../event')
5
5
  const output = require('../output')
6
6
  const heal = require('../heal')
7
7
  const store = require('../store')
8
+ const container = require('../container')
8
9
 
9
10
  const defaultConfig = {
10
11
  healLimit: 2,
@@ -115,4 +116,33 @@ module.exports = function (config = {}) {
115
116
  i++
116
117
  }
117
118
  })
119
+
120
+ event.dispatcher.on(event.workers.result, ({ tests }) => {
121
+ const { print } = output
122
+
123
+ const healedTests = Object.values(tests)
124
+ .flat()
125
+ .filter(test => test.notes.some(note => note.type === 'heal'))
126
+ if (!healedTests.length) return
127
+
128
+ setTimeout(() => {
129
+ print('')
130
+ print('===================')
131
+ print(colors.bold.green('Self-Healing Report:'))
132
+
133
+ print('')
134
+ print('Suggested changes:')
135
+ print('')
136
+
137
+ healedTests.forEach(test => {
138
+ print(`${colors.bold.magenta(test.title)}`)
139
+ test.notes
140
+ .filter(note => note.type === 'heal')
141
+ .forEach(note => {
142
+ print(note.text)
143
+ print('')
144
+ })
145
+ })
146
+ }, 0)
147
+ })
118
148
  }
@@ -1,127 +1,19 @@
1
- const recorder = require('../recorder')
2
- const { debug } = require('../output')
3
-
4
- const defaultConfig = {
5
- registerGlobal: true,
6
- pollInterval: 200,
7
- }
8
-
9
- /**
10
- *
11
- *
12
- * Adds global `retryTo` which retries steps a few times before failing.
13
- *
14
- * Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
15
- *
16
- * ```js
17
- * plugins: {
18
- * retryTo: {
19
- * enabled: true
20
- * }
21
- * }
22
- * ```
23
- *
24
- * Use it in your tests:
25
- *
26
- * ```js
27
- * // retry these steps 5 times before failing
28
- * await retryTo((tryNum) => {
29
- * I.switchTo('#editor frame');
30
- * I.click('Open');
31
- * I.see('Opened')
32
- * }, 5);
33
- * ```
34
- * Set polling interval as 3rd argument (200ms by default):
35
- *
36
- * ```js
37
- * // retry these steps 5 times before failing
38
- * await retryTo((tryNum) => {
39
- * I.switchTo('#editor frame');
40
- * I.click('Open');
41
- * I.see('Opened')
42
- * }, 5, 100);
43
- * ```
44
- *
45
- * Default polling interval can be changed in a config:
46
- *
47
- * ```js
48
- * plugins: {
49
- * retryTo: {
50
- * enabled: true,
51
- * pollInterval: 500,
52
- * }
53
- * }
54
- * ```
55
- *
56
- * Disables retryFailedStep plugin for steps inside a block;
57
- *
58
- * Use this plugin if:
59
- *
60
- * * you need repeat a set of actions in flaky tests
61
- * * iframe was not rendered and you need to retry switching to it
62
- *
63
- *
64
- * #### Configuration
65
- *
66
- * * `pollInterval` - default interval between retries in ms. 200 by default.
67
- * * `registerGlobal` - to register `retryTo` function globally, true by default
68
- *
69
- * If `registerGlobal` is false you can use retryTo from the plugin:
70
- *
71
- * ```js
72
- * const retryTo = codeceptjs.container.plugins('retryTo');
73
- * ```
74
- *
75
- */
76
- module.exports = function (config) {
77
- config = Object.assign(defaultConfig, config)
78
- function retryTo(callback, maxTries, pollInterval = config.pollInterval) {
79
- return new Promise((done, reject) => {
80
- let tries = 1
81
-
82
- function handleRetryException(err) {
83
- recorder.throw(err)
84
- reject(err)
85
- }
86
-
87
- const tryBlock = async () => {
88
- tries++
89
- recorder.session.start(`retryTo ${tries}`)
90
- try {
91
- await callback(tries)
92
- } catch (err) {
93
- handleRetryException(err)
94
- }
95
-
96
- // Call done if no errors
97
- recorder.add(() => {
98
- recorder.session.restore(`retryTo ${tries}`)
99
- done(null)
100
- })
101
-
102
- // Catch errors and retry
103
- recorder.session.catch(err => {
104
- recorder.session.restore(`retryTo ${tries}`)
105
- if (tries <= maxTries) {
106
- debug(`Error ${err}... Retrying`)
107
- recorder.add(`retryTo ${tries}`, () => setTimeout(tryBlock, pollInterval))
108
- } else {
109
- // if maxTries reached
110
- handleRetryException(err)
111
- }
112
- })
113
- }
114
-
115
- recorder.add('retryTo', tryBlock).catch(err => {
116
- console.error('An error occurred:', err)
117
- done(null)
118
- })
119
- })
120
- }
121
-
122
- if (config.registerGlobal) {
123
- global.retryTo = retryTo
124
- }
125
-
126
- return retryTo
1
+ module.exports = function () {
2
+ console.log(`
3
+ Deprecated Warning: 'retryTo' has been moved to the effects module.
4
+ You should update your tests to use it as follows:
5
+
6
+ \`\`\`javascript
7
+ const { retryTo } = require('codeceptjs/effects');
8
+
9
+ // Example: Retry these steps 5 times before failing
10
+ await retryTo((tryNum) => {
11
+ I.switchTo('#editor frame');
12
+ I.click('Open');
13
+ I.see('Opened');
14
+ }, 5);
15
+ \`\`\`
16
+
17
+ For more details, refer to the documentation.
18
+ `)
127
19
  }
@@ -1,5 +1,5 @@
1
1
  const event = require('../event')
2
- const TIMEOUT_ORDER = require('../step').TIMEOUT_ORDER
2
+ const { TIMEOUT_ORDER } = require('../step/timeout')
3
3
 
4
4
  const defaultConfig = {
5
5
  timeout: 150,
@@ -1,115 +1,17 @@
1
- const recorder = require('../recorder')
2
- const { debug } = require('../output')
1
+ module.exports = function () {
2
+ console.log(`
3
+ Deprecated Warning: 'tryTo' has been moved to the effects module.
4
+ You should update your tests to use it as follows:
3
5
 
4
- const defaultConfig = {
5
- registerGlobal: true,
6
- }
7
-
8
- /**
9
- *
10
- *
11
- * Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
12
- *
13
- * Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
14
- *
15
- * ```js
16
- * plugins: {
17
- * tryTo: {
18
- * enabled: true
19
- * }
20
- * }
21
- * ```
22
- * Use it in your tests:
23
- *
24
- * ```js
25
- * const result = await tryTo(() => I.see('Welcome'));
26
- *
27
- * // if text "Welcome" is on page, result => true
28
- * // if text "Welcome" is not on page, result => false
29
- * ```
30
- *
31
- * Disables retryFailedStep plugin for steps inside a block;
32
- *
33
- * Use this plugin if:
34
- *
35
- * * you need to perform multiple assertions inside a test
36
- * * there is A/B testing on a website you test
37
- * * there is "Accept Cookie" banner which may surprisingly appear on a page.
38
- *
39
- * #### Usage
40
- *
41
- * #### Multiple Conditional Assertions
42
- *
43
- * ```js
44
- *
45
- * Add assert requires first:
46
- * ```js
47
- * const assert = require('assert');
48
- * ```
49
- * Then use the assertion:
50
- * const result1 = await tryTo(() => I.see('Hello, user'));
51
- * const result2 = await tryTo(() => I.seeElement('.welcome'));
52
- * assert.ok(result1 && result2, 'Assertions were not succesful');
53
- * ```
54
- *
55
- * ##### Optional click
56
- *
57
- * ```js
58
- * I.amOnPage('/');
59
- * tryTo(() => I.click('Agree', '.cookies'));
60
- * ```
61
- *
62
- * #### Configuration
63
- *
64
- * * `registerGlobal` - to register `tryTo` function globally, true by default
65
- *
66
- * If `registerGlobal` is false you can use tryTo from the plugin:
67
- *
68
- * ```js
69
- * const tryTo = codeceptjs.container.plugins('tryTo');
70
- * ```
71
- *
72
- */
73
- module.exports = function (config) {
74
- config = Object.assign(defaultConfig, config)
6
+ \`\`\`javascript
7
+ const { tryTo } = require('codeceptjs/effects');
75
8
 
76
- if (config.registerGlobal) {
77
- global.tryTo = tryTo
78
- }
79
- return tryTo
80
- }
9
+ // Example: failed step won't fail a test but will return true/false
10
+ await tryTo(() => {
11
+ I.switchTo('#editor frame');
12
+ });
13
+ \`\`\`
81
14
 
82
- function tryTo(callback) {
83
- let result = false
84
- return recorder.add(
85
- 'tryTo',
86
- () => {
87
- recorder.session.start('tryTo')
88
- process.env.TRY_TO = 'true'
89
- callback()
90
- recorder.add(() => {
91
- result = true
92
- recorder.session.restore('tryTo')
93
- return result
94
- })
95
- recorder.session.catch(err => {
96
- result = false
97
- const msg = err.inspect ? err.inspect() : err.toString()
98
- debug(`Unsuccessful try > ${msg}`)
99
- recorder.session.restore('tryTo')
100
- return result
101
- })
102
- return recorder.add(
103
- 'result',
104
- () => {
105
- process.env.TRY_TO = undefined
106
- return result
107
- },
108
- true,
109
- false,
110
- )
111
- },
112
- false,
113
- false,
114
- )
15
+ For more details, refer to the documentation.
16
+ `)
115
17
  }
package/lib/recorder.js CHANGED
@@ -179,7 +179,7 @@ module.exports = {
179
179
  }
180
180
  if (retry === undefined) retry = true
181
181
  if (!running && !force) {
182
- return
182
+ return Promise.resolve()
183
183
  }
184
184
  tasks.push(taskName)
185
185
  debug(chalk.gray(`${currentQueue()} Queued | ${taskName}`))