codeceptjs 4.0.0-beta.4 → 4.0.0-beta.6.esm-aria

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 (188) hide show
  1. package/README.md +89 -119
  2. package/bin/codecept.js +53 -54
  3. package/docs/webapi/clearCookie.mustache +1 -1
  4. package/lib/actor.js +70 -102
  5. package/lib/ai.js +131 -121
  6. package/lib/assert/empty.js +11 -12
  7. package/lib/assert/equal.js +16 -21
  8. package/lib/assert/error.js +2 -2
  9. package/lib/assert/include.js +11 -15
  10. package/lib/assert/throws.js +3 -5
  11. package/lib/assert/truth.js +10 -7
  12. package/lib/assert.js +18 -18
  13. package/lib/codecept.js +112 -101
  14. package/lib/colorUtils.js +48 -50
  15. package/lib/command/check.js +206 -0
  16. package/lib/command/configMigrate.js +13 -14
  17. package/lib/command/definitions.js +24 -36
  18. package/lib/command/dryRun.js +16 -16
  19. package/lib/command/generate.js +38 -39
  20. package/lib/command/gherkin/init.js +36 -38
  21. package/lib/command/gherkin/snippets.js +76 -74
  22. package/lib/command/gherkin/steps.js +21 -18
  23. package/lib/command/info.js +49 -15
  24. package/lib/command/init.js +41 -37
  25. package/lib/command/interactive.js +22 -13
  26. package/lib/command/list.js +11 -10
  27. package/lib/command/run-multiple/chunk.js +50 -47
  28. package/lib/command/run-multiple/collection.js +5 -5
  29. package/lib/command/run-multiple/run.js +3 -3
  30. package/lib/command/run-multiple.js +27 -47
  31. package/lib/command/run-rerun.js +6 -7
  32. package/lib/command/run-workers.js +15 -66
  33. package/lib/command/run.js +8 -8
  34. package/lib/command/utils.js +22 -21
  35. package/lib/command/workers/runTests.js +131 -241
  36. package/lib/config.js +111 -49
  37. package/lib/container.js +589 -244
  38. package/lib/data/context.js +16 -18
  39. package/lib/data/dataScenarioConfig.js +9 -9
  40. package/lib/data/dataTableArgument.js +7 -7
  41. package/lib/data/table.js +6 -12
  42. package/lib/effects.js +307 -0
  43. package/lib/els.js +160 -0
  44. package/lib/event.js +24 -19
  45. package/lib/globals.js +141 -0
  46. package/lib/heal.js +89 -81
  47. package/lib/helper/AI.js +3 -2
  48. package/lib/helper/ApiDataFactory.js +19 -19
  49. package/lib/helper/Appium.js +47 -51
  50. package/lib/helper/FileSystem.js +35 -15
  51. package/lib/helper/GraphQL.js +1 -1
  52. package/lib/helper/GraphQLDataFactory.js +4 -4
  53. package/lib/helper/JSONResponse.js +72 -45
  54. package/lib/helper/Mochawesome.js +14 -11
  55. package/lib/helper/Playwright.js +832 -434
  56. package/lib/helper/Puppeteer.js +393 -292
  57. package/lib/helper/REST.js +32 -27
  58. package/lib/helper/WebDriver.js +320 -219
  59. package/lib/helper/errors/ConnectionRefused.js +6 -6
  60. package/lib/helper/errors/ElementAssertion.js +11 -16
  61. package/lib/helper/errors/ElementNotFound.js +5 -9
  62. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  63. package/lib/helper/extras/Console.js +11 -11
  64. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  65. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  66. package/lib/helper/extras/PlaywrightRestartOpts.js +23 -23
  67. package/lib/helper/extras/Popup.js +22 -22
  68. package/lib/helper/extras/React.js +29 -30
  69. package/lib/helper/network/actions.js +33 -48
  70. package/lib/helper/network/utils.js +76 -83
  71. package/lib/helper/scripts/blurElement.js +6 -6
  72. package/lib/helper/scripts/focusElement.js +6 -6
  73. package/lib/helper/scripts/highlightElement.js +9 -9
  74. package/lib/helper/scripts/isElementClickable.js +34 -34
  75. package/lib/helper.js +2 -1
  76. package/lib/history.js +23 -20
  77. package/lib/hooks.js +10 -10
  78. package/lib/html.js +90 -100
  79. package/lib/index.js +48 -21
  80. package/lib/listener/config.js +8 -9
  81. package/lib/listener/emptyRun.js +54 -0
  82. package/lib/listener/exit.js +10 -12
  83. package/lib/listener/{retry.js → globalRetry.js} +10 -10
  84. package/lib/listener/globalTimeout.js +166 -0
  85. package/lib/listener/helpers.js +43 -24
  86. package/lib/listener/mocha.js +4 -5
  87. package/lib/listener/result.js +11 -0
  88. package/lib/listener/steps.js +26 -23
  89. package/lib/listener/store.js +20 -0
  90. package/lib/locator.js +213 -192
  91. package/lib/mocha/asyncWrapper.js +264 -0
  92. package/lib/mocha/bdd.js +167 -0
  93. package/lib/mocha/cli.js +341 -0
  94. package/lib/mocha/factory.js +160 -0
  95. package/lib/{interfaces → mocha}/featureConfig.js +33 -13
  96. package/lib/{interfaces → mocha}/gherkin.js +75 -45
  97. package/lib/mocha/hooks.js +121 -0
  98. package/lib/mocha/index.js +21 -0
  99. package/lib/mocha/inject.js +46 -0
  100. package/lib/{interfaces → mocha}/scenarioConfig.js +32 -8
  101. package/lib/mocha/suite.js +89 -0
  102. package/lib/mocha/test.js +178 -0
  103. package/lib/mocha/types.d.ts +42 -0
  104. package/lib/mocha/ui.js +229 -0
  105. package/lib/output.js +86 -64
  106. package/lib/parser.js +44 -44
  107. package/lib/pause.js +160 -139
  108. package/lib/plugin/analyze.js +403 -0
  109. package/lib/plugin/{autoLogin.js → auth.js} +137 -43
  110. package/lib/plugin/autoDelay.js +19 -15
  111. package/lib/plugin/coverage.js +22 -27
  112. package/lib/plugin/customLocator.js +5 -5
  113. package/lib/plugin/customReporter.js +53 -0
  114. package/lib/plugin/heal.js +49 -17
  115. package/lib/plugin/pageInfo.js +140 -0
  116. package/lib/plugin/pauseOnFail.js +4 -3
  117. package/lib/plugin/retryFailedStep.js +60 -19
  118. package/lib/plugin/screenshotOnFail.js +80 -83
  119. package/lib/plugin/stepByStepReport.js +70 -31
  120. package/lib/plugin/stepTimeout.js +7 -13
  121. package/lib/plugin/subtitles.js +10 -9
  122. package/lib/recorder.js +167 -126
  123. package/lib/rerun.js +94 -50
  124. package/lib/result.js +161 -0
  125. package/lib/secret.js +18 -17
  126. package/lib/session.js +95 -89
  127. package/lib/step/base.js +239 -0
  128. package/lib/step/comment.js +10 -0
  129. package/lib/step/config.js +50 -0
  130. package/lib/step/func.js +46 -0
  131. package/lib/step/helper.js +50 -0
  132. package/lib/step/meta.js +99 -0
  133. package/lib/step/record.js +74 -0
  134. package/lib/step/retry.js +11 -0
  135. package/lib/step/section.js +55 -0
  136. package/lib/step.js +18 -332
  137. package/lib/steps.js +54 -0
  138. package/lib/store.js +37 -5
  139. package/lib/template/heal.js +2 -11
  140. package/lib/timeout.js +60 -0
  141. package/lib/transform.js +8 -8
  142. package/lib/translation.js +32 -18
  143. package/lib/utils.js +354 -250
  144. package/lib/workerStorage.js +16 -16
  145. package/lib/workers.js +366 -282
  146. package/package.json +107 -95
  147. package/translations/de-DE.js +5 -4
  148. package/translations/fr-FR.js +5 -4
  149. package/translations/index.js +23 -9
  150. package/translations/it-IT.js +5 -4
  151. package/translations/ja-JP.js +5 -4
  152. package/translations/nl-NL.js +76 -0
  153. package/translations/pl-PL.js +5 -4
  154. package/translations/pt-BR.js +5 -4
  155. package/translations/ru-RU.js +5 -4
  156. package/translations/utils.js +18 -0
  157. package/translations/zh-CN.js +5 -4
  158. package/translations/zh-TW.js +5 -4
  159. package/typings/index.d.ts +177 -186
  160. package/typings/promiseBasedTypes.d.ts +3573 -5941
  161. package/typings/types.d.ts +4042 -6370
  162. package/lib/cli.js +0 -256
  163. package/lib/helper/ExpectHelper.js +0 -391
  164. package/lib/helper/Nightmare.js +0 -1504
  165. package/lib/helper/Protractor.js +0 -1863
  166. package/lib/helper/SoftExpectHelper.js +0 -381
  167. package/lib/helper/TestCafe.js +0 -1414
  168. package/lib/helper/clientscripts/nightmare.js +0 -213
  169. package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -43
  170. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  171. package/lib/helper/testcafe/testcafe-utils.js +0 -62
  172. package/lib/interfaces/bdd.js +0 -81
  173. package/lib/listener/artifacts.js +0 -19
  174. package/lib/listener/timeout.js +0 -109
  175. package/lib/mochaFactory.js +0 -113
  176. package/lib/plugin/allure.js +0 -15
  177. package/lib/plugin/commentStep.js +0 -136
  178. package/lib/plugin/debugErrors.js +0 -67
  179. package/lib/plugin/eachElement.js +0 -127
  180. package/lib/plugin/fakerTransform.js +0 -49
  181. package/lib/plugin/retryTo.js +0 -127
  182. package/lib/plugin/selenoid.js +0 -384
  183. package/lib/plugin/standardActingHelpers.js +0 -3
  184. package/lib/plugin/tryTo.js +0 -115
  185. package/lib/plugin/wdio.js +0 -249
  186. package/lib/scenario.js +0 -224
  187. package/lib/ui.js +0 -236
  188. package/lib/within.js +0 -70
