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