codeceptjs 4.0.0-beta.5 → 4.0.0-beta.7.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 (179) hide show
  1. package/README.md +0 -45
  2. package/bin/codecept.js +46 -57
  3. package/lib/actor.js +15 -11
  4. package/lib/ai.js +6 -5
  5. package/lib/assert/empty.js +9 -8
  6. package/lib/assert/equal.js +15 -17
  7. package/lib/assert/error.js +2 -2
  8. package/lib/assert/include.js +9 -11
  9. package/lib/assert/throws.js +1 -1
  10. package/lib/assert/truth.js +8 -5
  11. package/lib/assert.js +18 -18
  12. package/lib/codecept.js +66 -107
  13. package/lib/colorUtils.js +48 -50
  14. package/lib/command/check.js +32 -27
  15. package/lib/command/configMigrate.js +11 -10
  16. package/lib/command/definitions.js +16 -10
  17. package/lib/command/dryRun.js +16 -16
  18. package/lib/command/generate.js +29 -26
  19. package/lib/command/gherkin/init.js +36 -38
  20. package/lib/command/gherkin/snippets.js +14 -14
  21. package/lib/command/gherkin/steps.js +21 -18
  22. package/lib/command/info.js +8 -8
  23. package/lib/command/init.js +34 -31
  24. package/lib/command/interactive.js +11 -10
  25. package/lib/command/list.js +10 -9
  26. package/lib/command/run-multiple/chunk.js +5 -5
  27. package/lib/command/run-multiple/collection.js +5 -5
  28. package/lib/command/run-multiple/run.js +3 -3
  29. package/lib/command/run-multiple.js +16 -13
  30. package/lib/command/run-rerun.js +6 -7
  31. package/lib/command/run-workers.js +10 -24
  32. package/lib/command/run.js +8 -8
  33. package/lib/command/utils.js +20 -18
  34. package/lib/command/workers/runTests.js +117 -269
  35. package/lib/config.js +111 -49
  36. package/lib/container.js +299 -102
  37. package/lib/data/context.js +6 -5
  38. package/lib/data/dataScenarioConfig.js +1 -1
  39. package/lib/data/dataTableArgument.js +1 -1
  40. package/lib/data/table.js +1 -1
  41. package/lib/effects.js +94 -10
  42. package/lib/els.js +11 -9
  43. package/lib/event.js +11 -10
  44. package/lib/globals.js +141 -0
  45. package/lib/heal.js +12 -12
  46. package/lib/helper/AI.js +1 -1
  47. package/lib/helper/ApiDataFactory.js +16 -13
  48. package/lib/helper/FileSystem.js +32 -12
  49. package/lib/helper/GraphQL.js +1 -1
  50. package/lib/helper/GraphQLDataFactory.js +1 -1
  51. package/lib/helper/JSONResponse.js +19 -30
  52. package/lib/helper/Mochawesome.js +9 -28
  53. package/lib/helper/Playwright.js +668 -265
  54. package/lib/helper/Puppeteer.js +284 -169
  55. package/lib/helper/REST.js +29 -12
  56. package/lib/helper/WebDriver.js +192 -71
  57. package/lib/helper/errors/ConnectionRefused.js +6 -6
  58. package/lib/helper/errors/ElementAssertion.js +11 -16
  59. package/lib/helper/errors/ElementNotFound.js +5 -9
  60. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
  61. package/lib/helper/extras/Console.js +11 -11
  62. package/lib/helper/extras/PlaywrightLocator.js +110 -0
  63. package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
  64. package/lib/helper/extras/PlaywrightRestartOpts.js +23 -23
  65. package/lib/helper/extras/Popup.js +1 -1
  66. package/lib/helper/extras/React.js +29 -30
  67. package/lib/helper/network/actions.js +33 -48
  68. package/lib/helper/network/utils.js +76 -83
  69. package/lib/helper/scripts/blurElement.js +6 -6
  70. package/lib/helper/scripts/focusElement.js +6 -6
  71. package/lib/helper/scripts/highlightElement.js +9 -9
  72. package/lib/helper/scripts/isElementClickable.js +34 -34
  73. package/lib/helper.js +2 -1
  74. package/lib/history.js +23 -20
  75. package/lib/hooks.js +10 -10
  76. package/lib/html.js +90 -100
  77. package/lib/index.js +48 -21
  78. package/lib/listener/config.js +8 -9
  79. package/lib/listener/emptyRun.js +6 -7
  80. package/lib/listener/exit.js +4 -3
  81. package/lib/listener/globalRetry.js +5 -5
  82. package/lib/listener/globalTimeout.js +11 -10
  83. package/lib/listener/helpers.js +33 -14
  84. package/lib/listener/mocha.js +3 -4
  85. package/lib/listener/result.js +4 -5
  86. package/lib/listener/steps.js +7 -18
  87. package/lib/listener/store.js +3 -3
  88. package/lib/locator.js +213 -192
  89. package/lib/mocha/asyncWrapper.js +108 -75
  90. package/lib/mocha/bdd.js +99 -13
  91. package/lib/mocha/cli.js +60 -27
  92. package/lib/mocha/factory.js +75 -19
  93. package/lib/mocha/featureConfig.js +1 -1
  94. package/lib/mocha/gherkin.js +57 -25
  95. package/lib/mocha/hooks.js +12 -3
  96. package/lib/mocha/index.js +13 -4
  97. package/lib/mocha/inject.js +22 -5
  98. package/lib/mocha/scenarioConfig.js +2 -2
  99. package/lib/mocha/suite.js +9 -2
  100. package/lib/mocha/test.js +10 -13
  101. package/lib/mocha/ui.js +28 -31
  102. package/lib/output.js +11 -9
  103. package/lib/parser.js +44 -44
  104. package/lib/pause.js +15 -16
  105. package/lib/plugin/analyze.js +19 -12
  106. package/lib/plugin/auth.js +20 -21
  107. package/lib/plugin/autoDelay.js +12 -8
  108. package/lib/plugin/coverage.js +12 -8
  109. package/lib/plugin/customLocator.js +3 -3
  110. package/lib/plugin/customReporter.js +3 -2
  111. package/lib/plugin/heal.js +14 -9
  112. package/lib/plugin/pageInfo.js +10 -10
  113. package/lib/plugin/pauseOnFail.js +4 -3
  114. package/lib/plugin/retryFailedStep.js +47 -5
  115. package/lib/plugin/screenshotOnFail.js +75 -37
  116. package/lib/plugin/stepByStepReport.js +14 -14
  117. package/lib/plugin/stepTimeout.js +4 -3
  118. package/lib/plugin/subtitles.js +6 -5
  119. package/lib/recorder.js +33 -23
  120. package/lib/rerun.js +69 -26
  121. package/lib/result.js +4 -4
  122. package/lib/secret.js +18 -17
  123. package/lib/session.js +95 -89
  124. package/lib/step/base.js +6 -6
  125. package/lib/step/config.js +1 -1
  126. package/lib/step/func.js +3 -3
  127. package/lib/step/helper.js +3 -3
  128. package/lib/step/meta.js +4 -4
  129. package/lib/step/record.js +11 -11
  130. package/lib/step/retry.js +3 -3
  131. package/lib/step/section.js +3 -3
  132. package/lib/step.js +7 -10
  133. package/lib/steps.js +9 -5
  134. package/lib/store.js +1 -1
  135. package/lib/timeout.js +1 -7
  136. package/lib/transform.js +8 -8
  137. package/lib/translation.js +32 -18
  138. package/lib/utils.js +68 -97
  139. package/lib/workerStorage.js +16 -17
  140. package/lib/workers.js +145 -171
  141. package/package.json +58 -55
  142. package/translations/de-DE.js +2 -2
  143. package/translations/fr-FR.js +2 -2
  144. package/translations/index.js +23 -10
  145. package/translations/it-IT.js +2 -2
  146. package/translations/ja-JP.js +2 -2
  147. package/translations/nl-NL.js +2 -2
  148. package/translations/pl-PL.js +2 -2
  149. package/translations/pt-BR.js +2 -2
  150. package/translations/ru-RU.js +2 -2
  151. package/translations/utils.js +4 -3
  152. package/translations/zh-CN.js +2 -2
  153. package/translations/zh-TW.js +2 -2
  154. package/typings/index.d.ts +7 -18
  155. package/typings/promiseBasedTypes.d.ts +3769 -5450
  156. package/typings/types.d.ts +3953 -5778
  157. package/bin/test-server.js +0 -53
  158. package/lib/element/WebElement.js +0 -327
  159. package/lib/helper/Nightmare.js +0 -1486
  160. package/lib/helper/Protractor.js +0 -1840
  161. package/lib/helper/TestCafe.js +0 -1391
  162. package/lib/helper/clientscripts/nightmare.js +0 -213
  163. package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -43
  164. package/lib/helper/testcafe/testControllerHolder.js +0 -42
  165. package/lib/helper/testcafe/testcafe-utils.js +0 -61
  166. package/lib/listener/retryEnhancer.js +0 -85
  167. package/lib/plugin/allure.js +0 -15
  168. package/lib/plugin/autoLogin.js +0 -5
  169. package/lib/plugin/commentStep.js +0 -141
  170. package/lib/plugin/eachElement.js +0 -127
  171. package/lib/plugin/fakerTransform.js +0 -49
  172. package/lib/plugin/htmlReporter.js +0 -1947
  173. package/lib/plugin/retryTo.js +0 -16
  174. package/lib/plugin/selenoid.js +0 -364
  175. package/lib/plugin/standardActingHelpers.js +0 -6
  176. package/lib/plugin/tryTo.js +0 -16
  177. package/lib/plugin/wdio.js +0 -247
  178. package/lib/test-server.js +0 -323
  179. package/lib/within.js +0 -90