@@ -1,13 +1,6 @@
1
- const Helper = require('@codeceptjs/helper')
2
-
3
- let expect
4
-
5
- import('chai').then((chai) => {
6
- expect = chai.expect
7
- chai.use(require('chai-deep-match'))
8
- })
9
-
10
- const joi = require('joi')
1
+ import Helper from '@codeceptjs/helper'
2
+ import assert from 'assert'
3
+ import joi from 'joi'
11
4
 
12
5
  /**
13
6
  * This helper allows performing assertions on JSON responses paired with following helpers:
@@ -76,14 +69,17 @@ class JSONResponse extends Helper {
76
69
 
77
70
  _beforeSuite() {
78
71
  this.response = null
79
- if (!this.helpers[this.options.requestHelper]) {
80
- throw new Error(
81
- `Error setting JSONResponse, helper ${this.options.requestHelper} is not enabled in config, helpers: ${Object.keys(this.helpers)}`,
82
- )
83
- }
84
- // connect to REST helper
85
- this.helpers[this.options.requestHelper].config.onResponse = (response) => {
86
- this.response = response
72
+ try {
73
+ if (!this.helpers[this.options.requestHelper]) {
74
+ throw new Error(`Error setting JSONResponse, helper ${this.options.requestHelper} is not enabled in config, helpers: ${Object.keys(this.helpers)}`)
75
+ }
76
+ // connect to REST helper
77
+ this.helpers[this.options.requestHelper].config.onResponse = response => {
78
+ this.response = response
79
+ }
80
+ } catch (e) {
81
+ // Temporary workaround for ESM transition - helpers access issue
82
+ console.log('[JSONResponse] Warning: Could not connect to REST helper during ESM transition:', e.message)
87
83
  }
88
84
  }
89
85
 
@@ -93,7 +89,9 @@ class JSONResponse extends Helper {
93
89
 
94
90
  static _checkRequirements() {
95
91
  try {
96
- require('joi')
92
+ // In ESM, joi is already imported at the top
93
+ // The import will fail at module load time if joi is missing
94
+ return null
97
95
  } catch (e) {
98
96
  return ['joi']
99
97
  }
@@ -110,7 +108,7 @@ class JSONResponse extends Helper {
110
108
  */
