codeceptjs 4.0.0-beta.2 → 4.0.0-beta.3

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 (151) hide show
  1. package/bin/codecept.js +84 -81
  2. package/lib/actor.js +13 -13
  3. package/lib/ai.js +10 -13
  4. package/lib/assert/empty.js +20 -21
  5. package/lib/assert/equal.js +37 -39
  6. package/lib/assert/error.js +14 -14
  7. package/lib/assert/include.js +46 -47
  8. package/lib/assert/throws.js +13 -11
  9. package/lib/assert/truth.js +19 -22
  10. package/lib/assert.js +4 -2
  11. package/lib/cli.js +57 -49
  12. package/lib/codecept.js +142 -155
  13. package/lib/colorUtils.js +3 -3
  14. package/lib/command/configMigrate.js +58 -52
  15. package/lib/command/definitions.js +88 -89
  16. package/lib/command/dryRun.js +71 -68
  17. package/lib/command/generate.js +197 -188
  18. package/lib/command/gherkin/init.js +27 -16
  19. package/lib/command/gherkin/snippets.js +20 -20
  20. package/lib/command/gherkin/steps.js +8 -8
  21. package/lib/command/info.js +40 -38
  22. package/lib/command/init.js +290 -288
  23. package/lib/command/interactive.js +32 -32
  24. package/lib/command/list.js +26 -26
  25. package/lib/command/run-multiple/chunk.js +5 -5
  26. package/lib/command/run-multiple/collection.js +3 -3
  27. package/lib/command/run-multiple/run.js +6 -2
  28. package/lib/command/run-multiple.js +113 -93
  29. package/lib/command/run-rerun.js +20 -25
  30. package/lib/command/run-workers.js +64 -66
  31. package/lib/command/run.js +26 -29
  32. package/lib/command/utils.js +80 -65
  33. package/lib/command/workers/runTests.js +10 -10
  34. package/lib/config.js +10 -9
  35. package/lib/container.js +40 -48
  36. package/lib/data/context.js +60 -59
  37. package/lib/data/dataScenarioConfig.js +47 -47
  38. package/lib/data/dataTableArgument.js +29 -29
  39. package/lib/data/table.js +26 -20
  40. package/lib/event.js +163 -167
  41. package/lib/heal.js +13 -17
  42. package/lib/helper/AI.js +130 -41
  43. package/lib/helper/ApiDataFactory.js +73 -69
  44. package/lib/helper/Appium.js +413 -382
  45. package/lib/helper/ExpectHelper.js +40 -48
  46. package/lib/helper/FileSystem.js +80 -79
  47. package/lib/helper/GraphQL.js +44 -43
  48. package/lib/helper/GraphQLDataFactory.js +50 -50
  49. package/lib/helper/JSONResponse.js +65 -62
  50. package/lib/helper/Mochawesome.js +28 -28
  51. package/lib/helper/MockServer.js +12 -14
  52. package/lib/helper/Nightmare.js +662 -566
  53. package/lib/helper/Playwright.js +1361 -1216
  54. package/lib/helper/Protractor.js +663 -627
  55. package/lib/helper/Puppeteer.js +1231 -1128
  56. package/lib/helper/REST.js +159 -68
  57. package/lib/helper/SoftExpectHelper.js +2 -2
  58. package/lib/helper/TestCafe.js +490 -484
  59. package/lib/helper/WebDriver.js +1297 -1156
  60. package/lib/helper/clientscripts/PollyWebDriverExt.js +1 -1
  61. package/lib/helper/errors/ConnectionRefused.js +1 -1
  62. package/lib/helper/errors/ElementAssertion.js +2 -2
  63. package/lib/helper/errors/ElementNotFound.js +2 -2
  64. package/lib/helper/errors/RemoteBrowserConnectionRefused.js +1 -1
  65. package/lib/helper/extras/Console.js +1 -1
  66. package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
  67. package/lib/helper/extras/PlaywrightReactVueLocator.js +1 -1
  68. package/lib/helper/extras/PlaywrightRestartOpts.js +21 -18
  69. package/lib/helper/extras/Popup.js +1 -1
  70. package/lib/helper/extras/React.js +3 -3
  71. package/lib/helper/network/actions.js +14 -7
  72. package/lib/helper/network/utils.js +3 -2
  73. package/lib/helper/scripts/blurElement.js +1 -1
  74. package/lib/helper/scripts/focusElement.js +1 -1
  75. package/lib/helper/scripts/highlightElement.js +1 -1
  76. package/lib/helper/scripts/isElementClickable.js +1 -1
  77. package/lib/helper/testcafe/testControllerHolder.js +1 -1
  78. package/lib/helper/testcafe/testcafe-utils.js +6 -7
  79. package/lib/helper.js +1 -3
  80. package/lib/history.js +6 -5
  81. package/lib/hooks.js +6 -6
  82. package/lib/html.js +7 -7
  83. package/lib/index.js +25 -41
  84. package/lib/interfaces/bdd.js +47 -64
  85. package/lib/interfaces/featureConfig.js +19 -19
  86. package/lib/interfaces/gherkin.js +124 -118
  87. package/lib/interfaces/scenarioConfig.js +29 -29
  88. package/lib/listener/artifacts.js +9 -9
  89. package/lib/listener/config.js +24 -24
  90. package/lib/listener/exit.js +12 -12
  91. package/lib/listener/helpers.js +42 -42
  92. package/lib/listener/mocha.js +11 -11
  93. package/lib/listener/retry.js +32 -30
  94. package/lib/listener/steps.js +50 -53
  95. package/lib/listener/timeout.js +54 -54
  96. package/lib/locator.js +6 -10
  97. package/lib/mochaFactory.js +18 -15
  98. package/lib/output.js +6 -10
  99. package/lib/parser.js +15 -12
  100. package/lib/pause.js +40 -33
  101. package/lib/plugin/allure.js +15 -15
  102. package/lib/plugin/autoDelay.js +29 -37
  103. package/lib/plugin/autoLogin.js +70 -65
  104. package/lib/plugin/commentStep.js +18 -18
  105. package/lib/plugin/coverage.js +115 -67
  106. package/lib/plugin/customLocator.js +21 -20
  107. package/lib/plugin/debugErrors.js +24 -24
  108. package/lib/plugin/eachElement.js +38 -38
  109. package/lib/plugin/fakerTransform.js +6 -6
  110. package/lib/plugin/heal.js +67 -108
  111. package/lib/plugin/pauseOnFail.js +11 -11
  112. package/lib/plugin/retryFailedStep.js +32 -39
  113. package/lib/plugin/retryTo.js +46 -40
  114. package/lib/plugin/screenshotOnFail.js +109 -87
  115. package/lib/plugin/selenoid.js +131 -118
  116. package/lib/plugin/standardActingHelpers.js +2 -8
  117. package/lib/plugin/stepByStepReport.js +110 -91
  118. package/lib/plugin/stepTimeout.js +24 -23
  119. package/lib/plugin/subtitles.js +34 -35
  120. package/lib/plugin/tryTo.js +40 -30
  121. package/lib/plugin/wdio.js +78 -75
  122. package/lib/recorder.js +14 -17
  123. package/lib/rerun.js +11 -10
  124. package/lib/scenario.js +25 -23
  125. package/lib/secret.js +4 -2
  126. package/lib/session.js +10 -10
  127. package/lib/step.js +12 -9
  128. package/lib/store.js +2 -3
  129. package/lib/transform.js +1 -1
  130. package/lib/translation.js +7 -8
  131. package/lib/ui.js +12 -14
  132. package/lib/utils.js +70 -72
  133. package/lib/within.js +10 -10
  134. package/lib/workerStorage.js +27 -25
  135. package/lib/workers.js +29 -32
  136. package/package.json +56 -57
  137. package/translations/de-DE.js +1 -1
  138. package/translations/fr-FR.js +1 -1
  139. package/translations/index.js +9 -13
  140. package/translations/it-IT.js +1 -1
  141. package/translations/ja-JP.js +1 -1
  142. package/translations/pl-PL.js +1 -1
  143. package/translations/pt-BR.js +1 -1
  144. package/translations/ru-RU.js +1 -1
  145. package/translations/zh-CN.js +1 -1
  146. package/translations/zh-TW.js +1 -1
  147. package/typings/index.d.ts +415 -65
  148. package/typings/promiseBasedTypes.d.ts +32 -0
  149. package/typings/types.d.ts +32 -0
  150. package/lib/dirname.js +0 -5
  151. package/lib/helper/Expect.js +0 -425