@@ -1,323 +0,0 @@
1
- const express = require('express')
2
- const fs = require('fs')
3
- const path = require('path')
4
-
5
- /**
6
- * Internal API test server to replace json-server dependency
7
- * Provides REST API endpoints for testing CodeceptJS helpers
8
- */
9
- class TestServer {
10
- constructor(config = {}) {
11
- this.app = express()
12
- this.server = null
13
- this.port = config.port || 8010
14
- this.host = config.host || 'localhost'
15
- this.dbFile = config.dbFile || path.join(__dirname, '../test/data/rest/db.json')
16
- this.lastModified = null
17
- this.data = this.loadData()
18
-
19
- this.setupMiddleware()
20
- this.setupRoutes()
21
- this.setupFileWatcher()
22
- }
23
-
24
- loadData() {
25
- try {
26
- const content = fs.readFileSync(this.dbFile, 'utf8')
27
- const data = JSON.parse(content)
28
- // Update lastModified time when loading data
29
- if (fs.existsSync(this.dbFile)) {
30
- this.lastModified = fs.statSync(this.dbFile).mtime
31
- }
32
- console.log('[Data Load] Loaded data from file:', JSON.stringify(data))
33
- return data
34
- } catch (err) {
35
- console.warn(`[Data Load] Could not load data file ${this.dbFile}:`, err.message)
36
- console.log('[Data Load] Using fallback default data')
37
- return {
38
- posts: [{ id: 1, title: 'json-server', author: 'davert' }],
39
- user: { name: 'john', password: '123456' },
40
- }
41
- }
42
- }
43
-
44
- reloadData() {
45
- console.log('[Reload] Reloading data from file...')
46
- this.data = this.loadData()
47
- console.log('[Reload] Data reloaded successfully')
48
- return this.data
49
- }
50
-
51
- saveData() {
52
- try {
53
- fs.writeFileSync(this.dbFile, JSON.stringify(this.data, null, 2))
54
- console.log('[Save] Data saved to file')
55
- // Force update modification time to ensure auto-reload works
56
- const now = new Date()
57
- fs.utimesSync(this.dbFile, now, now)
58
- this.lastModified = now
59
- console.log('[Save] File modification time updated')
60
- } catch (err) {
61
- console.warn(`[Save] Could not save data file ${this.dbFile}:`, err.message)
62
- }
63
- }
64
-
65
- setupMiddleware() {
66
- // Parse JSON bodies
67
- this.app.use(express.json())
68
-
69
- // Parse URL-encoded bodies
70
- this.app.use(express.urlencoded({ extended: true }))
71
-
72
- // CORS support
73
- this.app.use((req, res, next) => {
74
- res.header('Access-Control-Allow-Origin', '*')
75
- res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
76
- res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Test')
77
-
78
- if (req.method === 'OPTIONS') {
79
- res.status(200).end()
80
- return
81
- }
82
- next()
83
- })
84
-
85
- // Auto-reload middleware - check if file changed before each request
86
- this.app.use((req, res, next) => {
87
- try {
88
- if (fs.existsSync(this.dbFile)) {
89
- const stats = fs.statSync(this.dbFile)
90
- if (!this.lastModified || stats.mtime > this.lastModified) {
91
- console.log(`[Auto-reload] Database file changed (${this.dbFile}), reloading data...`)
92
- console.log(`[Auto-reload] Old mtime: ${this.lastModified}, New mtime: ${stats.mtime}`)
93
- this.reloadData()
94
- this.lastModified = stats.mtime
95
- console.log(`[Auto-reload] Data reloaded, user name is now: ${this.data.user?.name}`)
96
- }
97
- }
98
- } catch (err) {
99
- console.warn('[Auto-reload] Error checking file modification time:', err.message)
100
- }
101
- next()
102
- })
103
-
104
- // Logging middleware
105
- this.app.use((req, res, next) => {
106
- console.log(`${req.method} ${req.path}`)
107
- next()
108
- })
109
- }
110
-
111
- setupRoutes() {
112
- // Reload endpoint (for testing)
113
- this.app.post('/_reload', (req, res) => {
114
- this.reloadData()
115
- res.json({ message: 'Data reloaded', data: this.data })
116
- })
117
-
118
- // Headers endpoint (for header testing)
119
- this.app.get('/headers', (req, res) => {
120
- res.json(req.headers)
121
- })
122
-
123
- this.app.post('/headers', (req, res) => {
124
- res.json(req.headers)
125
- })
126
-
127
- // User endpoints
128
- this.app.get('/user', (req, res) => {
129
- console.log(`[GET /user] Serving user data: ${JSON.stringify(this.data.user)}`)
130
- res.json(this.data.user)
131
- })
132
-
133
- this.app.post('/user', (req, res) => {
134
- this.data.user = { ...this.data.user, ...req.body }
135
- this.saveData()
136
- res.status(201).json(this.data.user)
137
- })
138
-
139
- this.app.patch('/user', (req, res) => {
140
- this.data.user = { ...this.data.user, ...req.body }
141
- this.saveData()
142
- res.json(this.data.user)
143
- })
144
-
145
- this.app.put('/user', (req, res) => {
146
- this.data.user = req.body
147
- this.saveData()
148
- res.json(this.data.user)
149
- })
150
-
151
- // Posts endpoints
152
- this.app.get('/posts', (req, res) => {
153
- res.json(this.data.posts)
154
- })
155
-
156
- this.app.get('/posts/:id', (req, res) => {
157
- const id = parseInt(req.params.id)
158
- const post = this.data.posts.find(p => p.id === id)
159
-
160
- if (!post) {
161
- // Return empty object instead of 404 for json-server compatibility
162
- return res.json({})
163
- }
164
-
165
- res.json(post)
166
- })
167
-
168
- this.app.post('/posts', (req, res) => {
169
- const newId = Math.max(...this.data.posts.map(p => p.id || 0)) + 1
170
- const newPost = { id: newId, ...req.body }
171
-
172
- this.data.posts.push(newPost)
173
- this.saveData()
174
- res.status(201).json(newPost)
175
- })
176
-
177
- this.app.put('/posts/:id', (req, res) => {
178
- const id = parseInt(req.params.id)
179
- const postIndex = this.data.posts.findIndex(p => p.id === id)
180
-
181
- if (postIndex === -1) {
182
- return res.status(404).json({ error: 'Post not found' })
183
- }
184
-
185
- this.data.posts[postIndex] = { id, ...req.body }
186
- this.saveData()
187
- res.json(this.data.posts[postIndex])
188
- })
189
-
190
- this.app.patch('/posts/:id', (req, res) => {
191
- const id = parseInt(req.params.id)
192
- const postIndex = this.data.posts.findIndex(p => p.id === id)
193
-
194
- if (postIndex === -1) {
195
- return res.status(404).json({ error: 'Post not found' })
196
- }
197
-
198
- this.data.posts[postIndex] = { ...this.data.posts[postIndex], ...req.body }
199
- this.saveData()
200
- res.json(this.data.posts[postIndex])
201
- })
202
-
203
- this.app.delete('/posts/:id', (req, res) => {
204
- const id = parseInt(req.params.id)
205
- const postIndex = this.data.posts.findIndex(p => p.id === id)
206
-
207
- if (postIndex === -1) {
208
- return res.status(404).json({ error: 'Post not found' })
209
- }
210
-
211
- const deletedPost = this.data.posts.splice(postIndex, 1)[0]
212
- this.saveData()
213
- res.json(deletedPost)
214
- })
215
-
216
- // File upload endpoint (basic implementation)
217
- this.app.post('/upload', (req, res) => {
218
- // Simple upload simulation - for more complex file uploads,
219
- // multer would be needed but basic tests should work
220
- res.json({
221
- message: 'File upload endpoint available',
222
- headers: req.headers,
223
- body: req.body,
224
- })
225
- })
226
-
227
- // Comments endpoints (for ApiDataFactory tests)
228
- this.app.get('/comments', (req, res) => {
229
- res.json(this.data.comments || [])
230
- })
231
-
232
- this.app.post('/comments', (req, res) => {
233
- if (!this.data.comments) this.data.comments = []
234
- const newId = Math.max(...this.data.comments.map(c => c.id || 0), 0) + 1
235
- const newComment = { id: newId, ...req.body }
236
-
237
- this.data.comments.push(newComment)
238
- this.saveData()
239
- res.status(201).json(newComment)
240
- })
241
-
242
- this.app.delete('/comments/:id', (req, res) => {
243
- if (!this.data.comments) this.data.comments = []
244
- const id = parseInt(req.params.id)
245
- const commentIndex = this.data.comments.findIndex(c => c.id === id)
246
-
247
- if (commentIndex === -1) {
248
- return res.status(404).json({ error: 'Comment not found' })
249
- }
250
-
251
- const deletedComment = this.data.comments.splice(commentIndex, 1)[0]
252
- this.saveData()
253
- res.json(deletedComment)
254
- })
255
-
256
- // Generic catch-all for other endpoints
257
- this.app.use((req, res) => {
258
- res.status(404).json({ error: 'Endpoint not found' })
259
- })
260
- }
261
-
262
- setupFileWatcher() {
263
- if (fs.existsSync(this.dbFile)) {
264
- fs.watchFile(this.dbFile, (current, previous) => {
265
- if (current.mtime !== previous.mtime) {
266
- console.log('Database file changed, reloading data...')
267
- this.reloadData()
268
- }
269
- })
270
- }
271
- }
272
-
273
- start() {
274
- return new Promise((resolve, reject) => {
275
- this.server = this.app.listen(this.port, this.host, err => {
276
- if (err) {
277
- reject(err)
278
- } else {
279
- console.log(`Test server running on http://${this.host}:${this.port}`)
280
- resolve(this.server)
281
- }
282
- })
283
- })
284
- }
285
-
286
- stop() {
287
- return new Promise(resolve => {
288
- if (this.server) {
289
- this.server.close(() => {
290
- console.log('Test server stopped')
291
- resolve()
292
- })
293
- } else {
294
- resolve()
295
- }
296
- })
297
- }
298
- }
299
-
300
- module.exports = TestServer
301
-
302
- // CLI usage
303
- if (require.main === module) {
304
- const config = {
305
- port: process.env.PORT || 8010,
306
- host: process.env.HOST || '0.0.0.0',
307
- dbFile: process.argv[2] || path.join(__dirname, '../test/data/rest/db.json'),
308
- }
309
-
310
- const server = new TestServer(config)
311
- server.start().catch(console.error)
312
-
313
- // Graceful shutdown
314
- process.on('SIGINT', () => {
315
- console.log('\nShutting down test server...')
316
- server.stop().then(() => process.exit(0))
317
- })
318
-
319
- process.on('SIGTERM', () => {
320
- console.log('\nShutting down test server...')
321
- server.stop().then(() => process.exit(0))
322
- })
323
- }
package/lib/within.js DELETED
@@ -1,90 +0,0 @@
1
- const output = require('./output')
2
- const store = require('./store')
3
- const recorder = require('./recorder')
4
- const container = require('./container')
5
- const event = require('./event')
6
- const MetaStep = require('./step/meta')
7
- const { isAsyncFunction } = require('./utils')
8
-
9
- /**
10
- * TODO: move to effects
11
- *
12
- * @param {CodeceptJS.LocatorOrString} context
13
- * @param {Function} fn
14
- * @return {Promise<*> | undefined}
15
- */
16
- function within(context, fn) {
17
- const helpers = store.dryRun ? {} : container.helpers()
18
- const locator = typeof context === 'object' ? JSON.stringify(context) : context
19
-
20
- return recorder.add(
21
- 'register within wrapper',
22
- () => {
23
- const metaStep = new WithinStep(locator, fn)
24
- const defineMetaStep = step => (step.metaStep = metaStep)
25
- recorder.session.start('within')
26
-
27
- event.dispatcher.prependListener(event.step.before, defineMetaStep)
28
-
29
- Object.keys(helpers).forEach(helper => {
30
- if (helpers[helper]._withinBegin) recorder.add(`[${helper}] start within`, () => helpers[helper]._withinBegin(context))
31
- })
32
-
33
- const finalize = () => {
34
- event.dispatcher.removeListener(event.step.before, defineMetaStep)
35
- recorder.add('Finalize session within session', () => {
36
- output.stepShift = 1
37
- recorder.session.restore('within')
38
- })
39
- }
40
- const finishHelpers = () => {
41
- Object.keys(helpers).forEach(helper => {
42
- if (helpers[helper]._withinEnd) recorder.add(`[${helper}] finish within`, () => helpers[helper]._withinEnd())
43
- })
44
- }
45
-
46
- if (isAsyncFunction(fn)) {
47
- return fn()
48
- .then(res => {
49
- finishHelpers()
50
- finalize()
51
- return recorder.promise().then(() => res)
52
- })
53
- .catch(e => {
54
- finalize()
55
- recorder.throw(e)
56
- })
57
- }
58
-
59
- let res
60
- try {
61
- res = fn()
62
- } catch (err) {
63
- recorder.throw(err)
64
- } finally {
65
- finishHelpers()
66
- recorder.catch(err => {
67
- output.stepShift = 1
68
- throw err
69
- })
70
- }
71
- finalize()
72
- return recorder.promise().then(() => res)
73
- },
74
- false,
75
- false,
76
- )
77
- }
78
-
79
- module.exports = within
80
-
81
- class WithinStep extends MetaStep {
82
- constructor(locator, fn) {
83
- super('Within')
84
- this.args = [locator]
85
- }
86
-
87
- toString() {
88
- return `${this.prefix}Within ${this.humanizeArgs()}${this.suffix}`
89
- }
90
- }