111
109
  seeResponseCodeIs(code) {
112
110
  this._checkResponseReady()
113
- expect(this.response.status).to.eql(code, 'Response code is not the same as expected')
111
+ assert.strictEqual(this.response.status, code, 'Response code is not the same as expected')
114
112
  }
115
113
 
116
114
  /**
@@ -124,7 +122,7 @@ class JSONResponse extends Helper {
124
122
  */
125
123
  dontSeeResponseCodeIs(code) {
126
124
  this._checkResponseReady()
127
- expect(this.response.status).not.to.eql(code)
125
+ assert.notStrictEqual(this.response.status, code)
128
126
  }
129
127
 
130
128
  /**
@@ -132,8 +130,7 @@ class JSONResponse extends Helper {
132
130
  */
133
131
  seeResponseCodeIsClientError() {
134
132
  this._checkResponseReady()
135
- expect(this.response.status).to.be.gte(400)
136
- expect(this.response.status).to.be.lt(500)
133
+ assert(this.response.status >= 400 && this.response.status < 500)
137
134
  }
138
135
 
139
136
  /**
@@ -141,8 +138,7 @@ class JSONResponse extends Helper {
141
138
  */
142
139
  seeResponseCodeIsRedirection() {
143
140
  this._checkResponseReady()
144
- expect(this.response.status).to.be.gte(300)
145
- expect(this.response.status).to.be.lt(400)
141
+ assert(this.response.status >= 300 && this.response.status < 400)
146
142
  }