@@ -1,8 +1,9 @@
1
- import * as output from '../output.js';
1
+ const output = require('../output')
2
2
 
3
- import { expect } from 'chai'
3
+ let expect
4
4
 
5
5
  import('chai').then((chai) => {
6
+ expect = chai.expect
6
7
  chai.use(require('chai-string'))
7
8
  // @ts-ignore
8
9
  chai.use(require('chai-exclude'))
@@ -38,7 +39,7 @@ class ExpectHelper {
38
39
  */
39
40
  expectEqual(actualValue, expectedValue, customErrorMsg = '') {
40
41
  // @ts-ignore
41
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`)
42
+ output.step(`I expect "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`)
42
43
  return expect(actualValue, customErrorMsg).to.equal(expectedValue)
43
44
  }
44
45
 
@@ -50,7 +51,7 @@ class ExpectHelper {
50
51
  */
51
52
  expectNotEqual(actualValue, expectedValue, customErrorMsg = '') {
52
53
  // @ts-ignore
53
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to not equal "${JSON.stringify(expectedValue)}"`)
54
+ output.step(`I expect "${JSON.stringify(actualValue)}" to not equal "${JSON.stringify(expectedValue)}"`)
54
55
  return expect(actualValue, customErrorMsg).not.to.equal(expectedValue)
55
56
  }
56
57
 
@@ -63,7 +64,7 @@ class ExpectHelper {
63
64
  */
64
65
  expectDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
65
66
  // @ts-ignore
66
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to deep equal "${JSON.stringify(expectedValue)}"`)
67
+ output.step(`I expect "${JSON.stringify(actualValue)}" to deep equal "${JSON.stringify(expectedValue)}"`)
67
68
  return expect(actualValue, customErrorMsg).to.deep.equal(expectedValue)
68
69
  }
69
70
 
@@ -75,7 +76,7 @@ class ExpectHelper {
75
76
  */
76
77
  expectNotDeepEqual(actualValue, expectedValue, customErrorMsg = '') {
77
78
  // @ts-ignore
78
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to not deep equal "${JSON.stringify(expectedValue)}"`)
79
+ output.step(`I expect "${JSON.stringify(actualValue)}" to not deep equal "${JSON.stringify(expectedValue)}"`)
79
80
  return expect(actualValue, customErrorMsg).to.not.deep.equal(expectedValue)
80
81
  }
81
82
 
@@ -87,7 +88,7 @@ class ExpectHelper {
87
88
  */
88
89
  expectContain(actualValue, expectedValueToContain, customErrorMsg = '') {
89
90
  // @ts-ignore
90
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to contain "${JSON.stringify(expectedValueToContain)}"`)
91
+ output.step(`I expect "${JSON.stringify(actualValue)}" to contain "${JSON.stringify(expectedValueToContain)}"`)
91
92
  return expect(actualValue, customErrorMsg).to.contain(expectedValueToContain)
92
93
  }
93
94
 
@@ -99,7 +100,7 @@ class ExpectHelper {
99
100
  */
100
101
  expectNotContain(actualValue, expectedValueToNotContain, customErrorMsg = '') {
101
102
  // @ts-ignore
102
- output.output.step(
103
+ output.step(
103
104
  `I expect "${JSON.stringify(actualValue)}" to not contain "${JSON.stringify(expectedValueToNotContain)}"`,
104
105
  )
105
106
  return expect(actualValue, customErrorMsg).not.to.contain(expectedValueToNotContain)
@@ -112,17 +113,11 @@ class ExpectHelper {
112
113
  * @param {*} [customErrorMsg]
113
114
  */
114
115
  expectStartsWith(actualValue, expectedValueToStartWith, customErrorMsg = '') {
115
- // Log the step output
116
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to start with "${JSON.stringify(expectedValueToStartWith)}"`);
117
-
118
- // Check if actualValue is a string
119
- expect(actualValue, customErrorMsg).to.be.a('string');
120
-
121
- // Check if actualValue starts with expectedValueToStartWith
122
- expect(actualValue.startsWith(expectedValueToStartWith), customErrorMsg).to.be.true;
116
+ // @ts-ignore
117
+ output.step(`I expect "${JSON.stringify(actualValue)}" to start with "${JSON.stringify(expectedValueToStartWith)}"`)
118
+ return expect(actualValue, customErrorMsg).to.startsWith(expectedValueToStartWith)
123
119
  }
124
120
 
125
-
126
121
  /**
127
122
  *
128
123
  * @param {*} actualValue
@@ -130,14 +125,11 @@ class ExpectHelper {
130
125
  * @param {*} [customErrorMsg]
131
126
  */
132
127
  expectNotStartsWith(actualValue, expectedValueToNotStartWith, customErrorMsg = '') {
133
- // Log the step output
134
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to not start with "${JSON.stringify(expectedValueToNotStartWith)}"`);
135
-
136
- // Check if actualValue is a string
137
- expect(actualValue, customErrorMsg).to.be.a('string');
138
-
139
- // Check if actualValue starts with expectedValueToStartWith
140
- expect(actualValue.startsWith(expectedValueToNotStartWith), customErrorMsg).to.be.false;
128
+ // @ts-ignore
129
+ output.step(
130
+ `I expect "${JSON.stringify(actualValue)}" to not start with "${JSON.stringify(expectedValueToNotStartWith)}"`,
131
+ )
132
+ return expect(actualValue, customErrorMsg).not.to.startsWith(expectedValueToNotStartWith)
141
133
  }
142
134
 
143
135
  /**
@@ -147,7 +139,7 @@ class ExpectHelper {
147
139
  */
148
140
  expectEndsWith(actualValue, expectedValueToEndWith, customErrorMsg = '') {
149
141
  // @ts-ignore
150
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to end with "${JSON.stringify(expectedValueToEndWith)}"`)
142
+ output.step(`I expect "${JSON.stringify(actualValue)}" to end with "${JSON.stringify(expectedValueToEndWith)}"`)
151
143
  return expect(actualValue, customErrorMsg).to.endsWith(expectedValueToEndWith)
152
144
  }
153
145
 
@@ -158,7 +150,7 @@ class ExpectHelper {
158
150
  */
159
151
  expectNotEndsWith(actualValue, expectedValueToNotEndWith, customErrorMsg = '') {
160
152
  // @ts-ignore
161
- output.output.step(
153
+ output.step(
162
154
  `I expect "${JSON.stringify(actualValue)}" to not end with "${JSON.stringify(expectedValueToNotEndWith)}"`,
163
155
  )
164
156
  return expect(actualValue, customErrorMsg).not.to.endsWith(expectedValueToNotEndWith)
@@ -171,7 +163,7 @@ class ExpectHelper {
171
163
  */
172
164
  expectJsonSchema(targetData, jsonSchema, customErrorMsg = '') {
173
165
  // @ts-ignore
174
- output.output.step(`I expect "${JSON.stringify(targetData)}" to match this JSON schema "${JSON.stringify(jsonSchema)}"`)
166
+ output.step(`I expect "${JSON.stringify(targetData)}" to match this JSON schema "${JSON.stringify(jsonSchema)}"`)
175
167
 
176
168
  return expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema)
177
169
  }
@@ -184,7 +176,7 @@ class ExpectHelper {
184
176
  */
185
177
  expectJsonSchemaUsingAJV(targetData, jsonSchema, customErrorMsg = '', ajvOptions = { allErrors: true }) {
186
178
  // @ts-ignore
187
- output.output.step(
179
+ output.step(
188
180
  `I expect "${JSON.stringify(targetData)}" to match this JSON schema using AJV "${JSON.stringify(jsonSchema)}"`,
189
181
  )
190
182
  chai.use(require('chai-json-schema-ajv').create(ajvOptions))
@@ -198,7 +190,7 @@ class ExpectHelper {
198
190
  */
199
191
  expectHasProperty(targetData, propertyName, customErrorMsg = '') {
200
192
  // @ts-ignore
201
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have property: "${JSON.stringify(propertyName)}"`)
193
+ output.step(`I expect "${JSON.stringify(targetData)}" to have property: "${JSON.stringify(propertyName)}"`)
202
194
  return expect(targetData, customErrorMsg).to.have.property(propertyName)
203
195
  }
204
196
 
@@ -209,7 +201,7 @@ class ExpectHelper {
209
201
  */
210
202
  expectHasAProperty(targetData, propertyName, customErrorMsg = '') {
211
203
  // @ts-ignore
212
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have a property: "${JSON.stringify(propertyName)}"`)
204
+ output.step(`I expect "${JSON.stringify(targetData)}" to have a property: "${JSON.stringify(propertyName)}"`)
213
205
  return expect(targetData, customErrorMsg).to.have.a.property(propertyName)
214
206
  }
215
207
 
@@ -220,7 +212,7 @@ class ExpectHelper {
220
212
  */
221
213
  expectToBeA(targetData, type, customErrorMsg = '') {
222
214
  // @ts-ignore
223
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be a "${JSON.stringify(type)}"`)
215
+ output.step(`I expect "${JSON.stringify(targetData)}" to be a "${JSON.stringify(type)}"`)
224
216
  return expect(targetData, customErrorMsg).to.be.a(type)
225
217
  }
226
218
 
@@ -231,7 +223,7 @@ class ExpectHelper {
231
223
  */
232
224
  expectToBeAn(targetData, type, customErrorMsg = '') {
233
225
  // @ts-ignore
234
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be an "${JSON.stringify(type)}"`)
226
+ output.step(`I expect "${JSON.stringify(targetData)}" to be an "${JSON.stringify(type)}"`)
235
227
  return expect(targetData, customErrorMsg).to.be.an(type)
236
228
  }
237
229
 
@@ -242,7 +234,7 @@ class ExpectHelper {
242
234
  */
243
235
  expectMatchRegex(targetData, regex, customErrorMsg = '') {
244
236
  // @ts-ignore
245
- output.output.step(`I expect "${JSON.stringify(targetData)}" to match the regex "${JSON.stringify(regex)}"`)
237
+ output.step(`I expect "${JSON.stringify(targetData)}" to match the regex "${JSON.stringify(regex)}"`)
246
238
  return expect(targetData, customErrorMsg).to.match(regex)
247
239
  }
248
240
 
@@ -253,7 +245,7 @@ class ExpectHelper {
253
245
  */
254
246
  expectLengthOf(targetData, length, customErrorMsg = '') {
255
247
  // @ts-ignore
256
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of "${JSON.stringify(length)}"`)
248
+ output.step(`I expect "${JSON.stringify(targetData)}" to have length of "${JSON.stringify(length)}"`)
257
249
  return expect(targetData, customErrorMsg).to.have.lengthOf(length)
258
250
  }
259
251
 
@@ -263,7 +255,7 @@ class ExpectHelper {
263
255
  */
264
256
  expectEmpty(targetData, customErrorMsg = '') {
265
257
  // @ts-ignore
266
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be empty`)
258
+ output.step(`I expect "${JSON.stringify(targetData)}" to be empty`)
267
259
  return expect(targetData, customErrorMsg).to.be.empty
268
260
  }
269
261
 
@@ -273,7 +265,7 @@ class ExpectHelper {
273
265
  */
274
266
  expectTrue(targetData, customErrorMsg = '') {
275
267
  // @ts-ignore
276
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be true`)
268
+ output.step(`I expect "${JSON.stringify(targetData)}" to be true`)
277
269
  return expect(targetData, customErrorMsg).to.be.true
278
270
  }
279
271
 
@@ -283,7 +275,7 @@ class ExpectHelper {
283
275
  */
284
276
  expectFalse(targetData, customErrorMsg = '') {
285
277
  // @ts-ignore
286
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be false`)
278
+ output.step(`I expect "${JSON.stringify(targetData)}" to be false`)
287
279
  return expect(targetData, customErrorMsg).to.be.false
288
280
  }
289
281
 
@@ -294,7 +286,7 @@ class ExpectHelper {
294
286
  */
295
287
  expectAbove(targetData, aboveThan, customErrorMsg = '') {
296
288
  // @ts-ignore
297
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be above ${JSON.stringify(aboveThan)}`)
289
+ output.step(`I expect "${JSON.stringify(targetData)}" to be above ${JSON.stringify(aboveThan)}`)
298
290
  return expect(targetData, customErrorMsg).to.be.above(aboveThan)
299
291
  }
300
292
 
@@ -305,7 +297,7 @@ class ExpectHelper {
305
297
  */
306
298
  expectBelow(targetData, belowThan, customErrorMsg = '') {
307
299
  // @ts-ignore
308
- output.output.step(`I expect "${JSON.stringify(targetData)}" to be below ${JSON.stringify(belowThan)}`)
300
+ output.step(`I expect "${JSON.stringify(targetData)}" to be below ${JSON.stringify(belowThan)}`)
309
301
  return expect(targetData, customErrorMsg).to.be.below(belowThan)
310
302
  }
311
303
 
@@ -316,7 +308,7 @@ class ExpectHelper {
316
308
  */
317
309
  expectLengthAboveThan(targetData, lengthAboveThan, customErrorMsg = '') {
318
310
  // @ts-ignore
319
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of above ${JSON.stringify(lengthAboveThan)}`)
311
+ output.step(`I expect "${JSON.stringify(targetData)}" to have length of above ${JSON.stringify(lengthAboveThan)}`)
320
312
  return expect(targetData, customErrorMsg).to.have.lengthOf.above(lengthAboveThan)
321
313
  }
322
314
 
@@ -327,7 +319,7 @@ class ExpectHelper {
327
319
  */
328
320
  expectLengthBelowThan(targetData, lengthBelowThan, customErrorMsg = '') {
329
321
  // @ts-ignore
330
- output.output.step(`I expect "${JSON.stringify(targetData)}" to have length of below ${JSON.stringify(lengthBelowThan)}`)
322
+ output.step(`I expect "${JSON.stringify(targetData)}" to have length of below ${JSON.stringify(lengthBelowThan)}`)
331
323
  return expect(targetData, customErrorMsg).to.have.lengthOf.below(lengthBelowThan)
332
324
  }
333
325
 
@@ -338,7 +330,7 @@ class ExpectHelper {
338
330
  */
339
331
  expectEqualIgnoreCase(actualValue, expectedValue, customErrorMsg = '') {
340
332
  // @ts-ignore
341
- output.output.step(`I expect and ingore case "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`)
333
+ output.step(`I expect and ingore case "${JSON.stringify(actualValue)}" to equal "${JSON.stringify(expectedValue)}"`)
342
334
  return expect(actualValue, customErrorMsg).to.equalIgnoreCase(expectedValue)
343
335
  }
344
336
 
@@ -350,7 +342,7 @@ class ExpectHelper {
350
342
  */
351
343
  expectDeepMembers(actualValue, expectedValue, customErrorMsg = '') {
352
344
  // @ts-ignore
353
- output.output.step(
345
+ output.step(
354
346
  `I expect members of "${JSON.stringify(actualValue)}" and "${JSON.stringify(expectedValue)}" arrays are deeply equal`,
355
347
  )
356
348
  return expect(actualValue, customErrorMsg).to.have.deep.members(expectedValue)
@@ -364,7 +356,7 @@ class ExpectHelper {
364
356
  */
365
357
  expectDeepIncludeMembers(superset, set, customErrorMsg = '') {
366
358
  // @ts-ignore
367
- output.output.step(`I expect "${JSON.stringify(superset)}" array to be a superset of "${JSON.stringify(set)}" array`)
359
+ output.step(`I expect "${JSON.stringify(superset)}" array to be a superset of "${JSON.stringify(set)}" array`)
368
360
  return expect(superset, customErrorMsg).to.deep.include.members(set)
369
361
  }
370
362
 
@@ -377,7 +369,7 @@ class ExpectHelper {
377
369
  */
378
370
  expectDeepEqualExcluding(actualValue, expectedValue, fieldsToExclude, customErrorMsg = '') {
379
371
  // @ts-ignore
380
- output.output.step(
372
+ output.step(
381
373
  `I expect members of "${JSON.stringify(actualValue)}" and "${JSON.stringify(expectedValue)}" JSON objects are deeply equal excluding properties: ${JSON.stringify(fieldsToExclude)}`,
382
374
  )
383
375
  return expect(actualValue, customErrorMsg).excludingEvery(fieldsToExclude).to.deep.equal(expectedValue)
@@ -391,9 +383,9 @@ class ExpectHelper {
391
383
  */
392
384
  expectMatchesPattern(actualValue, expectedPattern, customErrorMsg = '') {
393
385
  // @ts-ignore
394
- output.output.step(`I expect "${JSON.stringify(actualValue)}" to match the ${JSON.stringify(expectedPattern)} pattern`)
386
+ output.step(`I expect "${JSON.stringify(actualValue)}" to match the ${JSON.stringify(expectedPattern)} pattern`)
395
387
  return expect(actualValue, customErrorMsg).to.matchPattern(expectedPattern)
396
388
  }
397
389
  }
398
390
 
399
- export default ExpectHelper
391
+ module.exports = ExpectHelper
@@ -1,11 +1,11 @@
1
- import assert from 'assert';
2
- import path from 'path';
3
- import fs from 'fs';
4
- import Helper from '@codeceptjs/helper';
5
- import { fileExists } from '../utils.js';
6
- import { fileIncludes } from '../assert/include.js';
7
- import { fileEquals } from '../assert/equal.js';
8
- import * as output from '../output.js';
1
+ const assert = require('assert')
2
+ const path = require('path')
3
+ const fs = require('fs')
4
+
5
+ const Helper = require('@codeceptjs/helper')
6
+ const { fileExists } = require('../utils')
7
+ const { fileIncludes } = require('../assert/include')
8
+ const { fileEquals } = require('../assert/equal')
9
9
 
10
10
  /**
11
11
  * Helper for testing filesystem.
@@ -30,15 +30,15 @@ import * as output from '../output.js';
30
30
  *
31
31
  * ## Methods
32
32
  */
33
- export default class FileSystem extends Helper {
34
- constructor(config) {
35
- super(config);
36
- this.dir = global.codecept_dir;
37
- this.file = '';
33
+ class FileSystem extends Helper {
34
+ constructor() {
35
+ super()
36
+ this.dir = global.codecept_dir
37
+ this.file = ''
38
38
  }
39
39
 
40
40
  _before() {
41
- output.output.debugSection('Dir', this.dir);
41
+ this.debugSection('Dir', this.dir)
42
42
  }
43
43
 
44
44
  /**
@@ -47,8 +47,8 @@ export default class FileSystem extends Helper {
47
47
  * @param {string} openPath
48
48
  */
49
49
  amInPath(openPath) {
50
- this.dir = path.join(global.codecept_dir, openPath);
51
- output.output.debugSection('Dir', this.dir);
50
+ this.dir = path.join(global.codecept_dir, openPath)
51
+ this.debugSection('Dir', this.dir)
52
52
  }
53
53
 
54
54
  /**
@@ -57,7 +57,7 @@ export default class FileSystem extends Helper {
57
57
  * @param {string} text
58
58
  */
59
59
  writeToFile(name, text) {
60
- fs.writeFileSync(path.join(this.dir, name), text);
60
+ fs.writeFileSync(path.join(this.dir, name), text)
61
61
  }
62
62
 
63
63
  /**
@@ -65,9 +65,9 @@ export default class FileSystem extends Helper {
65
65
  * @param {string} name
66
66
  */
67
67
  seeFile(name) {
68
- this.file = path.join(this.dir, name);
69
- output.output.debugSection('File', this.file);
70
- assert.ok(fileExists(this.file), `File ${name} not found in ${this.dir}`);
68
+ this.file = path.join(this.dir, name)
69
+ this.debugSection('File', this.file)
70
+ assert.ok(fileExists(this.file), `File ${name} not found in ${this.dir}`)
71
71
  }
72
72
 
73
73
  /**
@@ -83,31 +83,31 @@ export default class FileSystem extends Helper {
83
83
  * @param {number} [sec=1] seconds to wait
84
84
  */
85
85
  async waitForFile(name, sec = 1) {
86
- if (sec === 0) assert.fail('Use `seeFile` instead of waiting 0 seconds!');
87
- const waitTimeout = sec * 1000;
88
- this.file = path.join(this.dir, name);
89
- output.output.debugSection('File', this.file);
86
+ if (sec === 0) assert.fail('Use `seeFile` instead of waiting 0 seconds!')
87
+ const waitTimeout = sec * 1000
88
+ this.file = path.join(this.dir, name)
89
+ this.debugSection('File', this.file)
90
90
  return isFileExists(this.file, waitTimeout).catch(() => {
91
- throw new Error(`file (${name}) still not present in directory ${this.dir} after ${waitTimeout / 1000} sec`);
92
- });
91
+ throw new Error(`file (${name}) still not present in directory ${this.dir} after ${waitTimeout / 1000} sec`)
92
+ })
93
93
  }
94
94
 
95
95
  /**
96
- * Checks that file with a name including given text exists in the current directory.
97
- *
98
- *```js
99
- * I.handleDownloads();
100
- * I.click('Download as PDF');
101
- * I.amInPath('output/downloads');
102
- * I.seeFileNameMatching('.pdf');
103
- * ```
104
- * @param {string} text
105
- */
96
+ * Checks that file with a name including given text exists in the current directory.
97
+ *
98
+ *```js
99
+ * I.handleDownloads();
100
+ * I.click('Download as PDF');
101
+ * I.amInPath('output/downloads');
102
+ * I.seeFileNameMatching('.pdf');
103
+ * ```
104
+ * @param {string} text
105
+ */
106
106
  seeFileNameMatching(text) {
107
107
  assert.ok(
108
- this.grabFileNames().some(file => file.includes(text)),
108
+ this.grabFileNames().some((file) => file.includes(text)),
109
109
  `File name which contains ${text} not found in ${this.dir}`,
110
- );
110
+ )
111
111
  }
112
112
 
113
113
  /**
@@ -116,8 +116,8 @@ export default class FileSystem extends Helper {
116
116
  * @param {string} [encoding='utf8']
117
117
  */
118
118
  seeInThisFile(text, encoding = 'utf8') {
119
- const content = getFileContents(this.file, encoding);
120
- fileIncludes(this.file).assert(text, content);
119
+ const content = getFileContents(this.file, encoding)
120
+ fileIncludes(this.file).assert(text, content)
121
121
  }
122
122
 
123
123
  /**
@@ -126,8 +126,8 @@ export default class FileSystem extends Helper {
126
126
  * @param {string} [encoding='utf8']
127
127
  */
128
128
  dontSeeInThisFile(text, encoding = 'utf8') {
129
- const content = getFileContents(this.file, encoding);
130
- fileIncludes(this.file).negate(text, content);
129
+ const content = getFileContents(this.file, encoding)
130
+ fileIncludes(this.file).negate(text, content)
131
131
  }
132
132
 
133
133
  /**
@@ -136,8 +136,8 @@ export default class FileSystem extends Helper {
136
136
  * @param {string} [encoding='utf8']
137
137
  */
138
138
  seeFileContentsEqual(text, encoding = 'utf8') {
139
- const content = getFileContents(this.file, encoding);
140
- fileEquals(this.file).assert(text, content);
139
+ const content = getFileContents(this.file, encoding)
140
+ fileEquals(this.file).assert(text, content)
141
141
  }
142
142
 
143
143
  /**
@@ -147,11 +147,11 @@ export default class FileSystem extends Helper {
147
147
  * @param {string} [encodingReference='utf8']
148
148
  */
149
149
  seeFileContentsEqualReferenceFile(pathToReferenceFile, encoding = 'utf8', encodingReference = '') {
150
- const content = getFileContents(this.file, encoding);
151
- assert.ok(fileExists(pathToReferenceFile), `Reference file ${pathToReferenceFile} not found.`);
152
- encodingReference = encodingReference || encoding;
153
- const expectedContent = getFileContents(pathToReferenceFile, encodingReference);
154
- fileEquals(this.file).assert(expectedContent, content);
150
+ const content = getFileContents(this.file, encoding)
151
+ assert.ok(fileExists(pathToReferenceFile), `Reference file ${pathToReferenceFile} not found.`)
152
+ encodingReference = encodingReference || encoding
153
+ const expectedContent = getFileContents(pathToReferenceFile, encodingReference)
154
+ fileEquals(this.file).assert(expectedContent, content)
155
155
  }
156
156
 
157
157
  /**
@@ -160,26 +160,27 @@ export default class FileSystem extends Helper {
160
160
  * @param {string} [encoding='utf8']
161
161
  */
162
162
  dontSeeFileContentsEqual(text, encoding = 'utf8') {
163
- const content = getFileContents(this.file, encoding);
164
- fileEquals(this.file).negate(text, content);
163
+ const content = getFileContents(this.file, encoding)
164
+ fileEquals(this.file).negate(text, content)
165
165
  }
166
166
 
167
167
  /**
168
- * Returns file names in current directory.
169
- *
170
- * ```js
171
- * I.handleDownloads();
172
- * I.click('Download Files');
173
- * I.amInPath('output/downloads');
174
- * const downloadedFileNames = I.grabFileNames();
175
- * ```
176
- */
168
+ * Returns file names in current directory.
169
+ *
170
+ * ```js
171
+ * I.handleDownloads();
172
+ * I.click('Download Files');
173
+ * I.amInPath('output/downloads');
174
+ * const downloadedFileNames = I.grabFileNames();
175
+ * ```
176
+ */
177
177
  grabFileNames() {
178
- return fs.readdirSync(this.dir)
179
- .filter(item => !fs.lstatSync(path.join(this.dir, item)).isDirectory());
178
+ return fs.readdirSync(this.dir).filter((item) => !fs.lstatSync(path.join(this.dir, item)).isDirectory())
180
179
  }
181
180
  }
182
181
 
182
+ module.exports = FileSystem
183
+
183
184
  /**
184
185
  * @param {string} file
185
186
  * @param {string} [encoding='utf8']
@@ -187,9 +188,9 @@ export default class FileSystem extends Helper {
187
188
  * @returns {string}
188
189
  */
189
190
  function getFileContents(file, encoding = 'utf8') {
190
- if (!file) assert.fail('No files were opened, please use seeFile action');
191
- if (encoding === '') assert.fail('Encoding is an empty string, please set a valid encoding');
192
- return fs.readFileSync(file, encoding);
191
+ if (!file) assert.fail('No files were opened, please use seeFile action')
192
+ if (encoding === '') assert.fail('Encoding is an empty string, please set a valid encoding')
193
+ return fs.readFileSync(file, encoding)
193
194
  }
194
195
 
195
196
  /**
@@ -201,26 +202,26 @@ function getFileContents(file, encoding = 'utf8') {
201
202
  function isFileExists(file, timeout) {
202
203
  return new Promise((resolve, reject) => {
203
204
  const timer = setTimeout(() => {
204
- watcher.close();
205
- reject(new Error('File did not exists and was not created during the timeout.'));
206
- }, timeout);
205
+ watcher.close()
206
+ reject(new Error('File did not exists and was not created during the timeout.'))
207
+ }, timeout)
207
208
 
208
- const dir = path.dirname(file);
209
- const basename = path.basename(file);
209
+ const dir = path.dirname(file)
210
+ const basename = path.basename(file)
210
211
  const watcher = fs.watch(dir, (eventType, filename) => {
211
212
  if (eventType === 'rename' && filename === basename) {
212
- clearTimeout(timer);
213
- watcher.close();
214
- resolve();
213
+ clearTimeout(timer)
214
+ watcher.close()
215
+ resolve()
215
216
  }
216
- });
217
+ })
217
218
 
218
219
  fs.access(file, fs.constants.R_OK, (err) => {
219
220
  if (!err) {
220
- clearTimeout(timer);
221
- watcher.close();
222
- resolve();
221
+ clearTimeout(timer)
222
+ watcher.close()
223
+ resolve()
223
224
  }
224
- });
225
- });
225
+ })
226
+ })
226
227
  }