codeceptjs 4.0.0-beta.3 → 4.0.0-beta.5

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 (155) hide show
  1. package/README.md +134 -119
  2. package/bin/codecept.js +12 -2
  3. package/bin/test-server.js +53 -0
  4. package/docs/webapi/clearCookie.mustache +1 -1
  5. package/lib/actor.js +66 -102
  6. package/lib/ai.js +130 -121
  7. package/lib/assert/empty.js +3 -5
  8. package/lib/assert/equal.js +4 -7
  9. package/lib/assert/include.js +4 -6
  10. package/lib/assert/throws.js +2 -4
  11. package/lib/assert/truth.js +2 -2
  12. package/lib/codecept.js +141 -86
  13. package/lib/command/check.js +201 -0
  14. package/lib/command/configMigrate.js +2 -4
  15. package/lib/command/definitions.js +8 -26
  16. package/lib/command/dryRun.js +30 -35
  17. package/lib/command/generate.js +10 -14
  18. package/lib/command/gherkin/snippets.js +75 -73
  19. package/lib/command/gherkin/steps.js +1 -1
  20. package/lib/command/info.js +42 -8
  21. package/lib/command/init.js +13 -12
  22. package/lib/command/interactive.js +10 -2
  23. package/lib/command/list.js +1 -1
  24. package/lib/command/run-multiple/chunk.js +48 -45
  25. package/lib/command/run-multiple.js +12 -35
  26. package/lib/command/run-workers.js +21 -58
  27. package/lib/command/utils.js +5 -6
  28. package/lib/command/workers/runTests.js +263 -222
  29. package/lib/container.js +386 -238
  30. package/lib/data/context.js +10 -13
  31. package/lib/data/dataScenarioConfig.js +8 -8
  32. package/lib/data/dataTableArgument.js +6 -6
  33. package/lib/data/table.js +5 -11
  34. package/lib/effects.js +223 -0
  35. package/lib/element/WebElement.js +327 -0
  36. package/lib/els.js +158 -0
  37. package/lib/event.js +21 -17
  38. package/lib/heal.js +88 -80
  39. package/lib/helper/AI.js +2 -1
  40. package/lib/helper/ApiDataFactory.js +4 -7
  41. package/lib/helper/Appium.js +50 -57
  42. package/lib/helper/FileSystem.js +3 -3
  43. package/lib/helper/GraphQLDataFactory.js +4 -4
  44. package/lib/helper/JSONResponse.js +75 -37
  45. package/lib/helper/Mochawesome.js +31 -9
  46. package/lib/helper/Nightmare.js +37 -58
  47. package/lib/helper/Playwright.js +267 -272
  48. package/lib/helper/Protractor.js +56 -87
  49. package/lib/helper/Puppeteer.js +247 -264
  50. package/lib/helper/REST.js +29 -17
  51. package/lib/helper/TestCafe.js +22 -47
  52. package/lib/helper/WebDriver.js +157 -368
  53. package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
  54. package/lib/helper/extras/Popup.js +22 -22
  55. package/lib/helper/network/utils.js +1 -1
  56. package/lib/helper/testcafe/testcafe-utils.js +27 -28
  57. package/lib/listener/emptyRun.js +55 -0
  58. package/lib/listener/exit.js +7 -10
  59. package/lib/listener/{retry.js → globalRetry.js} +5 -5
  60. package/lib/listener/globalTimeout.js +165 -0
  61. package/lib/listener/helpers.js +15 -15
  62. package/lib/listener/mocha.js +1 -1
  63. package/lib/listener/result.js +12 -0
  64. package/lib/listener/retryEnhancer.js +85 -0
  65. package/lib/listener/steps.js +32 -18
  66. package/lib/listener/store.js +20 -0
  67. package/lib/locator.js +1 -1
  68. package/lib/mocha/asyncWrapper.js +231 -0
  69. package/lib/{interfaces → mocha}/bdd.js +3 -3
  70. package/lib/mocha/cli.js +308 -0
  71. package/lib/mocha/factory.js +104 -0
  72. package/lib/{interfaces → mocha}/featureConfig.js +32 -12
  73. package/lib/{interfaces → mocha}/gherkin.js +26 -28
  74. package/lib/mocha/hooks.js +112 -0
  75. package/lib/mocha/index.js +12 -0
  76. package/lib/mocha/inject.js +29 -0
  77. package/lib/{interfaces → mocha}/scenarioConfig.js +31 -7
  78. package/lib/mocha/suite.js +82 -0
  79. package/lib/mocha/test.js +181 -0
  80. package/lib/mocha/types.d.ts +42 -0
  81. package/lib/mocha/ui.js +232 -0
  82. package/lib/output.js +93 -65
  83. package/lib/pause.js +160 -138
  84. package/lib/plugin/analyze.js +396 -0
  85. package/lib/plugin/auth.js +435 -0
  86. package/lib/plugin/autoDelay.js +8 -8
  87. package/lib/plugin/autoLogin.js +3 -338
  88. package/lib/plugin/commentStep.js +6 -1
  89. package/lib/plugin/coverage.js +10 -22
  90. package/lib/plugin/customLocator.js +3 -3
  91. package/lib/plugin/customReporter.js +52 -0
  92. package/lib/plugin/eachElement.js +1 -1
  93. package/lib/plugin/fakerTransform.js +1 -1
  94. package/lib/plugin/heal.js +36 -9
  95. package/lib/plugin/htmlReporter.js +1947 -0
  96. package/lib/plugin/pageInfo.js +140 -0
  97. package/lib/plugin/retryFailedStep.js +17 -18
  98. package/lib/plugin/retryTo.js +2 -113
  99. package/lib/plugin/screenshotOnFail.js +17 -58
  100. package/lib/plugin/selenoid.js +15 -35
  101. package/lib/plugin/standardActingHelpers.js +4 -1
  102. package/lib/plugin/stepByStepReport.js +56 -17
  103. package/lib/plugin/stepTimeout.js +5 -12
  104. package/lib/plugin/subtitles.js +4 -4
  105. package/lib/plugin/tryTo.js +3 -102
  106. package/lib/plugin/wdio.js +8 -10
  107. package/lib/recorder.js +155 -124
  108. package/lib/rerun.js +43 -42
  109. package/lib/result.js +161 -0
  110. package/lib/secret.js +1 -2
  111. package/lib/step/base.js +239 -0
  112. package/lib/step/comment.js +10 -0
  113. package/lib/step/config.js +50 -0
  114. package/lib/step/func.js +46 -0
  115. package/lib/step/helper.js +50 -0
  116. package/lib/step/meta.js +99 -0
  117. package/lib/step/record.js +74 -0
  118. package/lib/step/retry.js +11 -0
  119. package/lib/step/section.js +55 -0
  120. package/lib/step.js +21 -332
  121. package/lib/steps.js +50 -0
  122. package/lib/store.js +37 -5
  123. package/lib/template/heal.js +2 -11
  124. package/lib/test-server.js +323 -0
  125. package/lib/timeout.js +66 -0
  126. package/lib/utils.js +351 -218
  127. package/lib/within.js +75 -55
  128. package/lib/workerStorage.js +2 -1
  129. package/lib/workers.js +386 -277
  130. package/package.json +81 -75
  131. package/translations/de-DE.js +5 -3
  132. package/translations/fr-FR.js +5 -4
  133. package/translations/index.js +1 -0
  134. package/translations/it-IT.js +4 -3
  135. package/translations/ja-JP.js +4 -3
  136. package/translations/nl-NL.js +76 -0
  137. package/translations/pl-PL.js +4 -3
  138. package/translations/pt-BR.js +4 -3
  139. package/translations/ru-RU.js +4 -3
  140. package/translations/utils.js +9 -0
  141. package/translations/zh-CN.js +4 -3
  142. package/translations/zh-TW.js +4 -3
  143. package/typings/index.d.ts +197 -187
  144. package/typings/promiseBasedTypes.d.ts +53 -903
  145. package/typings/types.d.ts +372 -1042
  146. package/lib/cli.js +0 -257
  147. package/lib/helper/ExpectHelper.js +0 -391
  148. package/lib/helper/MockServer.js +0 -221
  149. package/lib/helper/SoftExpectHelper.js +0 -381
  150. package/lib/listener/artifacts.js +0 -19
  151. package/lib/listener/timeout.js +0 -109
  152. package/lib/mochaFactory.js +0 -113
  153. package/lib/plugin/debugErrors.js +0 -67
  154. package/lib/scenario.js +0 -224
  155. package/lib/ui.js +0 -236