147
143
 
148
144
  /**
@@ -150,8 +146,7 @@ class JSONResponse extends Helper {
150
146
  */
151
147
  seeResponseCodeIsServerError() {
152
148
  this._checkResponseReady()
153
- expect(this.response.status).to.be.gte(500)
154
- expect(this.response.status).to.be.lt(600)
149
+ assert(this.response.status >= 500 && this.response.status < 600)
155
150
  }
156
151
 
157
152
  /**
@@ -164,8 +159,7 @@ class JSONResponse extends Helper {
164
159
  */
165
160
  seeResponseCodeIsSuccessful() {
166
161
  this._checkResponseReady()
167
- expect(this.response.status).to.be.gte(200)
168
- expect(this.response.status).to.be.lt(300)
162
+ assert(this.response.status >= 200 && this.response.status < 300)
169
163
  }
170
164
 
171
165
  /**
@@ -188,17 +182,19 @@ class JSONResponse extends Helper {
188
182
  seeResponseContainsJson(json = {}) {
189
183
  this._checkResponseReady()
190
184
  if (Array.isArray(this.response.data)) {
191
- let fails = 0
185
+ let found = false
192
186
  for (const el of this.response.data) {
193
187
  try {
194
- expect(el).to.deep.match(json)
188
+ this._assertContains(el, json)
189
+ found = true
190
+ break
195
191
  } catch (err) {
196
- fails++
192
+ continue
197
193
  }
198
194
  }
199
- expect(fails < this.response.data.length, `No elements in array matched ${JSON.stringify(json)}`).to.be.true
195
+ assert(found, `No elements in array matched ${JSON.stringify(json)}`)
200
196
  } else {
201
- expect(this.response.data).to.deep.match(json)
197
+ this._assertContains(this.response.data, json)
202
198
  }
203
199
  }
204
200
 
@@ -222,9 +218,22 @@ class JSONResponse extends Helper {
222
218
  dontSeeResponseContainsJson(json = {}) {
223
219
  this._checkResponseReady()
224
220
  if (Array.isArray(this.response.data)) {
225
- this.response.data.forEach((data) => expect(data).not.to.deep.match(json))
221
+ for (const data of this.response.data) {
222
+ try {
223
+ this._assertContains(data, json)
224
+ assert.fail(`Found matching element: ${JSON.stringify(data)}`)
225
+ } catch (err) {
226
+ // expected to fail
227
+ continue
228
+ }
229
+ }
226
230
  } else {
227
- expect(this.response.data).not.to.deep.match(json)
231
+ try {
232
+ this._assertContains(this.response.data, json)
233
+ assert.fail('Response contains the JSON')
234
+ } catch (err) {
235
+ // expected to fail
236
+ }
228
237
  }
229
238
  }
230
239
 
@@ -250,20 +259,27 @@ class JSONResponse extends Helper {
250
259
  seeResponseContainsKeys(keys = []) {
251
260
  this._checkResponseReady()
252
261
  if (Array.isArray(this.response.data)) {
253
- this.response.data.forEach((data) => expect(data).to.include.keys(keys))
262
+ for (const data of this.response.data) {
263
+ for (const key of keys) {
264
+ assert(key in data, `Key "${key}" is not found in ${JSON.stringify(data)}`)
265
+ }
266
+ }
254
267
  } else {
255
- expect(this.response.data).to.include.keys(keys)
268
+ for (const key of keys) {
269
+ assert(key in this.response.data, `Key "${key}" is not found in ${JSON.stringify(this.response.data)}`)
270
+ }
256
271
  }
257
272
  }
258
273
 
259
274
  /**
260
- * Executes a callback function passing in `response` object and chai assertions with `expect`
275
+ * Executes a callback function passing in `response` object and assert
261
276
  * Use it to perform custom checks of response data
262
277
  *
263
278
  * ```js
264
- * I.seeResponseValidByCallback(({ data, status, expect }) => {
265
- * expect(status).to.eql(200);
266
- * expect(data).keys.to.include(['user', 'company']);
279
+ * I.seeResponseValidByCallback(({ data, status }) => {
280
+ * assert.strictEqual(status, 200);
281
+ * assert('user' in data);
282
+ * assert('company' in data);
267
283
  * });
268
284
  * ```
269
285
  *
@@ -271,7 +287,7 @@ class JSONResponse extends Helper {
271
287
  */
