codeceptjs 3.7.0-beta.1 → 3.7.0-beta.11

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 (73) hide show
  1. package/README.md +9 -10
  2. package/bin/codecept.js +7 -0
  3. package/lib/actor.js +46 -92
  4. package/lib/ai.js +130 -121
  5. package/lib/codecept.js +2 -2
  6. package/lib/command/check.js +186 -0
  7. package/lib/command/definitions.js +3 -1
  8. package/lib/command/interactive.js +1 -1
  9. package/lib/command/run-workers.js +2 -54
  10. package/lib/command/workers/runTests.js +64 -225
  11. package/lib/container.js +32 -0
  12. package/lib/effects.js +218 -0
  13. package/lib/els.js +87 -106
  14. package/lib/event.js +18 -17
  15. package/lib/heal.js +10 -0
  16. package/lib/helper/AI.js +2 -1
  17. package/lib/helper/Appium.js +31 -22
  18. package/lib/helper/Playwright.js +22 -1
  19. package/lib/helper/Puppeteer.js +5 -0
  20. package/lib/helper/WebDriver.js +29 -8
  21. package/lib/listener/emptyRun.js +2 -5
  22. package/lib/listener/exit.js +5 -8
  23. package/lib/listener/globalTimeout.js +66 -10
  24. package/lib/listener/result.js +12 -0
  25. package/lib/listener/steps.js +3 -6
  26. package/lib/listener/store.js +9 -1
  27. package/lib/mocha/asyncWrapper.js +15 -3
  28. package/lib/mocha/cli.js +79 -28
  29. package/lib/mocha/featureConfig.js +13 -0
  30. package/lib/mocha/hooks.js +32 -3
  31. package/lib/mocha/inject.js +5 -0
  32. package/lib/mocha/scenarioConfig.js +11 -0
  33. package/lib/mocha/suite.js +27 -1
  34. package/lib/mocha/test.js +102 -3
  35. package/lib/mocha/types.d.ts +11 -0
  36. package/lib/output.js +75 -73
  37. package/lib/pause.js +3 -10
  38. package/lib/plugin/analyze.js +349 -0
  39. package/lib/plugin/autoDelay.js +2 -2
  40. package/lib/plugin/commentStep.js +5 -0
  41. package/lib/plugin/customReporter.js +52 -0
  42. package/lib/plugin/heal.js +30 -0
  43. package/lib/plugin/pageInfo.js +140 -0
  44. package/lib/plugin/retryTo.js +18 -118
  45. package/lib/plugin/screenshotOnFail.js +12 -17
  46. package/lib/plugin/standardActingHelpers.js +4 -1
  47. package/lib/plugin/stepByStepReport.js +6 -5
  48. package/lib/plugin/stepTimeout.js +1 -1
  49. package/lib/plugin/tryTo.js +17 -107
  50. package/lib/recorder.js +5 -5
  51. package/lib/rerun.js +43 -42
  52. package/lib/result.js +161 -0
  53. package/lib/step/base.js +228 -0
  54. package/lib/step/config.js +50 -0
  55. package/lib/step/func.js +46 -0
  56. package/lib/step/helper.js +50 -0
  57. package/lib/step/meta.js +99 -0
  58. package/lib/step/record.js +74 -0
  59. package/lib/step/retry.js +11 -0
  60. package/lib/step/section.js +55 -0
  61. package/lib/step.js +20 -347
  62. package/lib/steps.js +50 -0
  63. package/lib/store.js +4 -0
  64. package/lib/timeout.js +66 -0
  65. package/lib/utils.js +93 -0
  66. package/lib/within.js +2 -2
  67. package/lib/workers.js +29 -49
  68. package/package.json +23 -20
  69. package/typings/index.d.ts +5 -4
  70. package/typings/promiseBasedTypes.d.ts +507 -49
  71. package/typings/types.d.ts +623 -73
  72. package/lib/listener/artifacts.js +0 -19
  73. package/lib/plugin/debugErrors.js +0 -67
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,10 @@ 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.file && outputLevel >= 1) print(colors.underline.grey(suite.file))
140
+ if (suite.comment) print(suite.comment)
139
141
  },
