codeceptjs 4.0.0-beta.4 → 4.0.0-beta.6.esm-aria
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -119
- package/bin/codecept.js +53 -54
- package/docs/webapi/clearCookie.mustache +1 -1
- package/lib/actor.js +70 -102
- package/lib/ai.js +131 -121
- package/lib/assert/empty.js +11 -12
- package/lib/assert/equal.js +16 -21
- package/lib/assert/error.js +2 -2
- package/lib/assert/include.js +11 -15
- package/lib/assert/throws.js +3 -5
- package/lib/assert/truth.js +10 -7
- package/lib/assert.js +18 -18
- package/lib/codecept.js +112 -101
- package/lib/colorUtils.js +48 -50
- package/lib/command/check.js +206 -0
- package/lib/command/configMigrate.js +13 -14
- package/lib/command/definitions.js +24 -36
- package/lib/command/dryRun.js +16 -16
- package/lib/command/generate.js +38 -39
- package/lib/command/gherkin/init.js +36 -38
- package/lib/command/gherkin/snippets.js +76 -74
- package/lib/command/gherkin/steps.js +21 -18
- package/lib/command/info.js +49 -15
- package/lib/command/init.js +41 -37
- package/lib/command/interactive.js +22 -13
- package/lib/command/list.js +11 -10
- package/lib/command/run-multiple/chunk.js +50 -47
- package/lib/command/run-multiple/collection.js +5 -5
- package/lib/command/run-multiple/run.js +3 -3
- package/lib/command/run-multiple.js +27 -47
- package/lib/command/run-rerun.js +6 -7
- package/lib/command/run-workers.js +15 -66
- package/lib/command/run.js +8 -8
- package/lib/command/utils.js +22 -21
- package/lib/command/workers/runTests.js +131 -241
- package/lib/config.js +111 -49
- package/lib/container.js +589 -244
- package/lib/data/context.js +16 -18
- package/lib/data/dataScenarioConfig.js +9 -9
- package/lib/data/dataTableArgument.js +7 -7
- package/lib/data/table.js +6 -12
- package/lib/effects.js +307 -0
- package/lib/els.js +160 -0
- package/lib/event.js +24 -19
- package/lib/globals.js +141 -0
- package/lib/heal.js +89 -81
- package/lib/helper/AI.js +3 -2
- package/lib/helper/ApiDataFactory.js +19 -19
- package/lib/helper/Appium.js +47 -51
- package/lib/helper/FileSystem.js +35 -15
- package/lib/helper/GraphQL.js +1 -1
- package/lib/helper/GraphQLDataFactory.js +4 -4
- package/lib/helper/JSONResponse.js +72 -45
- package/lib/helper/Mochawesome.js +14 -11
- package/lib/helper/Playwright.js +832 -434
- package/lib/helper/Puppeteer.js +393 -292
- package/lib/helper/REST.js +32 -27
- package/lib/helper/WebDriver.js +320 -219
- package/lib/helper/errors/ConnectionRefused.js +6 -6
- package/lib/helper/errors/ElementAssertion.js +11 -16
- package/lib/helper/errors/ElementNotFound.js +5 -9
- package/lib/helper/errors/RemoteBrowserConnectionRefused.js +5 -5
- package/lib/helper/extras/Console.js +11 -11
- package/lib/helper/extras/PlaywrightLocator.js +110 -0
- package/lib/helper/extras/PlaywrightPropEngine.js +18 -18
- package/lib/helper/extras/PlaywrightRestartOpts.js +23 -23
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/extras/React.js +29 -30
- package/lib/helper/network/actions.js +33 -48
- package/lib/helper/network/utils.js +76 -83
- package/lib/helper/scripts/blurElement.js +6 -6
- package/lib/helper/scripts/focusElement.js +6 -6
- package/lib/helper/scripts/highlightElement.js +9 -9
- package/lib/helper/scripts/isElementClickable.js +34 -34
- package/lib/helper.js +2 -1
- package/lib/history.js +23 -20
- package/lib/hooks.js +10 -10
- package/lib/html.js +90 -100
- package/lib/index.js +48 -21
- package/lib/listener/config.js +8 -9
- package/lib/listener/emptyRun.js +54 -0
- package/lib/listener/exit.js +10 -12
- package/lib/listener/{retry.js → globalRetry.js} +10 -10
- package/lib/listener/globalTimeout.js +166 -0
- package/lib/listener/helpers.js +43 -24
- package/lib/listener/mocha.js +4 -5
- package/lib/listener/result.js +11 -0
- package/lib/listener/steps.js +26 -23
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +213 -192
- package/lib/mocha/asyncWrapper.js +264 -0
- package/lib/mocha/bdd.js +167 -0
- package/lib/mocha/cli.js +341 -0
- package/lib/mocha/factory.js +160 -0
- package/lib/{interfaces → mocha}/featureConfig.js +33 -13
- package/lib/{interfaces → mocha}/gherkin.js +75 -45
- package/lib/mocha/hooks.js +121 -0
- package/lib/mocha/index.js +21 -0
- package/lib/mocha/inject.js +46 -0
- package/lib/{interfaces → mocha}/scenarioConfig.js +32 -8
- package/lib/mocha/suite.js +89 -0
- package/lib/mocha/test.js +178 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +229 -0
- package/lib/output.js +86 -64
- package/lib/parser.js +44 -44
- package/lib/pause.js +160 -139
- package/lib/plugin/analyze.js +403 -0
- package/lib/plugin/{autoLogin.js → auth.js} +137 -43
- package/lib/plugin/autoDelay.js +19 -15
- package/lib/plugin/coverage.js +22 -27
- package/lib/plugin/customLocator.js +5 -5
- package/lib/plugin/customReporter.js +53 -0
- package/lib/plugin/heal.js +49 -17
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/pauseOnFail.js +4 -3
- package/lib/plugin/retryFailedStep.js +60 -19
- package/lib/plugin/screenshotOnFail.js +80 -83
- package/lib/plugin/stepByStepReport.js +70 -31
- package/lib/plugin/stepTimeout.js +7 -13
- package/lib/plugin/subtitles.js +10 -9
- package/lib/recorder.js +167 -126
- package/lib/rerun.js +94 -50
- package/lib/result.js +161 -0
- package/lib/secret.js +18 -17
- package/lib/session.js +95 -89
- package/lib/step/base.js +239 -0
- package/lib/step/comment.js +10 -0
- package/lib/step/config.js +50 -0
- package/lib/step/func.js +46 -0
- package/lib/step/helper.js +50 -0
- package/lib/step/meta.js +99 -0
- package/lib/step/record.js +74 -0
- package/lib/step/retry.js +11 -0
- package/lib/step/section.js +55 -0
- package/lib/step.js +18 -332
- package/lib/steps.js +54 -0
- package/lib/store.js +37 -5
- package/lib/template/heal.js +2 -11
- package/lib/timeout.js +60 -0
- package/lib/transform.js +8 -8
- package/lib/translation.js +32 -18
- package/lib/utils.js +354 -250
- package/lib/workerStorage.js +16 -16
- package/lib/workers.js +366 -282
- package/package.json +107 -95
- package/translations/de-DE.js +5 -4
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +23 -9
- package/translations/it-IT.js +5 -4
- package/translations/ja-JP.js +5 -4
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +5 -4
- package/translations/pt-BR.js +5 -4
- package/translations/ru-RU.js +5 -4
- package/translations/utils.js +18 -0
- package/translations/zh-CN.js +5 -4
- package/translations/zh-TW.js +5 -4
- package/typings/index.d.ts +177 -186
- package/typings/promiseBasedTypes.d.ts +3573 -5941
- package/typings/types.d.ts +4042 -6370
- package/lib/cli.js +0 -256
- package/lib/helper/ExpectHelper.js +0 -391
- package/lib/helper/Nightmare.js +0 -1504
- package/lib/helper/Protractor.js +0 -1863
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/helper/TestCafe.js +0 -1414
- package/lib/helper/clientscripts/nightmare.js +0 -213
- package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -43
- package/lib/helper/testcafe/testControllerHolder.js +0 -42
- package/lib/helper/testcafe/testcafe-utils.js +0 -62
- package/lib/interfaces/bdd.js +0 -81
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -113
- package/lib/plugin/allure.js +0 -15
- package/lib/plugin/commentStep.js +0 -136
- package/lib/plugin/debugErrors.js +0 -67
- package/lib/plugin/eachElement.js +0 -127
- package/lib/plugin/fakerTransform.js +0 -49
- package/lib/plugin/retryTo.js +0 -127
- package/lib/plugin/selenoid.js +0 -384
- package/lib/plugin/standardActingHelpers.js +0 -3
- package/lib/plugin/tryTo.js +0 -115
- package/lib/plugin/wdio.js +0 -249
- package/lib/scenario.js +0 -224
- package/lib/ui.js +0 -236
- package/lib/within.js +0 -70
package/lib/plugin/wdio.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
const debug = require('debug')('codeceptjs:plugin:wdio')
|
|
2
|
-
|
|
3
|
-
const container = require('../container')
|
|
4
|
-
const mainConfig = require('../config')
|
|
5
|
-
const recorder = require('../recorder')
|
|
6
|
-
const event = require('../event')
|
|
7
|
-
const output = require('../output')
|
|
8
|
-
|
|
9
|
-
const defaultConfig = {
|
|
10
|
-
services: [],
|
|
11
|
-
capabilities: {},
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let restartsSession
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Webdriverio services runner.
|
|
18
|
-
*
|
|
19
|
-
* This plugin allows to run webdriverio services like:
|
|
20
|
-
*
|
|
21
|
-
* * selenium-standalone
|
|
22
|
-
* * sauce
|
|
23
|
-
* * testingbot
|
|
24
|
-
* * browserstack
|
|
25
|
-
* * appium
|
|
26
|
-
*
|
|
27
|
-
* A complete list of all available services can be found on [webdriverio website](https://webdriver.io).
|
|
28
|
-
*
|
|
29
|
-
* #### Setup
|
|
30
|
-
*
|
|
31
|
-
* 1. Install a webdriverio service
|
|
32
|
-
* 2. Enable `wdio` plugin in config
|
|
33
|
-
* 3. Add service name to `services` array inside wdio plugin config.
|
|
34
|
-
*
|
|
35
|
-
* See examples below:
|
|
36
|
-
*
|
|
37
|
-
* #### Selenium Standalone Service
|
|
38
|
-
*
|
|
39
|
-
* Install ` @wdio/selenium-standalone-service` package, as [described here](https://webdriver.io/docs/selenium-standalone-service.html).
|
|
40
|
-
* It is important to make sure it is compatible with current webdriverio version.
|
|
41
|
-
*
|
|
42
|
-
* Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
|
|
43
|
-
*
|
|
44
|
-
* ```js
|
|
45
|
-
* plugins: {
|
|
46
|
-
* wdio: {
|
|
47
|
-
* enabled: true,
|
|
48
|
-
* services: ['selenium-standalone']
|
|
49
|
-
* // additional config for service can be passed here
|
|
50
|
-
* }
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* #### Sauce Service
|
|
56
|
-
*
|
|
57
|
-
* Install `@wdio/sauce-service` package, as [described here](https://webdriver.io/docs/sauce-service.html).
|
|
58
|
-
* It is important to make sure it is compatible with current webdriverio version.
|
|
59
|
-
*
|
|
60
|
-
* Enable `wdio` plugin in plugins list and add `sauce` service:
|
|
61
|
-
*
|
|
62
|
-
* ```js
|
|
63
|
-
* plugins: {
|
|
64
|
-
* wdio: {
|
|
65
|
-
* enabled: true,
|
|
66
|
-
* services: ['sauce'],
|
|
67
|
-
* user: ... ,// saucelabs username
|
|
68
|
-
* key: ... // saucelabs api key
|
|
69
|
-
* // additional config, from sauce service
|
|
70
|
-
* }
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* ---
|
|
75
|
-
*
|
|
76
|
-
* In the same manner additional services from webdriverio can be installed, enabled, and configured.
|
|
77
|
-
*
|
|
78
|
-
* #### Configuration
|
|
79
|
-
*
|
|
80
|
-
* * `services` - list of enabled services
|
|
81
|
-
* * ... - additional configuration passed into services.
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
module.exports = (config) => {
|
|
85
|
-
// Keep initial configs to pass as options to wdio services
|
|
86
|
-
const wdioOptions = { ...config }
|
|
87
|
-
const webDriver = container.helpers('WebDriver')
|
|
88
|
-
if (webDriver) {
|
|
89
|
-
config = Object.assign(webDriver.options, config)
|
|
90
|
-
restartsSession = !!config.restart
|
|
91
|
-
}
|
|
92
|
-
config = Object.assign(defaultConfig, config)
|
|
93
|
-
const seleniumInstallArgs = { ...config.seleniumInstallArgs }
|
|
94
|
-
const seleniumArgs = { ...config.seleniumArgs }
|
|
95
|
-
|
|
96
|
-
const services = []
|
|
97
|
-
const launchers = []
|
|
98
|
-
|
|
99
|
-
for (const name of config.services) {
|
|
100
|
-
const Service = safeRequire(`@wdio/${name.toLowerCase()}-service`)
|
|
101
|
-
if (Service) {
|
|
102
|
-
if (Service.launcher && typeof Service.launcher === 'function') {
|
|
103
|
-
const Launcher = Service.launcher
|
|
104
|
-
|
|
105
|
-
const options = {
|
|
106
|
-
logPath: global.output_dir,
|
|
107
|
-
installArgs: seleniumInstallArgs,
|
|
108
|
-
args: seleniumArgs,
|
|
109
|
-
...wdioOptions,
|
|
110
|
-
}
|
|
111
|
-
launchers.push(new Launcher(options, [config.capabilities], config))
|
|
112
|
-
}
|
|
113
|
-
if (typeof Service === 'function') {
|
|
114
|
-
services.push(new Service(config, config.capabilities))
|
|
115
|
-
}
|
|
116
|
-
continue
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
throw new Error(
|
|
120
|
-
`Couldn't initialize service ${name} from wdio plugin config.\nIt should be available either in '@wdio/${name.toLowerCase()}-service' package`,
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
debug(`services ${services}, launchers ${launchers}`)
|
|
125
|
-
|
|
126
|
-
recorder.startUnlessRunning()
|
|
127
|
-
|
|
128
|
-
for (const launcher of launchers) {
|
|
129
|
-
registerLauncher(launcher)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
for (const service of services) {
|
|
133
|
-
registerService(service)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function registerService(service) {
|
|
137
|
-
const name = service.constructor.name
|
|
138
|
-
if (service.beforeSession) {
|
|
139
|
-
event.dispatcher.on(event.all.before, () => {
|
|
140
|
-
recorder.add(`service ${name} all.before`, async () => {
|
|
141
|
-
await service.beforeSession(config, config.capabilities)
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (service.afterSession) {
|
|
147
|
-
event.dispatcher.on(event.all.result, (result) => {
|
|
148
|
-
recorder.add(`service ${name} all.after`, async () => {
|
|
149
|
-
await service.afterSession(result)
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (service.beforeSuite) {
|
|
155
|
-
event.dispatcher.on(event.suite.before, (suite) => {
|
|
156
|
-
debug(`suite started: ${suite.title}`)
|
|
157
|
-
recorder.add(`service ${name} suite.before`, () => service.beforeSuite(suite))
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (service.afterSuite) {
|
|
162
|
-
event.dispatcher.on(event.suite.after, (suite) => {
|
|
163
|
-
debug(`suite finished: ${suite.title}`)
|
|
164
|
-
recorder.add(`service ${name} suite.after`, () => service.afterSuite(suite))
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (service.beforeTest) {
|
|
169
|
-
event.dispatcher.on(event.test.started, async (test) => {
|
|
170
|
-
if (test.parent) {
|
|
171
|
-
test.parent.toString = () => test.parent.title
|
|
172
|
-
}
|
|
173
|
-
// test.parent = test.parent ? test.parent.title : null;
|
|
174
|
-
debug(`test started: ${test.title}`)
|
|
175
|
-
if (webDriver) {
|
|
176
|
-
global.browser = webDriver.browser
|
|
177
|
-
global.browser.config = Object.assign(mainConfig.get('test', 1), global.browser.config)
|
|
178
|
-
}
|
|
179
|
-
await service.beforeTest(test)
|
|
180
|
-
})
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (service.afterTest) {
|
|
184
|
-
event.dispatcher.on(event.test.finished, async (test) => {
|
|
185
|
-
debug(`test finished: ${test.title}`)
|
|
186
|
-
await service.afterTest(test)
|
|
187
|
-
})
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (restartsSession && service.before) {
|
|
191
|
-
event.dispatcher.on(event.test.started, () => service.before())
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (restartsSession && service.after) {
|
|
195
|
-
event.dispatcher.on(event.test.finished, () => service.after())
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!restartsSession && service.before) {
|
|
199
|
-
let initializedBrowser = false
|
|
200
|
-
event.dispatcher.on(event.test.started, async () => {
|
|
201
|
-
if (!initializedBrowser) {
|
|
202
|
-
await service.before()
|
|
203
|
-
initializedBrowser = true
|
|
204
|
-
}
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (!restartsSession && service.after) {
|
|
209
|
-
event.dispatcher.on(event.all.result, (result) => service.after(result))
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function registerLauncher(launcher) {
|
|
214
|
-
const name = launcher.constructor.name
|
|
215
|
-
if (launcher.onPrepare) {
|
|
216
|
-
event.dispatcher.on(event.all.before, () => {
|
|
217
|
-
recorder.add(`launcher ${name} start`, async () => {
|
|
218
|
-
// browserstack-service expects capabilities as array
|
|
219
|
-
if (launcher.constructor.name === 'BrowserstackLauncherService') {
|
|
220
|
-
await launcher.onPrepare(config, [config.capabilities])
|
|
221
|
-
} else {
|
|
222
|
-
await launcher.onPrepare(config, config.capabilities)
|
|
223
|
-
}
|
|
224
|
-
output.debug(`Started ${name}`)
|
|
225
|
-
})
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (launcher.onComplete) {
|
|
230
|
-
event.dispatcher.on(event.all.after, () => {
|
|
231
|
-
recorder.add(`launcher ${name} start`, async () => {
|
|
232
|
-
await launcher.onComplete(process.exitCode, config, config.capabilities)
|
|
233
|
-
output.debug(`Stopped ${name}`)
|
|
234
|
-
})
|
|
235
|
-
})
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function safeRequire(name) {
|
|
241
|
-
try {
|
|
242
|
-
return require(name)
|
|
243
|
-
} catch (e) {
|
|
244
|
-
if (!e.message.match(`Cannot find module '${name}'`)) {
|
|
245
|
-
throw new Error(`Couldn't initialise "${name}".\n${e.stack}`)
|
|
246
|
-
}
|
|
247
|
-
return null
|
|
248
|
-
}
|
|
249
|
-
}
|
package/lib/scenario.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
const promiseRetry = require('promise-retry');
|
|
2
|
-
const event = require('./event');
|
|
3
|
-
const recorder = require('./recorder');
|
|
4
|
-
const assertThrown = require('./assert/throws');
|
|
5
|
-
const { ucfirst, isAsyncFunction } = require('./utils');
|
|
6
|
-
const parser = require('./parser');
|
|
7
|
-
|
|
8
|
-
const injectHook = function (inject, suite) {
|
|
9
|
-
try {
|
|
10
|
-
inject();
|
|
11
|
-
} catch (err) {
|
|
12
|
-
recorder.throw(err);
|
|
13
|
-
}
|
|
14
|
-
recorder.catch((err) => {
|
|
15
|
-
event.emit(event.test.failed, suite, err);
|
|
16
|
-
throw err;
|
|
17
|
-
});
|
|
18
|
-
return recorder.promise();
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function makeDoneCallableOnce(done) {
|
|
22
|
-
let called = false;
|
|
23
|
-
return function (err) {
|
|
24
|
-
if (called) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
called = true;
|
|
28
|
-
return done(err);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Wraps test function, injects support objects from container,
|
|
33
|
-
* starts promise chain with recorder, performs before/after hooks
|
|
34
|
-
* through event system.
|
|
35
|
-
*/
|
|
36
|
-
module.exports.test = (test) => {
|
|
37
|
-
const testFn = test.fn;
|
|
38
|
-
if (!testFn) {
|
|
39
|
-
return test;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
test.steps = [];
|
|
43
|
-
test.timeout(0);
|
|
44
|
-
test.async = true;
|
|
45
|
-
|
|
46
|
-
test.fn = function (done) {
|
|
47
|
-
const doneFn = makeDoneCallableOnce(done);
|
|
48
|
-
recorder.errHandler((err) => {
|
|
49
|
-
recorder.session.start('teardown');
|
|
50
|
-
recorder.cleanAsyncErr();
|
|
51
|
-
if (test.throws) {
|
|
52
|
-
// check that test should actually fail
|
|
53
|
-
try {
|
|
54
|
-
assertThrown(err, test.throws);
|
|
55
|
-
event.emit(event.test.passed, test);
|
|
56
|
-
event.emit(event.test.finished, test);
|
|
57
|
-
recorder.add(doneFn);
|
|
58
|
-
return;
|
|
59
|
-
} catch (newErr) {
|
|
60
|
-
err = newErr;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
event.emit(event.test.failed, test, err);
|
|
64
|
-
event.emit(event.test.finished, test);
|
|
65
|
-
recorder.add(() => doneFn(err));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (isAsyncFunction(testFn)) {
|
|
69
|
-
event.emit(event.test.started, test);
|
|
70
|
-
testFn
|
|
71
|
-
.call(test, getInjectedArguments(testFn, test))
|
|
72
|
-
.then(() => {
|
|
73
|
-
recorder.add('fire test.passed', () => {
|
|
74
|
-
event.emit(event.test.passed, test);
|
|
75
|
-
event.emit(event.test.finished, test);
|
|
76
|
-
});
|
|
77
|
-
recorder.add('finish test', doneFn);
|
|
78
|
-
})
|
|
79
|
-
.catch((err) => {
|
|
80
|
-
recorder.throw(err);
|
|
81
|
-
})
|
|
82
|
-
.finally(() => {
|
|
83
|
-
recorder.catch();
|
|
84
|
-
});
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
event.emit(event.test.started, test);
|
|
90
|
-
testFn.call(test, getInjectedArguments(testFn, test));
|
|
91
|
-
} catch (err) {
|
|
92
|
-
recorder.throw(err);
|
|
93
|
-
} finally {
|
|
94
|
-
recorder.add('fire test.passed', () => {
|
|
95
|
-
event.emit(event.test.passed, test);
|
|
96
|
-
event.emit(event.test.finished, test);
|
|
97
|
-
});
|
|
98
|
-
recorder.add('finish test', doneFn);
|
|
99
|
-
recorder.catch();
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
return test;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Injects arguments to function from controller
|
|
107
|
-
*/
|
|
108
|
-
module.exports.injected = function (fn, suite, hookName) {
|
|
109
|
-
return function (done) {
|
|
110
|
-
const doneFn = makeDoneCallableOnce(done);
|
|
111
|
-
const errHandler = (err) => {
|
|
112
|
-
recorder.session.start('teardown');
|
|
113
|
-
recorder.cleanAsyncErr();
|
|
114
|
-
event.emit(event.test.failed, suite, err);
|
|
115
|
-
if (hookName === 'after') event.emit(event.test.after, suite);
|
|
116
|
-
if (hookName === 'afterSuite') event.emit(event.suite.after, suite);
|
|
117
|
-
recorder.add(() => doneFn(err));
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
recorder.errHandler((err) => {
|
|
121
|
-
errHandler(err);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (!fn) throw new Error('fn is not defined');
|
|
125
|
-
|
|
126
|
-
event.emit(event.hook.started, suite);
|
|
127
|
-
|
|
128
|
-
this.test.body = fn.toString();
|
|
129
|
-
|
|
130
|
-
if (!recorder.isRunning()) {
|
|
131
|
-
recorder.errHandler((err) => {
|
|
132
|
-
errHandler(err);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const opts = suite.opts || {};
|
|
137
|
-
const retries = opts[`retry${ucfirst(hookName)}`] || 0;
|
|
138
|
-
|
|
139
|
-
promiseRetry(
|
|
140
|
-
async (retry, number) => {
|
|
141
|
-
try {
|
|
142
|
-
recorder.startUnlessRunning();
|
|
143
|
-
await fn.call(this, getInjectedArguments(fn));
|
|
144
|
-
await recorder.promise().catch((err) => retry(err));
|
|
145
|
-
} catch (err) {
|
|
146
|
-
retry(err);
|
|
147
|
-
} finally {
|
|
148
|
-
if (number < retries) {
|
|
149
|
-
recorder.stop();
|
|
150
|
-
recorder.start();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
{ retries },
|
|
155
|
-
)
|
|
156
|
-
.then(() => {
|
|
157
|
-
recorder.add('fire hook.passed', () => event.emit(event.hook.passed, suite));
|
|
158
|
-
recorder.add(`finish ${hookName} hook`, doneFn);
|
|
159
|
-
recorder.catch();
|
|
160
|
-
})
|
|
161
|
-
.catch((e) => {
|
|
162
|
-
recorder.throw(e);
|
|
163
|
-
recorder.catch((e) => {
|
|
164
|
-
const err = recorder.getAsyncErr() === null ? e : recorder.getAsyncErr();
|
|
165
|
-
errHandler(err);
|
|
166
|
-
});
|
|
167
|
-
recorder.add('fire hook.failed', () => event.emit(event.hook.failed, suite, e));
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Starts promise chain, so helpers could enqueue their hooks
|
|
174
|
-
*/
|
|
175
|
-
module.exports.setup = function (suite) {
|
|
176
|
-
return injectHook(() => {
|
|
177
|
-
recorder.startUnlessRunning();
|
|
178
|
-
event.emit(event.test.before, suite && suite.ctx && suite.ctx.currentTest);
|
|
179
|
-
}, suite);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
module.exports.teardown = function (suite) {
|
|
183
|
-
return injectHook(() => {
|
|
184
|
-
recorder.startUnlessRunning();
|
|
185
|
-
event.emit(event.test.after, suite && suite.ctx && suite.ctx.currentTest);
|
|
186
|
-
}, suite);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
module.exports.suiteSetup = function (suite) {
|
|
190
|
-
return injectHook(() => {
|
|
191
|
-
recorder.startUnlessRunning();
|
|
192
|
-
event.emit(event.suite.before, suite);
|
|
193
|
-
}, suite);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
module.exports.suiteTeardown = function (suite) {
|
|
197
|
-
return injectHook(() => {
|
|
198
|
-
recorder.startUnlessRunning();
|
|
199
|
-
event.emit(event.suite.after, suite);
|
|
200
|
-
}, suite);
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const getInjectedArguments = (fn, test) => {
|
|
204
|
-
const container = require('./container');
|
|
205
|
-
const testArgs = {};
|
|
206
|
-
const params = parser.getParams(fn) || [];
|
|
207
|
-
const objects = container.support();
|
|
208
|
-
for (const key of params) {
|
|
209
|
-
testArgs[key] = {};
|
|
210
|
-
if (test && test.inject && test.inject[key]) {
|
|
211
|
-
// @FIX: need fix got inject
|
|
212
|
-
testArgs[key] = test.inject[key];
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (!objects[key]) {
|
|
216
|
-
throw new Error(`Object of type ${key} is not defined in container`);
|
|
217
|
-
}
|
|
218
|
-
testArgs[key] = container.support(key);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return testArgs;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
module.exports.getInjectedArguments = getInjectedArguments;
|
package/lib/ui.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
const escapeRe = require('escape-string-regexp');
|
|
2
|
-
const Suite = require('mocha/lib/suite');
|
|
3
|
-
const Test = require('mocha/lib/test');
|
|
4
|
-
|
|
5
|
-
const scenario = require('./scenario');
|
|
6
|
-
const ScenarioConfig = require('./interfaces/scenarioConfig');
|
|
7
|
-
const FeatureConfig = require('./interfaces/featureConfig');
|
|
8
|
-
const addDataContext = require('./data/context');
|
|
9
|
-
const container = require('./container');
|
|
10
|
-
|
|
11
|
-
const setContextTranslation = (context) => {
|
|
12
|
-
const contexts = container.translation().value('contexts');
|
|
13
|
-
|
|
14
|
-
if (contexts) {
|
|
15
|
-
for (const key of Object.keys(contexts)) {
|
|
16
|
-
if (context[key]) {
|
|
17
|
-
context[contexts[key]] = context[key];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Codecept-style interface:
|
|
25
|
-
*
|
|
26
|
-
* Feature('login');
|
|
27
|
-
*
|
|
28
|
-
* Scenario('login as regular user', ({I}) {
|
|
29
|
-
* I.fillField();
|
|
30
|
-
* I.click();
|
|
31
|
-
* I.see('Hello, '+data.login);
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* @param {Mocha.Suite} suite Root suite.
|
|
35
|
-
* @ignore
|
|
36
|
-
*/
|
|
37
|
-
module.exports = function (suite) {
|
|
38
|
-
const suites = [suite];
|
|
39
|
-
suite.timeout(0);
|
|
40
|
-
let afterAllHooks;
|
|
41
|
-
let afterEachHooks;
|
|
42
|
-
let afterAllHooksAreLoaded;
|
|
43
|
-
let afterEachHooksAreLoaded;
|
|
44
|
-
|
|
45
|
-
suite.on('pre-require', (context, file, mocha) => {
|
|
46
|
-
const common = require('mocha/lib/interfaces/common')(suites, context, mocha);
|
|
47
|
-
|
|
48
|
-
const addScenario = function (title, opts = {}, fn) {
|
|
49
|
-
const suite = suites[0];
|
|
50
|
-
|
|
51
|
-
if (typeof opts === 'function' && !fn) {
|
|
52
|
-
fn = opts;
|
|
53
|
-
opts = {};
|
|
54
|
-
}
|
|
55
|
-
if (suite.pending) {
|
|
56
|
-
fn = null;
|
|
57
|
-
}
|
|
58
|
-
const test = new Test(title, fn);
|
|
59
|
-
test.fullTitle = () => `${suite.title}: ${test.title}`;
|
|
60
|
-
|
|
61
|
-
test.tags = (suite.tags || []).concat(title.match(/(\@[a-zA-Z0-9-_]+)/g) || []); // match tags from title
|
|
62
|
-
test.file = file;
|
|
63
|
-
if (!test.inject) {
|
|
64
|
-
test.inject = {};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
suite.addTest(scenario.test(test));
|
|
68
|
-
if (opts.retries) test.retries(opts.retries);
|
|
69
|
-
if (opts.timeout) test.totalTimeout = opts.timeout;
|
|
70
|
-
test.opts = opts;
|
|
71
|
-
|
|
72
|
-
return new ScenarioConfig(test);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// create dispatcher
|
|
76
|
-
|
|
77
|
-
context.BeforeAll = common.before;
|
|
78
|
-
context.AfterAll = common.after;
|
|
79
|
-
|
|
80
|
-
context.run = mocha.options.delay && common.runWithSuite(suite);
|
|
81
|
-
/**
|
|
82
|
-
* Describe a "suite" with the given `title`
|
|
83
|
-
* and callback `fn` containing nested suites
|
|
84
|
-
* and/or tests.
|
|
85
|
-
* @global
|
|
86
|
-
* @param {string} title
|
|
87
|
-
* @param {Object<string, *>} [opts]
|
|
88
|
-
* @returns {FeatureConfig}
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
context.Feature = function (title, opts) {
|
|
92
|
-
if (suites.length > 1) {
|
|
93
|
-
suites.shift();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
afterAllHooks = [];
|
|
97
|
-
afterEachHooks = [];
|
|
98
|
-
afterAllHooksAreLoaded = false;
|
|
99
|
-
afterEachHooksAreLoaded = false;
|
|
100
|
-
|
|
101
|
-
const suite = Suite.create(suites[0], title);
|
|
102
|
-
if (!opts) opts = {};
|
|
103
|
-
suite.opts = opts;
|
|
104
|
-
suite.timeout(0);
|
|
105
|
-
|
|
106
|
-
if (opts.retries) suite.retries(opts.retries);
|
|
107
|
-
if (opts.timeout) suite.totalTimeout = opts.timeout;
|
|
108
|
-
|
|
109
|
-
suite.tags = title.match(/(\@[a-zA-Z0-9-_]+)/g) || []; // match tags from title
|
|
110
|
-
suite.file = file;
|
|
111
|
-
suite.fullTitle = () => `${suite.title}:`;
|
|
112
|
-
suites.unshift(suite);
|
|
113
|
-
suite.beforeEach('codeceptjs.before', () => scenario.setup(suite));
|
|
114
|
-
afterEachHooks.push(['finalize codeceptjs', () => scenario.teardown(suite)]);
|
|
115
|
-
|
|
116
|
-
suite.beforeAll('codeceptjs.beforeSuite', () => scenario.suiteSetup(suite));
|
|
117
|
-
afterAllHooks.push(['codeceptjs.afterSuite', () => scenario.suiteTeardown(suite)]);
|
|
118
|
-
|
|
119
|
-
if (opts.skipInfo && opts.skipInfo.skipped) {
|
|
120
|
-
suite.pending = true;
|
|
121
|
-
suite.opts = { ...suite.opts, skipInfo: opts.skipInfo };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return new FeatureConfig(suite);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Pending test suite.
|
|
129
|
-
* @global
|
|
130
|
-
* @kind constant
|
|
131
|
-
* @type {CodeceptJS.IFeature}
|
|
132
|
-
*/
|
|
133
|
-
context.xFeature = context.Feature.skip = function (title, opts) {
|
|
134
|
-
const skipInfo = {
|
|
135
|
-
skipped: true,
|
|
136
|
-
message: 'Skipped due to "skip" on Feature.',
|
|
137
|
-
};
|
|
138
|
-
return context.Feature(title, { ...opts, skipInfo });
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
context.BeforeSuite = function (fn) {
|
|
142
|
-
suites[0].beforeAll('BeforeSuite', scenario.injected(fn, suites[0], 'beforeSuite'));
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
context.AfterSuite = function (fn) {
|
|
146
|
-
afterAllHooks.unshift(['AfterSuite', scenario.injected(fn, suites[0], 'afterSuite')]);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
context.Background = context.Before = function (fn) {
|
|
150
|
-
suites[0].beforeEach('Before', scenario.injected(fn, suites[0], 'before'));
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
context.After = function (fn) {
|
|
154
|
-
afterEachHooks.unshift(['After', scenario.injected(fn, suites[0], 'after')]);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Describe a specification or test-case
|
|
159
|
-
* with the given `title` and callback `fn`
|
|
160
|
-
* acting as a thunk.
|
|
161
|
-
* @ignore
|
|
162
|
-
*/
|
|
163
|
-
context.Scenario = addScenario;
|
|
164
|
-
/**
|
|
165
|
-
* Exclusive test-case.
|
|
166
|
-
* @ignore
|
|
167
|
-
*/
|
|
168
|
-
context.Scenario.only = function (title, opts, fn) {
|
|
169
|
-
const reString = `^${escapeRe(`${suites[0].title}: ${title}`.replace(/( \| {.+})?$/g, ''))}`;
|
|
170
|
-
mocha.grep(new RegExp(reString));
|
|
171
|
-
process.env.SCENARIO_ONLY = true;
|
|
172
|
-
return addScenario(title, opts, fn);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Pending test case.
|
|
177
|
-
* @global
|
|
178
|
-
* @kind constant
|
|
179
|
-
* @type {CodeceptJS.IScenario}
|
|
180
|
-
*/
|
|
181
|
-
context.xScenario = context.Scenario.skip = function (title, opts = {}, fn) {
|
|
182
|
-
if (typeof opts === 'function' && !fn) {
|
|
183
|
-
opts = {};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return context.Scenario(title, opts);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Pending test case with message: 'Test not implemented!'.
|
|
191
|
-
* @global
|
|
192
|
-
* @kind constant
|
|
193
|
-
* @type {CodeceptJS.IScenario}
|
|
194
|
-
*/
|
|
195
|
-
context.Scenario.todo = function (title, opts = {}, fn) {
|
|
196
|
-
if (typeof opts === 'function' && !fn) {
|
|
197
|
-
fn = opts;
|
|
198
|
-
opts = {};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const skipInfo = {
|
|
202
|
-
message: 'Test not implemented!',
|
|
203
|
-
description: fn ? fn.toString() : '',
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
return context.Scenario(title, { ...opts, skipInfo });
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* For translation
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
setContextTranslation(context);
|
|
214
|
-
|
|
215
|
-
addDataContext(context);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
suite.on('post-require', () => {
|
|
219
|
-
/**
|
|
220
|
-
* load hooks from arrays to suite to prevent reordering
|
|
221
|
-
*/
|
|
222
|
-
if (!afterEachHooksAreLoaded && Array.isArray(afterEachHooks)) {
|
|
223
|
-
afterEachHooks.forEach((hook) => {
|
|
224
|
-
suites[0].afterEach(hook[0], hook[1]);
|
|
225
|
-
});
|
|
226
|
-
afterEachHooksAreLoaded = true;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (!afterAllHooksAreLoaded && Array.isArray(afterAllHooks)) {
|
|
230
|
-
afterAllHooks.forEach((hook) => {
|
|
231
|
-
suites[0].afterAll(hook[0], hook[1]);
|
|
232
|
-
});
|
|
233
|
-
afterAllHooksAreLoaded = true;
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
};
|