272
288
  seeResponseValidByCallback(fn) {
273
289
  this._checkResponseReady()
274
- fn({ ...this.response, expect })
290
+ fn({ ...this.response, assert })
275
291
  const body = fn.toString()
276
292
  fn.toString = () => `${body.split('\n')[1]}...`
277
293
  }
@@ -288,7 +304,7 @@ class JSONResponse extends Helper {
288
304
  */
289
305
  seeResponseEquals(resp) {
290
306
  this._checkResponseReady()
291
- expect(this.response.data).to.deep.equal(resp)
307
+ assert.deepStrictEqual(this.response.data, resp)
292
308
  }
293
309
 
294
310
  /**
@@ -335,6 +351,17 @@ class JSONResponse extends Helper {
335
351
  _checkResponseReady() {
336
352
  if (!this.response) throw new Error('Response is not available')
337
353
  }
354
+
355
+ _assertContains(actual, expected) {
356
+ for (const key in expected) {
357
+ assert(key in actual, `Key "${key}" not found in ${JSON.stringify(actual)}`)
358
+ if (typeof expected[key] === 'object' && expected[key] !== null) {
359
+ this._assertContains(actual[key], expected[key])
360
+ } else {
361
+ assert.deepStrictEqual(actual[key], expected[key], `Values for key "${key}" don't match`)
362
+ }
363
+ }
364
+ }
338
365
  }
339
366
 
340
- module.exports = JSONResponse
367
+ export { JSONResponse as default }
@@ -1,9 +1,10 @@
1
- let addMochawesomeContext
2
1
  let currentTest
3
2
  let currentSuite
4
3
 
5
- const Helper = require('@codeceptjs/helper')
6
- const { clearString } = require('../utils')
4
+ import Helper from '@codeceptjs/helper'
5
+ import { createRequire } from 'module'
6
+ import { clearString } from '../utils.js'
7
+ import { testToFileName } from '../mocha/test.js'
7
8
 
8
9
  class Mochawesome extends Helper {
9
10
  constructor(config) {
@@ -15,7 +16,10 @@ class Mochawesome extends Helper {
15
16
  disableScreenshots: false,
16
17
  }
17
18
 
18
- addMochawesomeContext = require('mochawesome/addContext')
19
+ // ESM-compatible require for CommonJS module
20
+ const require = createRequire(import.meta.url)
21
+ this._addContext = require('mochawesome/addContext')
22
+
19
23
  this._createConfig(config)
20
24
  }
21
25
 
@@ -43,29 +47,28 @@ class Mochawesome extends Helper {
43
47
  if (this.options.disableScreenshots) return
44
48
  let fileName
45
49
  // Get proper name if we are fail on hook
46
- if (test.ctx.test.type === 'hook') {
50
+ if (test.ctx?.test?.type === 'hook') {
47
51
  currentTest = { test: test.ctx.test }
48
52
  // ignore retries if we are in hook
49
53
  test._retries = -1
50
54
  fileName = clearString(`${test.title}_${currentTest.test.title}`)
51
55
  } else {
52
56
  currentTest = { test }
53
- fileName = clearString(test.title)
57
+ fileName = testToFileName(test)
54
58
  }
55
59
  if (this.options.uniqueScreenshotNames) {
56
- const uuid = test.uuid || test.ctx.test.uuid
57
- fileName = `${fileName.substring(0, 10)}_${uuid}`
60
+ fileName = testToFileName(test, { unique: true })
58
61
  }
59
62
  if (test._retries < 1 || test._retries === test.retryNum) {
60
63
  fileName = `${fileName}.failed.png`
61
- return addMochawesomeContext(currentTest, fileName)
64
+ return this._addContext(currentTest, fileName)
62
65
  }
63
66
  }
64
67
 
65
68
  addMochawesomeContext(context) {
66
69
  if (currentTest === '') currentTest = { test: currentSuite.ctx.test }
67
- return addMochawesomeContext(currentTest, context)
70
+ return this._addContext(currentTest, context)
68
71
  }
69
72
  }
70
73
 
71
- module.exports = Mochawesome
74
+ export default Mochawesome