140
142
  },
141
143
 
@@ -145,25 +147,25 @@ module.exports = {
145
147
  * @param {Mocha.Test} test
146
148
  */
147
149
  started(test) {
148
- print(` ${colors.magenta.bold(test.title)}`);
150
+ print(` ${colors.magenta.bold(test.title)}`)
149
151
  },
150
152
  /**
151
153
  * @param {Mocha.Test} test
152
154
  */
153
155
  passed(test) {
154
- print(` ${colors.green.bold(figures.tick)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`);
156
+ print(` ${colors.green.bold(figures.tick)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`)
155
157
  },
156
158
  /**
157
159
  * @param {Mocha.Test} test
158
160
  */
159
161
  failed(test) {
160
- print(` ${colors.red.bold(figures.cross)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`);
162
+ print(` ${colors.red.bold(figures.cross)} ${test.title} ${colors.grey(`in ${test.duration}ms`)}`)
161
163
  },
162
164
  /**
163
165
  * @param {Mocha.Test} test
164
166
  */
165
167
  skipped(test) {
166
- print(` ${colors.yellow.bold('S')} ${test.title}`);
168
+ print(` ${colors.yellow.bold('S')} ${test.title}`)
167
169
  },
168
170
  },
169
171
 
@@ -174,38 +176,38 @@ module.exports = {
174
176
  */
175
177
 
176
178
  started(test) {
177
- if (outputLevel < 1) return;
178
- print(` ${colors.dim.bold('Scenario()')}`);
179
+ if (outputLevel < 1) return
180
+ print(` ${colors.dim.bold('Scenario()')}`)
179
181
  },
180
182
 
181
183
  /**
182
184
  * @param {Mocha.Test} test
183
185
  */
184
186
  passed(test) {
185
- print(` ${colors.green.bold(`${figures.tick} OK`)} ${colors.grey(`in ${test.duration}ms`)}`);
186
- print();
187
+ print(` ${colors.green.bold(`${figures.tick} OK`)} ${colors.grey(`in ${test.duration}ms`)}`)
188
+ print()
187
189
  },
188
190
  /**
189
191
  * @param {Mocha.Test} test
190
192
  */
191
193
  failed(test) {
192
- print(` ${colors.red.bold(`${figures.cross} FAILED`)} ${colors.grey(`in ${test.duration}ms`)}`);
193
- print();
194
+ print(` ${colors.red.bold(`${figures.cross} FAILED`)} ${colors.grey(`in ${test.duration}ms`)}`)
195
+ print()
194
196
  },
195
197
  },
196
198
 
197
199
  hook: {
198
200
  started(hook) {
199
- if (outputLevel < 1) return;
200
- print(` ${colors.dim.bold(hook.toCode())}`);
201
+ if (outputLevel < 1) return
202
+ print(` ${colors.dim.bold(hook.toCode())}`)
201
203
  },
202
204
  passed(hook) {
203
- if (outputLevel < 1) return;
204
- print();
205
+ if (outputLevel < 1) return
206
+ print()
205
207
  },
206
208
  failed(hook) {
207
- if (outputLevel < 1) return;
208
- print(` ${colors.red.bold(hook.toCode())}`);
209
+ if (outputLevel < 1) return
210
+ print(` ${colors.red.bold(hook.toCode())}`)
209
211
  },
210
212
  },
211
213
 
