codeceptjs 3.7.0-beta.15 → 3.7.0-beta.16

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.
package/bin/codecept.js CHANGED
@@ -62,7 +62,7 @@ program
62
62
  .command('check')
63
63
  .option(commandFlags.config.flag, commandFlags.config.description)
64
64
  .description('Checks configuration and environment before running tests')
65
- .option('-t, --timeout [ms]', 'timeout for checks in ms, 20000 by default')
65
+ .option('-t, --timeout [ms]', 'timeout for checks in ms, 50000 by default')
66
66
  .action(errorHandler(require('../lib/command/check')))
67
67
 
68
68
  program
@@ -87,9 +87,9 @@ module.exports = async function (options) {
87
87
 
88
88
  if (config?.ai?.request) {
89
89
  checks.ai = true
90
- printCheck('ai', checks['ai'], 'AI configuration is enabled, request function is set')
90
+ printCheck('ai', checks['ai'], 'Configuration is enabled, request function is set')
91
91
  } else {
92
- printCheck('ai', checks['ai'], 'AI is disabled')
92
+ printCheck('ai', checks['ai'], 'Disabled')
93
93
  }
94
94
 
95
95
  printCheck('tests', checks['tests'], `Total: ${numTests} tests`)
package/lib/effects.js CHANGED
@@ -2,6 +2,7 @@ const recorder = require('./recorder')
2
2
  const { debug } = require('./output')
3
3
  const store = require('./store')
4
4
  const event = require('./event')
5
+ const within = require('./within')
5
6
 
6
7
  /**
7
8
  * A utility function for CodeceptJS tests that acts as a soft assertion.
@@ -178,11 +179,14 @@ async function tryTo(callback) {
178
179
  const sessionName = 'tryTo'
179
180
 
180
181
  let result = false
182
+ let hasAutoRetriesEnabled = store.autoRetries
181
183
  return recorder.add(
182
184
  sessionName,
183
185
  () => {
184
186
  recorder.session.start(sessionName)
185
- store.tryTo = true
187
+ hasAutoRetriesEnabled = store.autoRetries
188
+ if (hasAutoRetriesEnabled) debug('Auto retries disabled inside tryTo effect')
189
+ store.autoRetries = false
186
190
  callback()
187
191
  recorder.add(() => {
188
192
  result = true
@@ -199,7 +203,7 @@ async function tryTo(callback) {
199
203
  return recorder.add(
200
204
  'result',
201
205
  () => {
202
- store.tryTo = undefined
206
+ store.autoRetries = hasAutoRetriesEnabled
203
207
  return result
204
208
  },
205
209
  true,
@@ -215,4 +219,5 @@ module.exports = {
215
219
  hopeThat,
216
220
  retryTo,
217
221
  tryTo,
222
+ within,
218
223
  }
@@ -484,7 +484,7 @@ class Playwright extends Helper {
484
484
  this.currentRunningTest = test
485
485
 
486
486
  recorder.retry({
487
- retries: process.env.FAILED_STEP_RETRIES || 3,
487
+ retries: test.opts?.conditionalRetries || 3,
488
488
  when: err => {
489
489
  if (!err || typeof err.message !== 'string') {
490
490
  return false
@@ -312,7 +312,7 @@ class Puppeteer extends Helper {
312
312
  this.sessionPages = {}
313
313
  this.currentRunningTest = test
314
314
  recorder.retry({
315
- retries: process.env.FAILED_STEP_RETRIES || 3,
315
+ retries: test.opts?.conditionalRetries || 3,
316
316
  when: err => {
317
317
  if (!err || typeof err.message !== 'string') {
318
318
  return false
@@ -1,8 +1,6 @@
1
1
  const event = require('../event')
2
2
  const recorder = require('../recorder')
3
- const container = require('../container')
4
- const { log } = require('../output')
5
-
3
+ const store = require('../store')
6
4
  const defaultConfig = {
7
5
  retries: 3,
8
6
  defaultIgnoredSteps: ['amOnPage', 'wait*', 'send*', 'execute*', 'run*', 'have*'],
@@ -70,9 +68,9 @@ const defaultConfig = {
70
68
  * Use scenario configuration to disable plugin for a test
71
69
  *
72
70
  * ```js
73
- * Scenario('scenario tite', () => {
71
+ * Scenario('scenario tite', { disableRetryFailedStep: true }, () => {
74
72
  * // test goes here
75
- * }).config(test => test.disableRetryFailedStep = true)
73
+ * })
76
74
  * ```
77
75
  *
78
76
  */
@@ -85,19 +83,14 @@ module.exports = config => {
85
83
 
86
84
  const when = err => {
87
85
  if (!enableRetry) return
88
- const store = require('../store')
89
86
  if (store.debugMode) return false
87
+ if (!store.autoRetries) return false
90
88
  if (customWhen) return customWhen(err)
91
89
  return true
92
90
  }
93
91
  config.when = when
94
92
 
95
93
  event.dispatcher.on(event.step.started, step => {
96
- if (process.env.TRY_TO === 'true') {
97
- log('Info: RetryFailedStep plugin is disabled inside tryTo block')
98
- return
99
- }
100
-
101
94
  // if a step is ignored - return
102
95
  for (const ignored of config.ignoredSteps) {
103
96
  if (step.name === ignored) return
@@ -113,9 +106,15 @@ module.exports = config => {
113
106
  })
114
107
 
115
108
  event.dispatcher.on(event.test.before, test => {
116
- if (test && test.disableRetryFailedStep) return // disable retry when a test is not active
117
- // this env var is used to set the retries inside _before() block of helpers
118
- process.env.FAILED_STEP_RETRIES = config.retries
109
+ // pass disableRetryFailedStep is a preferred way to disable retries
110
+ // test.disableRetryFailedStep is used for backward compatibility
111
+ if (test.opts.disableRetryFailedStep || test.disableRetryFailedStep) {
112
+ store.autoRetries = false
113
+ return // disable retry when a test is not active
114
+ }
115
+ // this option is used to set the retries inside _before() block of helpers
116
+ store.autoRetries = true
117
+ test.opts.conditionalRetries = config.retries
119
118
  recorder.retry(config)
120
119
  })
121
120
  }
package/lib/recorder.js CHANGED
@@ -192,6 +192,7 @@ module.exports = {
192
192
  .pop()
193
193
  // no retries or unnamed tasks
194
194
  debug(`${currentQueue()} Running | ${taskName} | Timeout: ${timeout || 'None'}`)
195
+ if (retryOpts) debug(`${currentQueue()} Retry opts`, JSON.stringify(retryOpts))
195
196
 
196
197
  if (!retryOpts || !taskName || !retry) {
197
198
  const [promise, timer] = getTimeoutPromise(timeout, taskName)
package/lib/store.js CHANGED
@@ -3,17 +3,41 @@
3
3
  * @namespace
4
4
  */
5
5
  const store = {
6
- /** @type {boolean} */
6
+ /**
7
+ * If we are in --debug mode
8
+ * @type {boolean}
9
+ */
7
10
  debugMode: false,
8
- /** @type {boolean} */
11
+
12
+ /**
13
+ * Is timeouts enabled
14
+ * @type {boolean}
15
+ */
9
16
  timeouts: true,
10
- /** @type {boolean} */
17
+
18
+ /**
19
+ * If auto-retries are enabled by retryFailedStep plugin
20
+ * tryTo effect disables them
21
+ * @type {boolean}
22
+ */
23
+ autoRetries: false,
24
+
25
+ /**
26
+ * Tests are executed via dry-run
27
+ * @type {boolean}
28
+ */
11
29
  dryRun: false,
12
- /** @type {boolean} */
30
+ /**
31
+ * If we are in pause mode
32
+ * @type {boolean}
33
+ */
13
34
  onPause: false,
35
+
36
+ // current object states
37
+
14
38
  /** @type {CodeceptJS.Test | null} */
15
39
  currentTest: null,
16
- /** @type {any} */
40
+ /** @type {CodeceptJS.Step | null} */
17
41
  currentStep: null,
18
42
  /** @type {CodeceptJS.Suite | null} */
19
43
  currentSuite: null,
package/lib/within.js CHANGED
@@ -7,6 +7,8 @@ const MetaStep = require('./step/meta')
7
7
  const { isAsyncFunction } = require('./utils')
8
8
 
9
9
  /**
10
+ * TODO: move to effects
11
+ *
10
12
  * @param {CodeceptJS.LocatorOrString} context
11
13
  * @param {Function} fn
12
14
  * @return {Promise<*> | undefined}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.7.0-beta.15",
3
+ "version": "3.7.0-beta.16",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -1759,6 +1759,9 @@ declare namespace CodeceptJS {
1759
1759
  * @property [host = "0.0.0.0"] - Mock server host
1760
1760
  * @property [httpsOpts] - key & cert values are the paths to .key and .crt files
1761
1761
  */
1762
+ // @ts-ignore
1763
+ // @ts-ignore
1764
+ // @ts-ignore
1762
1765
  type MockServerConfig = {
1763
1766
  port?: number;
1764
1767
  host?: string;
@@ -1883,6 +1886,9 @@ declare namespace CodeceptJS {
1883
1886
  *
1884
1887
  * ## Methods
1885
1888
  */
1889
+ // @ts-ignore
1890
+ // @ts-ignore
1891
+ // @ts-ignore
1886
1892
  class MockServer {
1887
1893
  /**
1888
1894
  * Start the mock server
@@ -2916,6 +2922,9 @@ declare namespace CodeceptJS {
2916
2922
  * @property [recordHar] - record HAR and will be saved to `output/har`. See more of [HAR options](https://playwright.dev/docs/api/class-browser#browser-new-context-option-record-har).
2917
2923
  * @property [testIdAttribute = data-testid] - locate elements based on the testIdAttribute. See more of [locate by test id](https://playwright.dev/docs/locators#locate-by-test-id).
2918
2924
  */
2925
+ // @ts-ignore
2926
+ // @ts-ignore
2927
+ // @ts-ignore
2919
2928
  type PlaywrightConfig = {
2920
2929
  url?: string;
2921
2930
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -6292,6 +6301,9 @@ declare namespace CodeceptJS {
6292
6301
  * @property [chrome] - pass additional [Puppeteer run options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).
6293
6302
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6294
6303
  */
6304
+ // @ts-ignore
6305
+ // @ts-ignore
6306
+ // @ts-ignore
6295
6307
  type PuppeteerConfig = {
6296
6308
  url: string;
6297
6309
  basicAuth?: any;
@@ -8098,6 +8110,9 @@ declare namespace CodeceptJS {
8098
8110
  * @property [onResponse] - an async function which can update response object.
8099
8111
  * @property [maxUploadFileSize] - set the max content file size in MB when performing api calls.
8100
8112
  */
8113
+ // @ts-ignore
8114
+ // @ts-ignore
8115
+ // @ts-ignore
8101
8116
  type RESTConfig = {
8102
8117
  endpoint?: string;
8103
8118
  prettyPrintJson?: boolean;
@@ -9242,6 +9257,9 @@ declare namespace CodeceptJS {
9242
9257
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
9243
9258
  * @property [logLevel = silent] - level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: https://webdriver.io/docs/configuration/#loglevel
9244
9259
  */
9260
+ // @ts-ignore
9261
+ // @ts-ignore
9262
+ // @ts-ignore
9245
9263
  type WebDriverConfig = {
9246
9264
  url: string;
9247
9265
  browser: string;
@@ -1786,6 +1786,9 @@ declare namespace CodeceptJS {
1786
1786
  * @property [host = "0.0.0.0"] - Mock server host
1787
1787
  * @property [httpsOpts] - key & cert values are the paths to .key and .crt files
1788
1788
  */
1789
+ // @ts-ignore
1790
+ // @ts-ignore
1791
+ // @ts-ignore
1789
1792
  type MockServerConfig = {
1790
1793
  port?: number;
1791
1794
  host?: string;
@@ -1910,6 +1913,9 @@ declare namespace CodeceptJS {
1910
1913
  *
1911
1914
  * ## Methods
1912
1915
  */
1916
+ // @ts-ignore
1917
+ // @ts-ignore
1918
+ // @ts-ignore
1913
1919
  class MockServer {
1914
1920
  /**
1915
1921
  * Start the mock server
@@ -3009,6 +3015,9 @@ declare namespace CodeceptJS {
3009
3015
  * @property [recordHar] - record HAR and will be saved to `output/har`. See more of [HAR options](https://playwright.dev/docs/api/class-browser#browser-new-context-option-record-har).
3010
3016
  * @property [testIdAttribute = data-testid] - locate elements based on the testIdAttribute. See more of [locate by test id](https://playwright.dev/docs/locators#locate-by-test-id).
3011
3017
  */
3018
+ // @ts-ignore
3019
+ // @ts-ignore
3020
+ // @ts-ignore
3012
3021
  type PlaywrightConfig = {
3013
3022
  url?: string;
3014
3023
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -6536,6 +6545,9 @@ declare namespace CodeceptJS {
6536
6545
  * @property [chrome] - pass additional [Puppeteer run options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).
6537
6546
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6538
6547
  */
6548
+ // @ts-ignore
6549
+ // @ts-ignore
6550
+ // @ts-ignore
6539
6551
  type PuppeteerConfig = {
6540
6552
  url: string;
6541
6553
  basicAuth?: any;
@@ -8478,6 +8490,9 @@ declare namespace CodeceptJS {
8478
8490
  * @property [onResponse] - an async function which can update response object.
8479
8491
  * @property [maxUploadFileSize] - set the max content file size in MB when performing api calls.
8480
8492
  */
8493
+ // @ts-ignore
8494
+ // @ts-ignore
8495
+ // @ts-ignore
8481
8496
  type RESTConfig = {
8482
8497
  endpoint?: string;
8483
8498
  prettyPrintJson?: boolean;
@@ -9682,6 +9697,9 @@ declare namespace CodeceptJS {
9682
9697
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
9683
9698
  * @property [logLevel = silent] - level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: https://webdriver.io/docs/configuration/#loglevel
9684
9699
  */
9700
+ // @ts-ignore
9701
+ // @ts-ignore
9702
+ // @ts-ignore
9685
9703
  type WebDriverConfig = {
9686
9704
  url: string;
9687
9705
  browser: string;
@@ -12209,12 +12227,29 @@ declare namespace CodeceptJS {
12209
12227
  * global values for current session
12210
12228
  */
12211
12229
  namespace store {
12230
+ /**
12231
+ * If we are in --debug mode
12232
+ */
12212
12233
  var debugMode: boolean;
12234
+ /**
12235
+ * Is timeouts enabled
12236
+ */
12213
12237
  var timeouts: boolean;
12238
+ /**
12239
+ * If auto-retries are enabled by retryFailedStep plugin
12240
+ * tryTo effect disables them
12241
+ */
12242
+ var autoRetries: boolean;
12243
+ /**
12244
+ * Tests are executed via dry-run
12245
+ */
12214
12246
  var dryRun: boolean;
12247
+ /**
12248
+ * If we are in pause mode
12249
+ */
12215
12250
  var onPause: boolean;
12216
12251
  var currentTest: CodeceptJS.Test | null;
12217
- var currentStep: any;
12252
+ var currentStep: CodeceptJS.Step | null;
12218
12253
  var currentSuite: CodeceptJS.Suite | null;
12219
12254
  }
12220
12255
  /**
@@ -12355,6 +12390,9 @@ declare namespace CodeceptJS {
12355
12390
  */
12356
12391
  err: Error | null;
12357
12392
  }
12393
+ /**
12394
+ * TODO: move to effects
12395
+ */
12358
12396
  function within(context: CodeceptJS.LocatorOrString, fn: (...params: any[]) => any): Promise<any> | undefined;
12359
12397
  /**
12360
12398
  * This is a wrapper on top of [Detox](https://github.com/wix/Detox) library, aimied to unify testing experience for CodeceptJS framework.