codeceptjs 3.6.4 → 3.6.5-beta.1
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 +84 -63
- package/lib/assert/empty.js +19 -19
- package/lib/assert/equal.js +32 -30
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +42 -42
- package/lib/assert/throws.js +13 -11
- package/lib/assert/truth.js +17 -18
- package/lib/command/configMigrate.js +57 -52
- package/lib/command/definitions.js +88 -88
- package/lib/command/dryRun.js +65 -63
- package/lib/command/generate.js +191 -181
- package/lib/command/info.js +39 -37
- package/lib/command/init.js +289 -286
- package/lib/command/interactive.js +32 -32
- package/lib/command/list.js +26 -26
- package/lib/command/run-multiple.js +113 -93
- package/lib/command/run-rerun.js +22 -22
- package/lib/command/run-workers.js +63 -63
- package/lib/command/run.js +24 -26
- package/lib/command/utils.js +64 -63
- package/lib/data/context.js +60 -60
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +26 -20
- package/lib/helper/AI.js +67 -65
- package/lib/helper/ApiDataFactory.js +72 -69
- package/lib/helper/Appium.js +409 -379
- package/lib/helper/ExpectHelper.js +214 -248
- package/lib/helper/FileSystem.js +77 -78
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +49 -50
- package/lib/helper/JSONResponse.js +64 -62
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +12 -12
- package/lib/helper/Nightmare.js +664 -572
- package/lib/helper/Playwright.js +1320 -1211
- package/lib/helper/Protractor.js +663 -629
- package/lib/helper/Puppeteer.js +1232 -1124
- package/lib/helper/REST.js +87 -72
- package/lib/helper/TestCafe.js +490 -491
- package/lib/helper/WebDriver.js +1294 -1156
- package/lib/interfaces/bdd.js +38 -51
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +122 -111
- package/lib/interfaces/scenarioConfig.js +29 -29
- package/lib/listener/artifacts.js +9 -9
- package/lib/listener/config.js +24 -23
- package/lib/listener/exit.js +12 -12
- package/lib/listener/helpers.js +42 -42
- package/lib/listener/mocha.js +11 -11
- package/lib/listener/retry.js +32 -30
- package/lib/listener/steps.js +50 -51
- package/lib/listener/timeout.js +53 -53
- package/lib/plugin/allure.js +14 -14
- package/lib/plugin/autoDelay.js +29 -36
- package/lib/plugin/autoLogin.js +70 -66
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +92 -77
- package/lib/plugin/customLocator.js +20 -19
- package/lib/plugin/debugErrors.js +24 -24
- package/lib/plugin/eachElement.js +37 -37
- package/lib/plugin/fakerTransform.js +6 -6
- package/lib/plugin/heal.js +66 -63
- package/lib/plugin/pauseOnFail.js +10 -10
- package/lib/plugin/retryFailedStep.js +31 -38
- package/lib/plugin/retryTo.js +28 -28
- package/lib/plugin/screenshotOnFail.js +107 -86
- package/lib/plugin/selenoid.js +131 -117
- package/lib/plugin/standardActingHelpers.js +2 -8
- package/lib/plugin/stepByStepReport.js +102 -92
- package/lib/plugin/stepTimeout.js +23 -22
- package/lib/plugin/subtitles.js +34 -34
- package/lib/plugin/tryTo.js +39 -29
- package/lib/plugin/wdio.js +77 -72
- package/lib/template/heal.js +11 -14
- package/package.json +4 -2
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- package/translations/index.js +9 -9
- package/translations/it-IT.js +1 -1
- package/translations/ja-JP.js +1 -1
- package/translations/pl-PL.js +1 -1
- package/translations/pt-BR.js +1 -1
- package/translations/ru-RU.js +1 -1
- package/translations/zh-CN.js +1 -1
- package/translations/zh-TW.js +1 -1
- package/typings/promiseBasedTypes.d.ts +238 -0
- package/typings/types.d.ts +32 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const path = require('path')
|
|
1
|
+
const path = require('path')
|
|
2
2
|
|
|
3
|
-
const Helper = require('@codeceptjs/helper')
|
|
4
|
-
const REST = require('./REST')
|
|
3
|
+
const Helper = require('@codeceptjs/helper')
|
|
4
|
+
const REST = require('./REST')
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Helper for managing remote data using REST API.
|
|
@@ -184,67 +184,67 @@ const REST = require('./REST');
|
|
|
184
184
|
*/
|
|
185
185
|
class ApiDataFactory extends Helper {
|
|
186
186
|
constructor(config) {
|
|
187
|
-
super(config)
|
|
187
|
+
super(config)
|
|
188
188
|
|
|
189
189
|
const defaultConfig = {
|
|
190
190
|
cleanup: true,
|
|
191
191
|
REST: {},
|
|
192
192
|
factories: {},
|
|
193
193
|
returnId: false,
|
|
194
|
-
}
|
|
195
|
-
this.config = Object.assign(defaultConfig, this.config)
|
|
194
|
+
}
|
|
195
|
+
this.config = Object.assign(defaultConfig, this.config)
|
|
196
196
|
|
|
197
|
-
if (this.config.headers) this.config.REST.defaultHeaders = this.config.headers
|
|
198
|
-
if (this.config.onRequest) this.config.REST.onRequest = this.config.onRequest
|
|
199
|
-
this.restHelper = new REST(Object.assign(this.config.REST, { endpoint: this.config.endpoint }))
|
|
200
|
-
this.factories = this.config.factories
|
|
197
|
+
if (this.config.headers) this.config.REST.defaultHeaders = this.config.headers
|
|
198
|
+
if (this.config.onRequest) this.config.REST.onRequest = this.config.onRequest
|
|
199
|
+
this.restHelper = new REST(Object.assign(this.config.REST, { endpoint: this.config.endpoint }))
|
|
200
|
+
this.factories = this.config.factories
|
|
201
201
|
|
|
202
202
|
for (const factory in this.factories) {
|
|
203
|
-
const factoryConfig = this.factories[factory]
|
|
203
|
+
const factoryConfig = this.factories[factory]
|
|
204
204
|
if (!factoryConfig.uri && !factoryConfig.create) {
|
|
205
205
|
throw new Error(`Uri for factory "${factory}" is not defined. Please set "uri" parameter:
|
|
206
206
|
|
|
207
207
|
"factories": {
|
|
208
208
|
"${factory}": {
|
|
209
209
|
"uri": ...
|
|
210
|
-
`)
|
|
210
|
+
`)
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
if (!factoryConfig.create) factoryConfig.create = { post: factoryConfig.uri }
|
|
214
|
-
if (!factoryConfig.delete) factoryConfig.delete = { delete: `${factoryConfig.uri}/{id}` }
|
|
213
|
+
if (!factoryConfig.create) factoryConfig.create = { post: factoryConfig.uri }
|
|
214
|
+
if (!factoryConfig.delete) factoryConfig.delete = { delete: `${factoryConfig.uri}/{id}` }
|
|
215
215
|
|
|
216
|
-
this.factories[factory] = factoryConfig
|
|
216
|
+
this.factories[factory] = factoryConfig
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
this.created = {}
|
|
220
|
-
Object.keys(this.factories).forEach(f => this.created[f] = [])
|
|
219
|
+
this.created = {}
|
|
220
|
+
Object.keys(this.factories).forEach((f) => (this.created[f] = []))
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
static _checkRequirements() {
|
|
224
224
|
try {
|
|
225
|
-
require('axios')
|
|
226
|
-
require('rosie')
|
|
225
|
+
require('axios')
|
|
226
|
+
require('rosie')
|
|
227
227
|
} catch (e) {
|
|
228
|
-
return ['axios', 'rosie']
|
|
228
|
+
return ['axios', 'rosie']
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
_after() {
|
|
233
233
|
if (!this.config.cleanup || this.config.cleanup === false) {
|
|
234
|
-
return Promise.resolve()
|
|
234
|
+
return Promise.resolve()
|
|
235
235
|
}
|
|
236
|
-
const promises = []
|
|
236
|
+
const promises = []
|
|
237
237
|
|
|
238
238
|
// clean up all created items
|
|
239
239
|
for (const factoryName in this.created) {
|
|
240
|
-
const createdItems = this.created[factoryName]
|
|
241
|
-
if (!createdItems.length) continue
|
|
242
|
-
this.debug(`Deleting ${createdItems.length} ${factoryName}(s)`)
|
|
240
|
+
const createdItems = this.created[factoryName]
|
|
241
|
+
if (!createdItems.length) continue
|
|
242
|
+
this.debug(`Deleting ${createdItems.length} ${factoryName}(s)`)
|
|
243
243
|
for (const id in createdItems) {
|
|
244
|
-
promises.push(this._requestDelete(factoryName, createdItems[id]))
|
|
244
|
+
promises.push(this._requestDelete(factoryName, createdItems[id]))
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
return Promise.all(promises)
|
|
247
|
+
return Promise.all(promises)
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
@@ -266,9 +266,9 @@ class ApiDataFactory extends Helper {
|
|
|
266
266
|
* @returns {Promise<*>}
|
|
267
267
|
*/
|
|
268
268
|
have(factory, params, options) {
|
|
269
|
-
const item = this._createItem(factory, params, options)
|
|
270
|
-
this.debug(`Creating ${factory} ${JSON.stringify(item)}`)
|
|
271
|
-
return this._requestCreate(factory, item)
|
|
269
|
+
const item = this._createItem(factory, params, options)
|
|
270
|
+
this.debug(`Creating ${factory} ${JSON.stringify(item)}`)
|
|
271
|
+
return this._requestCreate(factory, item)
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
/**
|
|
@@ -291,27 +291,27 @@ class ApiDataFactory extends Helper {
|
|
|
291
291
|
* @param {*} [options]
|
|
292
292
|
*/
|
|
293
293
|
haveMultiple(factory, times, params, options) {
|
|
294
|
-
const promises = []
|
|
294
|
+
const promises = []
|
|
295
295
|
for (let i = 0; i < times; i++) {
|
|
296
|
-
promises.push(this.have(factory, params, options))
|
|
296
|
+
promises.push(this.have(factory, params, options))
|
|
297
297
|
}
|
|
298
|
-
return Promise.all(promises)
|
|
298
|
+
return Promise.all(promises)
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
_createItem(model, data, options) {
|
|
302
302
|
if (!this.factories[model]) {
|
|
303
|
-
throw new Error(`Factory ${model} is not defined in config`)
|
|
303
|
+
throw new Error(`Factory ${model} is not defined in config`)
|
|
304
304
|
}
|
|
305
|
-
let modulePath = this.factories[model].factory
|
|
305
|
+
let modulePath = this.factories[model].factory
|
|
306
306
|
try {
|
|
307
307
|
try {
|
|
308
|
-
require.resolve(modulePath)
|
|
308
|
+
require.resolve(modulePath)
|
|
309
309
|
} catch (e) {
|
|
310
|
-
modulePath = path.join(global.codecept_dir, modulePath)
|
|
310
|
+
modulePath = path.join(global.codecept_dir, modulePath)
|
|
311
311
|
}
|
|
312
312
|
// check if the new syntax `export default new Factory()` is used and loads the builder, otherwise loads the module that used old syntax `module.exports = new Factory()`.
|
|
313
|
-
const builder = require(modulePath).default || require(modulePath)
|
|
314
|
-
return builder.build(data, options)
|
|
313
|
+
const builder = require(modulePath).default || require(modulePath)
|
|
314
|
+
return builder.build(data, options)
|
|
315
315
|
} catch (err) {
|
|
316
316
|
throw new Error(`Couldn't load factory file from ${modulePath}, check that
|
|
317
317
|
|
|
@@ -322,17 +322,17 @@ class ApiDataFactory extends Helper {
|
|
|
322
322
|
points to valid factory file.
|
|
323
323
|
Factory file should export an object with build method.
|
|
324
324
|
|
|
325
|
-
Current file error: ${err.message}`)
|
|
325
|
+
Current file error: ${err.message}`)
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
_fetchId(body, factory) {
|
|
330
330
|
if (this.config.factories[factory].fetchId) {
|
|
331
|
-
return this.config.factories[factory].fetchId(body)
|
|
331
|
+
return this.config.factories[factory].fetchId(body)
|
|
332
332
|
}
|
|
333
|
-
if (body.id) return body.id
|
|
334
|
-
if (body[factory] && body[factory].id) return body[factory].id
|
|
335
|
-
return null
|
|
333
|
+
if (body.id) return body.id
|
|
334
|
+
if (body[factory] && body[factory].id) return body[factory].id
|
|
335
|
+
return null
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
/**
|
|
@@ -343,27 +343,27 @@ Current file error: ${err.message}`);
|
|
|
343
343
|
* @param {*} data
|
|
344
344
|
*/
|
|
345
345
|
_requestCreate(factory, data) {
|
|
346
|
-
let request = createRequestFromFunction(this.factories[factory].create, data)
|
|
346
|
+
let request = createRequestFromFunction(this.factories[factory].create, data)
|
|
347
347
|
|
|
348
348
|
if (!request) {
|
|
349
|
-
const method = Object.keys(this.factories[factory].create)[0]
|
|
350
|
-
const url = this.factories[factory].create[method]
|
|
349
|
+
const method = Object.keys(this.factories[factory].create)[0]
|
|
350
|
+
const url = this.factories[factory].create[method]
|
|
351
351
|
request = {
|
|
352
352
|
method,
|
|
353
353
|
url,
|
|
354
354
|
data,
|
|
355
|
-
}
|
|
355
|
+
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
request.baseURL = this.config.endpoint
|
|
358
|
+
request.baseURL = this.config.endpoint
|
|
359
359
|
|
|
360
360
|
return this.restHelper._executeRequest(request).then((resp) => {
|
|
361
|
-
const id = this._fetchId(resp.data, factory)
|
|
362
|
-
this.created[factory].push(id)
|
|
363
|
-
this.debugSection('Created', `Id: ${id}`)
|
|
364
|
-
if (this.config.returnId) return id
|
|
365
|
-
return resp.data
|
|
366
|
-
})
|
|
361
|
+
const id = this._fetchId(resp.data, factory)
|
|
362
|
+
this.created[factory].push(id)
|
|
363
|
+
this.debugSection('Created', `Id: ${id}`)
|
|
364
|
+
if (this.config.returnId) return id
|
|
365
|
+
return resp.data
|
|
366
|
+
})
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
/**
|
|
@@ -374,37 +374,40 @@ Current file error: ${err.message}`);
|
|
|
374
374
|
* @param {*} id
|
|
375
375
|
*/
|
|
376
376
|
_requestDelete(factory, id) {
|
|
377
|
-
if (!this.factories[factory].delete) return
|
|
378
|
-
let request = createRequestFromFunction(this.factories[factory].delete, id)
|
|
377
|
+
if (!this.factories[factory].delete) return
|
|
378
|
+
let request = createRequestFromFunction(this.factories[factory].delete, id)
|
|
379
379
|
|
|
380
380
|
if (!request) {
|
|
381
|
-
const method = Object.keys(this.factories[factory].delete)[0]
|
|
381
|
+
const method = Object.keys(this.factories[factory].delete)[0]
|
|
382
382
|
|
|
383
|
-
const url = this.factories[factory].delete[method].replace('{id}', id)
|
|
383
|
+
const url = this.factories[factory].delete[method].replace('{id}', id)
|
|
384
384
|
|
|
385
385
|
request = {
|
|
386
386
|
method,
|
|
387
387
|
url,
|
|
388
|
-
}
|
|
388
|
+
}
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
request.baseURL = this.config.endpoint
|
|
391
|
+
request.baseURL = this.config.endpoint
|
|
392
392
|
|
|
393
393
|
if (request.url.match(/^undefined/)) {
|
|
394
|
-
return this.debugSection(
|
|
394
|
+
return this.debugSection(
|
|
395
|
+
'Please configure the delete request in your ApiDataFactory helper',
|
|
396
|
+
"delete: () => ({ method: 'DELETE', url: '/api/users' })",
|
|
397
|
+
)
|
|
395
398
|
}
|
|
396
399
|
|
|
397
400
|
return this.restHelper._executeRequest(request).then(() => {
|
|
398
|
-
const idx = this.created[factory].indexOf(id)
|
|
399
|
-
this.debugSection('Deleted Id', `Id: ${id}`)
|
|
400
|
-
this.created[factory].splice(idx, 1)
|
|
401
|
-
})
|
|
401
|
+
const idx = this.created[factory].indexOf(id)
|
|
402
|
+
this.debugSection('Deleted Id', `Id: ${id}`)
|
|
403
|
+
this.created[factory].splice(idx, 1)
|
|
404
|
+
})
|
|
402
405
|
}
|
|
403
406
|
}
|
|
404
407
|
|
|
405
|
-
module.exports = ApiDataFactory
|
|
408
|
+
module.exports = ApiDataFactory
|
|
406
409
|
|
|
407
410
|
function createRequestFromFunction(param, data) {
|
|
408
|
-
if (typeof param !== 'function') return
|
|
409
|
-
return param(data)
|
|
411
|
+
if (typeof param !== 'function') return
|
|
412
|
+
return param(data)
|
|
410
413
|
}
|