@@ -217,9 +219,9 @@ module.exports = {
217
219
  */
218
220
  say(message, color = 'cyan') {
219
221
  if (colors[color] === undefined) {
220
- color = 'cyan';
222
+ color = 'cyan'
221
223
  }
222
- if (outputLevel >= 1) print(` ${colors[color].bold(message)}`);
224
+ if (outputLevel >= 1) print(` ${colors[color].bold(message)}`)
223
225
  },
224
226
 
225
227
  /**
@@ -229,54 +231,54 @@ module.exports = {
229
231
  * @param {number|string} duration
230
232
  */
231
233
  result(passed, failed, skipped, duration, failedHooks = 0) {
232
- let style = colors.bgGreen;
233
- let msg = ` ${passed || 0} passed`;
234
- let status = style.bold(' OK ');
234
+ let style = colors.bgGreen
235
+ let msg = ` ${passed || 0} passed`
236
+ let status = style.bold(' OK ')
235
237
  if (failed) {
236
- style = style.bgRed;
237
- status = style.bold(' FAIL ');
238
- msg += `, ${failed} failed`;
238
+ style = style.bgRed
239
+ status = style.bold(' FAIL ')
240
+ msg += `, ${failed} failed`
239
241
  }
240
242
 
241
243
  if (failedHooks > 0) {
242
- style = style.bgRed;
243
- status = style.bold(' FAIL ');
244
- msg += `, ${failedHooks} failedHooks`;
244
+ style = style.bgRed
245
+ status = style.bold(' FAIL ')
246
+ msg += `, ${failedHooks} failedHooks`
245
247
  }
246
- status += style.grey(' |');
248
+ status += style.grey(' |')
247
249
 
248
250
  if (skipped) {
249
- if (!failed) style = style.bgYellow;
250
- msg += `, ${skipped} skipped`;
251
+ if (!failed) style = style.bgYellow
252
+ msg += `, ${skipped} skipped`
251
253
  }
252
- msg += ' ';
253
- print(status + style(msg) + colors.grey(` // ${duration}`));
254
+ msg += ' '
255
+ print(status + style(msg) + colors.grey(` // ${duration}`))
254
256
  },
255
- };
257
+ }
256
258
 
257
259
  function print(...msg) {
258
260
  if (outputProcess) {
259
- msg.unshift(outputProcess);
261
+ msg.unshift(outputProcess)
260
262
  }
261
263
  if (!newline) {
262
- console.log();
263
- newline = true;
264
+ console.log()
265
+ newline = true
264
266
  }
265
267
 
266
- console.log.apply(this, msg);
268
+ console.log.apply(this, msg)
267
269
  }
268
270
 
269
271
  function truncate(msg, gap = 0) {
270
272
  if (msg.indexOf('\n') > 0 || outputLevel >= 3) {
271
- return msg; // don't cut multi line steps or on verbose log level
273
+ return msg // don't cut multi line steps or on verbose log level
272
274
  }
273
- const width = (process.stdout.columns || 200) - gap - 4;
275
+ const width = (process.stdout.columns || 200) - gap - 4
274
276
  if (msg.length > width) {
275
- msg = msg.substr(0, width - 1) + figures.ellipsis;
277
+ msg = msg.substr(0, width - 1) + figures.ellipsis
276
278
  }
277
- return msg;
279
+ return msg
278
280
  }
279
281
 
280
282
  function isMaskedData() {
281
- return global.maskSensitiveData === true || false;
283
+ return global.maskSensitiveData === true || false
282
284
  }
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
@@ -85,12 +84,10 @@ function pauseSession(passedObject = {}) {
85
84
  })
86
85
  return new Promise(resolve => {
87
86
  finish = resolve
88
- // eslint-disable-next-line
89
87
  return askForStep()
90
88
  })
91
89
  }
92
90
 
93
- /* eslint-disable */
94
91
  async function parseInput(cmd) {
95
92
  rl.pause()
96
93
  next = false
@@ -199,7 +196,6 @@ async function parseInput(cmd) {
199
196
  recorder.add('ask for next step', askForStep)
200
197
  nextStep()
201
198
  }
202
- /* eslint-enable */
203
199
 
204
200
  function askForStep() {
205
201
  return new Promise(resolve => {
@@ -218,15 +214,12 @@ function completer(line) {
218
214
  return [completions, line]
219
215
  }
220
216
 
221
- // Initialize Fuse with completions
222
- const fuse = new Fuse(completions, {
217
+ // Search using Fuse.js
218
+ const searchResults = searchWithFusejs(completions, line, {
223
219
  threshold: 0.3,
224
220
  distance: 100,
225
221
  minMatchCharLength: 1,
226
222
  })
227
-
228
- // Search using Fuse.js
229
- const searchResults = fuse.search(line)
230
223
  const hits = searchResults.map(result => result.item)
231
224
 
232
225
  return [hits, line]