@@ -13,8 +13,8 @@ module.exports = function (context) {
13
13
  fn = opts
14
14
  opts = {}
15
15
  }
16
- opts.data = data.map((dataRow) => dataRow.data)
17
- data.forEach((dataRow) => {
16
+ opts.data = data.map(dataRow => dataRow.data)
17
+ data.forEach(dataRow => {
18
18
  const dataTitle = replaceTitle(title, dataRow)
19
19
  if (dataRow.skip) {
20
20
  context.xScenario(dataTitle)
@@ -32,8 +32,8 @@ module.exports = function (context) {
32
32
  fn = opts
33
33
  opts = {}
34
34
  }
35
- opts.data = data.map((dataRow) => dataRow.data)
36
- data.forEach((dataRow) => {
35
+ opts.data = data.map(dataRow => dataRow.data)
36
+ data.forEach(dataRow => {
37
37
  const dataTitle = replaceTitle(title, dataRow)
38
38
  if (dataRow.skip) {
39
39
  context.xScenario(dataTitle)
@@ -51,8 +51,8 @@ module.exports = function (context) {
51
51
  context.xData = function (dataTable) {
52
52
  const data = detectDataType(dataTable)
53
53
  return {
54
- Scenario: (title) => {
55
- data.forEach((dataRow) => {
54
+ Scenario: title => {
55
+ data.forEach(dataRow => {
56
56
  const dataTitle = replaceTitle(title, dataRow)
57
57
  context.xScenario(dataTitle)
58
58
  })
@@ -69,10 +69,7 @@ function replaceTitle(title, dataRow) {
69
69
 
70
70
  // if `dataRow` is object and has own `toString()` method,
71
71
  // it should be printed
72
- if (
73
- Object.prototype.toString.call(dataRow.data) === Object().toString() &&
74
- dataRow.data.toString() !== Object().toString()
75
- ) {
72
+ if (Object.prototype.toString.call(dataRow.data) === Object().toString() && dataRow.data.toString() !== Object().toString()) {
76
73
  return `${title} | ${dataRow.data}`
77
74
  }
78
75
 
@@ -102,7 +99,7 @@ function detectDataType(dataTable) {
102
99
  return dataTable()
103
100
  }
104
101
  if (Array.isArray(dataTable)) {
105
- return dataTable.map((item) => {
102
+ return dataTable.map(item => {
106
103
  if (isTableDataRow(item)) {
107
104
  return item
108
105
  }
@@ -117,10 +114,10 @@ function detectDataType(dataTable) {
117
114
  }
118
115
 
119
116
  function maskSecretInTitle(scenarios) {
120
- scenarios.forEach((scenario) => {
117
+ scenarios.forEach(scenario => {
121
118
  const res = []
122
119
 
123
- scenario.test.title.split(',').forEach((item) => {
120
+ scenario.test.title.split(',').forEach(item => {
124
121
  res.push(item.replace(/{"_secret":"(.*)"}/, '"*****"'))
125
122
  })
126
123
 
@@ -10,7 +10,7 @@ class DataScenarioConfig {
10
10
  * @param {*} err
11
11
  */
12
12
  throws(err) {
13
- this.scenarios.forEach((scenario) => scenario.throws(err))
13
+ this.scenarios.forEach(scenario => scenario.throws(err))
14
14
  return this
15
15
  }
16
16
 
@@ -21,7 +21,7 @@ class DataScenarioConfig {
21
21
  *
22
22
  */
23
23
  fails() {
24
- this.scenarios.forEach((scenario) => scenario.fails())
24
+ this.scenarios.forEach(scenario => scenario.fails())
25
25
  return this
26
26
  }
27
27
 
@@ -31,7 +31,7 @@ class DataScenarioConfig {
31
31
  * @param {*} retries
32
32
  */
33
33
  retry(retries) {
34
- this.scenarios.forEach((scenario) => scenario.retry(retries))
34
+ this.scenarios.forEach(scenario => scenario.retry(retries))
35
35
  return this
36
36
  }
37
37
 
@@ -40,7 +40,7 @@ class DataScenarioConfig {
40
40
  * @param {*} timeout
41
41
  */
42
42
  timeout(timeout) {
43
- this.scenarios.forEach((scenario) => scenario.timeout(timeout))
43
+ this.scenarios.forEach(scenario => scenario.timeout(timeout))
44
44
  return this
45
45
  }
46
46
 
@@ -49,7 +49,7 @@ class DataScenarioConfig {
49
49
  * Helper name can be omitted and values will be applied to first helper.
50
50
  */
51
51
  config(helper, obj) {
52
- this.scenarios.forEach((scenario) => scenario.config(helper, obj))
52
+ this.scenarios.forEach(scenario => scenario.config(helper, obj))
53
53
  return this
54
54
  }
55
55
 
@@ -58,7 +58,7 @@ class DataScenarioConfig {
58
58
  * @param {*} tagName
59
59
  */
60
60
  tag(tagName) {
61
- this.scenarios.forEach((scenario) => scenario.tag(tagName))
61
+ this.scenarios.forEach(scenario => scenario.tag(tagName))
62
62
  return this
63
63
  }
64
64
 
@@ -67,7 +67,7 @@ class DataScenarioConfig {
67
67
  * @param {*} obj
68
68
  */
69
69
  inject(obj) {
70
- this.scenarios.forEach((scenario) => scenario.inject(obj))
70
+ this.scenarios.forEach(scenario => scenario.inject(obj))
71
71
  return this
72
72
  }
73
73
 
@@ -76,7 +76,7 @@ class DataScenarioConfig {
76
76
  * @param {*} dependencies
77
77
  */
78
78
  injectDependencies(dependencies) {
79
- this.scenarios.forEach((scenario) => scenario.injectDependencies(dependencies))
79
+ this.scenarios.forEach(scenario => scenario.injectDependencies(dependencies))
80
80
  return this
81
81
  }
82
82
  }
@@ -5,8 +5,8 @@
5
5
  class DataTableArgument {
6
6
  /** @param {*} gherkinDataTable */
7
7
  constructor(gherkinDataTable) {
8
- this.rawData = gherkinDataTable.rows.map((row) => {
9
- return row.cells.map((cell) => {
8
+ this.rawData = gherkinDataTable.rows.map(row => {
9
+ return row.cells.map(cell => {
10
10
  return cell.value
11
11
  })
12
12
  })
@@ -34,7 +34,7 @@ class DataTableArgument {
34
34
  hashes() {
35
35
  const copy = this.raw()
36
36
  const header = copy.shift()
37
- return copy.map((row) => {
37
+ return copy.map(row => {
38
38
  const r = {}
39
39
  row.forEach((cell, index) => (r[header[index]] = cell))
40
40
  return r
@@ -47,19 +47,19 @@ class DataTableArgument {
47
47
  */
48
48
  rowsHash() {
49
49
  const rows = this.raw()
50
- const everyRowHasTwoColumns = rows.every((row) => row.length === 2)
50
+ const everyRowHasTwoColumns = rows.every(row => row.length === 2)
51
51
  if (!everyRowHasTwoColumns) {
52
52
  throw new Error('rowsHash can only be called on a data table where all rows have exactly two columns')
53
53
  }
54
54
  /** @type {Record<string, string>} */
55
55
  const result = {}
56
- rows.forEach((x) => (result[x[0]] = x[1]))
56
+ rows.forEach(x => (result[x[0]] = x[1]))
57
57
  return result
58
58
  }
59
59
 
60
60
  /** Transposed the data */
61
61
  transpose() {
62
- this.rawData = this.rawData[0].map((x, i) => this.rawData.map((y) => y[i]))
62
+ this.rawData = this.rawData[0].map((x, i) => this.rawData.map(y => y[i]))
63
63
  }
64
64
  }
65
65
 
package/lib/data/table.js CHANGED
@@ -10,13 +10,10 @@ class DataTable {
10
10
 
11
11
  /** @param {Array<*>} array */
12
12
  add(array) {
13
- if (array.length !== this.array.length)
14
- throw new Error(
15
- `There is too many elements in given data array. Please provide data in this format: ${this.array}`,
16
- )
13
+ if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`)
17
14
  const tempObj = {}
18
15
  let arrayCounter = 0
19
- this.array.forEach((elem) => {
16
+ this.array.forEach(elem => {
20
17
  tempObj[elem] = array[arrayCounter]
21
18
  tempObj.toString = () => JSON.stringify(tempObj)
22
19
  arrayCounter++
@@ -26,13 +23,10 @@ class DataTable {
26
23
 
27
24
  /** @param {Array<*>} array */
28
25
  xadd(array) {
29
- if (array.length !== this.array.length)
30
- throw new Error(
31
- `There is too many elements in given data array. Please provide data in this format: ${this.array}`,
32
- )
26
+ if (array.length !== this.array.length) throw new Error(`There is too many elements in given data array. Please provide data in this format: ${this.array}`)
33
27
  const tempObj = {}
34
28
  let arrayCounter = 0
35
- this.array.forEach((elem) => {
29
+ this.array.forEach(elem => {
36
30
  tempObj[elem] = array[arrayCounter]
37
31
  tempObj.toString = () => JSON.stringify(tempObj)
38
32
  arrayCounter++
@@ -42,7 +36,7 @@ class DataTable {
42
36
 
43
37
  /** @param {Function} func */
44
38
  filter(func) {
45
- return this.rows.filter((row) => func(row.data))
39
+ return this.rows.filter(row => func(row.data))
46
40
  }
47
41
  }
48
42
 
package/lib/effects.js ADDED
@@ -0,0 +1,223 @@
1
+ const recorder = require('./recorder')
2
+ const { debug } = require('./output')
3
+ const store = require('./store')
4
+ const event = require('./event')
5
+ const within = require('./within')
6
+
7
+ /**
8
+ * A utility function for CodeceptJS tests that acts as a soft assertion.
9
+ * Executes a callback within a recorded session, ensuring errors are handled gracefully without failing the test immediately.
10
+ *
11
+ * @async
12
+ * @function hopeThat
13
+ * @param {Function} callback - The callback function containing the logic to validate.
14
+ * This function should perform the desired assertion or condition check.
15
+ * @returns {Promise<boolean|any>} A promise resolving to `true` if the assertion or condition was successful,
16
+ * or `false` if an error occurred.
17
+ *
18
+ * @description
19
+ * - Designed for use in CodeceptJS tests as a "soft assertion."
20
+ * Unlike standard assertions, it does not stop the test execution on failure.
21
+ * - Starts a new recorder session named 'hopeThat' and manages state restoration.
22
+ * - Logs errors and attaches them as notes to the test, enabling post-test reporting of soft assertion failures.
23
+ * - Resets the `store.hopeThat` flag after the execution, ensuring clean state for subsequent operations.
24
+ *
25
+ * @example
26
+ * const { hopeThat } = require('codeceptjs/effects')
27
+ * await hopeThat(() => {
28
+ * I.see('Welcome'); // Perform a soft assertion
29
+ * });
30
+ *
31
+ * @throws Will handle errors that occur during the callback execution. Errors are logged and attached as notes to the test.
32
+ */
33
+ async function hopeThat(callback) {
34
+ if (store.dryRun) return
35
+ const sessionName = 'hopeThat'
36
+
37
+ let result = false
38
+ return recorder.add(
39
+ 'hopeThat',
40
+ () => {
41
+ recorder.session.start(sessionName)
42
+ store.hopeThat = true
43
+ callback()
44
+ recorder.add(() => {
45
+ result = true
46
+ recorder.session.restore(sessionName)
47
+ return result
48
+ })
49
+ recorder.session.catch(err => {
50
+ result = false
51
+ const msg = err.inspect ? err.inspect() : err.toString()
52
+ debug(`Unsuccessful assertion > ${msg}`)
53
+ event.dispatcher.once(event.test.finished, test => {
54
+ test.notes.push({ type: 'conditionalError', text: msg })
55
+ })
56
+ recorder.session.restore(sessionName)
57
+ return result
58
+ })
59
+ return recorder.add(
60
+ 'result',
61
+ () => {
62
+ store.hopeThat = undefined
63
+ return result
64
+ },
65
+ true,
66
+ false,
67
+ )
68
+ },
69
+ false,
70
+ false,
71
+ )
72
+ }
73
+
74
+ /**
75
+ * A CodeceptJS utility function to retry a step or callback multiple times with a specified polling interval.
76
+ *
77
+ * @async
78
+ * @function retryTo
79
+ * @param {Function} callback - The function to execute, which will be retried upon failure.
80
+ * Receives the current retry count as an argument.
81
+ * @param {number} maxTries - The maximum number of attempts to retry the callback.
82
+ * @param {number} [pollInterval=200] - The delay (in milliseconds) between retry attempts.
83
+ * @returns {Promise<void|any>} A promise that resolves when the callback executes successfully, or rejects after reaching the maximum retries.
84
+ *
85
+ * @description
86
+ * - This function is designed for use in CodeceptJS tests to handle intermittent or flaky test steps.
87
+ * - Starts a new recorder session for each retry attempt, ensuring proper state management and error handling.
88
+ * - Logs errors and retries the callback until it either succeeds or the maximum number of attempts is reached.
89
+ * - Restores the session state after each attempt, whether successful or not.
90
+ *
91
+ * @example
92
+ * const { hopeThat } = require('codeceptjs/effects')
93
+ * await retryTo((tries) => {
94
+ * if (tries < 3) {
95
+ * I.see('Non-existent element'); // Simulates a failure
96
+ * } else {
97
+ * I.see('Welcome'); // Succeeds on the 3rd attempt
98
+ * }
99
+ * }, 5, 300); // Retry up to 5 times, with a 300ms interval
100
+ *
101
+ * @throws Will reject with the last error encountered if the maximum retries are exceeded.
102
+ */
103
+ async function retryTo(callback, maxTries, pollInterval = 200) {
104
+ const sessionName = 'retryTo'
105
+
106
+ return new Promise((done, reject) => {
107
+ let tries = 1
108
+
109
+ function handleRetryException(err) {
110
+ recorder.throw(err)
111
+ reject(err)
112
+ }
113
+
114
+ const tryBlock = async () => {
115
+ tries++
116
+ recorder.session.start(`${sessionName} ${tries}`)
117
+ try {
118
+ await callback(tries)
119
+ } catch (err) {
120
+ handleRetryException(err)
121
+ }
122
+
123
+ // Call done if no errors
124
+ recorder.add(() => {
125
+ recorder.session.restore(`${sessionName} ${tries}`)
126
+ done(null)
127
+ })
128
+
129
+ // Catch errors and retry
130
+ recorder.session.catch(err => {
131
+ recorder.session.restore(`${sessionName} ${tries}`)
132
+ if (tries <= maxTries) {
133
+ debug(`Error ${err}... Retrying`)
134
+ recorder.add(`${sessionName} ${tries}`, () => setTimeout(tryBlock, pollInterval))
135
+ } else {
136
+ // if maxTries reached
137
+ handleRetryException(err)
138
+ }
139
+ })
140
+ }
141
+
142
+ recorder.add(sessionName, tryBlock).catch(err => {
143
+ console.error('An error occurred:', err)
144
+ done(null)
145
+ })
146
+ })
147
+ }
148
+
149
+ /**
150
+ * A CodeceptJS utility function to attempt a step or callback without failing the test.
151
+ * If the step fails, the test continues execution without interruption, and the result is logged.
152
+ *
153
+ * @async
154
+ * @function tryTo
155
+ * @param {Function} callback - The function to execute, which may succeed or fail.
156
+ * This function contains the logic to be attempted.
157
+ * @returns {Promise<boolean|any>} A promise resolving to `true` if the step succeeds, or `false` if it fails.
158
+ *
159
+ * @description
160
+ * - Useful for scenarios where certain steps are optional or their failure should not interrupt the test flow.
161
+ * - Starts a new recorder session named 'tryTo' for isolation and error handling.
162
+ * - Captures errors during execution and logs them for debugging purposes.
163
+ * - Ensures the `store.tryTo` flag is reset after execution to maintain a clean state.
164
+ *
165
+ * @example
166
+ * const { tryTo } = require('codeceptjs/effects')
167
+ * const wasSuccessful = await tryTo(() => {
168
+ * I.see('Welcome'); // Attempt to find an element on the page
169
+ * });
170
+ *
171
+ * if (!wasSuccessful) {
172
+ * I.say('Optional step failed, but test continues.');
173
+ * }
174
+ *
175
+ * @throws Will handle errors internally, logging them and returning `false` as the result.
176
+ */
177
+ async function tryTo(callback) {
178
+ if (store.dryRun) return
179
+ const sessionName = 'tryTo'
180
+
181
+ let result = false
182
+ let isAutoRetriesEnabled = store.autoRetries
183
+ return recorder.add(
184
+ sessionName,
185
+ () => {
186
+ recorder.session.start(sessionName)
187
+ isAutoRetriesEnabled = store.autoRetries
188
+ if (isAutoRetriesEnabled) debug('Auto retries disabled inside tryTo effect')
189
+ store.autoRetries = false
190
+ callback()
191
+ recorder.add(() => {
192
+ result = true
193
+ recorder.session.restore(sessionName)
194
+ return result
195
+ })
196
+ recorder.session.catch(err => {
197
+ result = false
198
+ const msg = err.inspect ? err.inspect() : err.toString()
199
+ debug(`Unsuccessful try > ${msg}`)
200
+ recorder.session.restore(sessionName)
201
+ return result
202
+ })
203
+ return recorder.add(
204
+ 'result',
205
+ () => {
206
+ store.autoRetries = isAutoRetriesEnabled
207
+ return result
208
+ },
209
+ true,
210
+ false,
211
+ )
212
+ },
213
+ false,
214
+ false,
215
+ )
216
+ }
217
+
218
+ module.exports = {
219
+ hopeThat,
220
+ retryTo,
221
+ tryTo,
222
+ within,
223
+ }