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
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { fork } from 'child_process'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import crypto from 'crypto'
|
|
4
|
+
import { fileURLToPath } from 'url'
|
|
5
|
+
|
|
6
|
+
import runHook from '../hooks.js'
|
|
7
|
+
import event from '../event.js'
|
|
8
|
+
import { createRuns } from './run-multiple/collection.js'
|
|
9
|
+
import { clearString, replaceValueDeep } from '../utils.js'
|
|
10
|
+
import { getConfig, getTestRoot, fail } from './utils.js'
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
13
|
+
const __dirname = path.dirname(__filename)
|
|
11
14
|
const runner = path.join(__dirname, '/../../bin/codecept')
|
|
12
15
|
let config
|
|
13
16
|
const childOpts = {}
|
|
14
|
-
const copyOptions = [
|
|
15
|
-
'override',
|
|
16
|
-
'steps',
|
|
17
|
-
'reporter',
|
|
18
|
-
'verbose',
|
|
19
|
-
'config',
|
|
20
|
-
'reporter-options',
|
|
21
|
-
'grep',
|
|
22
|
-
'fgrep',
|
|
23
|
-
'invert',
|
|
24
|
-
'debug',
|
|
25
|
-
'plugins',
|
|
26
|
-
'colors',
|
|
27
|
-
]
|
|
17
|
+
const copyOptions = ['override', 'steps', 'reporter', 'verbose', 'config', 'reporter-options', 'grep', 'fgrep', 'invert', 'debug', 'plugins', 'colors']
|
|
28
18
|
let overrides = {}
|
|
29
19
|
|
|
30
20
|
// codeceptjs run-multiple smoke:chrome regression:firefox - will launch smoke run in chrome and regression in firefox
|
|
@@ -37,7 +27,7 @@ let subprocessCount = 0
|
|
|
37
27
|
let totalSubprocessCount = 0
|
|
38
28
|
let processesDone
|
|
39
29
|
|
|
40
|
-
|
|
30
|
+
export default async function (selectedRuns, options) {
|
|
41
31
|
// registering options globally to use in config
|
|
42
32
|
if (options.profile) {
|
|
43
33
|
process.env.profile = options.profile
|
|
@@ -49,8 +39,8 @@ module.exports = async function (selectedRuns, options) {
|
|
|
49
39
|
|
|
50
40
|
// copy opts to run
|
|
51
41
|
Object.keys(options)
|
|
52
|
-
.filter(
|
|
53
|
-
.forEach(
|
|
42
|
+
.filter(key => copyOptions.indexOf(key) > -1)
|
|
43
|
+
.forEach(key => {
|
|
54
44
|
childOpts[key] = options[key]
|
|
55
45
|
})
|
|
56
46
|
|
|
@@ -62,7 +52,7 @@ module.exports = async function (selectedRuns, options) {
|
|
|
62
52
|
}
|
|
63
53
|
|
|
64
54
|
config = {
|
|
65
|
-
...getConfig(configFile),
|
|
55
|
+
...(await getConfig(configFile)),
|
|
66
56
|
...overrides,
|
|
67
57
|
}
|
|
68
58
|
|
|
@@ -96,12 +86,12 @@ module.exports = async function (selectedRuns, options) {
|
|
|
96
86
|
config.gherkin.features = ''
|
|
97
87
|
}
|
|
98
88
|
|
|
99
|
-
const childProcessesPromise = new Promise(
|
|
89
|
+
const childProcessesPromise = new Promise(resolve => {
|
|
100
90
|
processesDone = resolve
|
|
101
91
|
})
|
|
102
92
|
|
|
103
93
|
const runsToExecute = []
|
|
104
|
-
|
|
94
|
+
createRuns(selectedRuns, config).forEach(run => {
|
|
105
95
|
const runName = run.getOriginalName() || run.getName()
|
|
106
96
|
const runConfig = run.getConfig()
|
|
107
97
|
runsToExecute.push(executeRun(runName, runConfig))
|
|
@@ -113,7 +103,7 @@ module.exports = async function (selectedRuns, options) {
|
|
|
113
103
|
|
|
114
104
|
// Execute all forks
|
|
115
105
|
totalSubprocessCount = runsToExecute.length
|
|
116
|
-
runsToExecute.forEach(
|
|
106
|
+
runsToExecute.forEach(runToExecute => runToExecute.call(this))
|
|
117
107
|
|
|
118
108
|
return childProcessesPromise.then(async () => {
|
|
119
109
|
// fire hook
|
|
@@ -149,11 +139,7 @@ function executeRun(runName, runConfig) {
|
|
|
149
139
|
// tweaking default output directories and for mochawesome
|
|
150
140
|
overriddenConfig = replaceValueDeep(overriddenConfig, 'output', path.join(config.output, outputDir))
|
|
151
141
|
overriddenConfig = replaceValueDeep(overriddenConfig, 'reportDir', path.join(config.output, outputDir))
|
|
152
|
-
overriddenConfig = replaceValueDeep(
|
|
153
|
-
overriddenConfig,
|
|
154
|
-
'mochaFile',
|
|
155
|
-
path.join(config.output, outputDir, `${browserName}_report.xml`),
|
|
156
|
-
)
|
|
142
|
+
overriddenConfig = replaceValueDeep(overriddenConfig, 'mochaFile', path.join(config.output, outputDir, `${browserName}_report.xml`))
|
|
157
143
|
|
|
158
144
|
// override tests configuration
|
|
159
145
|
if (overriddenConfig.tests) {
|
|
@@ -165,15 +151,9 @@ function executeRun(runName, runConfig) {
|
|
|
165
151
|
}
|
|
166
152
|
|
|
167
153
|
// override grep param and collect all params
|
|
168
|
-
const params = [
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
`${runId++}.${runName}:${browserName}`,
|
|
172
|
-
'--override',
|
|
173
|
-
JSON.stringify(overriddenConfig),
|
|
174
|
-
]
|
|
175
|
-
|
|
176
|
-
Object.keys(childOpts).forEach((key) => {
|
|
154
|
+
const params = ['run', '--child', `${runId++}.${runName}:${browserName}`, '--override', JSON.stringify(overriddenConfig)]
|
|
155
|
+
|
|
156
|
+
Object.keys(childOpts).forEach(key => {
|
|
177
157
|
params.push(`--${key}`)
|
|
178
158
|
if (childOpts[key] !== true) params.push(childOpts[key])
|
|
179
159
|
})
|
|
@@ -183,7 +163,7 @@ function executeRun(runName, runConfig) {
|
|
|
183
163
|
params.push(runConfig.grep)
|
|
184
164
|
}
|
|
185
165
|
|
|
186
|
-
const onProcessEnd =
|
|
166
|
+
const onProcessEnd = errorCode => {
|
|
187
167
|
if (errorCode !== 0) {
|
|
188
168
|
process.exitCode = errorCode
|
|
189
169
|
}
|
|
@@ -197,7 +177,7 @@ function executeRun(runName, runConfig) {
|
|
|
197
177
|
// Return function of fork for later execution
|
|
198
178
|
return () =>
|
|
199
179
|
fork(runner, params, { stdio: [0, 1, 2, 'ipc'] })
|
|
200
|
-
.on('exit',
|
|
180
|
+
.on('exit', code => {
|
|
201
181
|
return onProcessEnd(code)
|
|
202
182
|
})
|
|
203
183
|
.on('error', () => {
|
package/lib/command/run-rerun.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Codecept = require('../rerun')
|
|
1
|
+
import { getConfig, getTestRoot, printError, createOutputDir } from './utils.js'
|
|
2
|
+
import Config from '../config.js'
|
|
3
|
+
import Codecept from '../rerun.js'
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export default async function (test, options) {
|
|
7
6
|
// registering options globally to use in config
|
|
8
7
|
// Backward compatibility for --profile
|
|
9
8
|
process.profile = options.profile
|
|
10
9
|
process.env.profile = options.profile
|
|
11
10
|
const configFile = options.config
|
|
12
11
|
|
|
13
|
-
let config = getConfig(configFile)
|
|
12
|
+
let config = await getConfig(configFile)
|
|
14
13
|
if (options.override) {
|
|
15
14
|
config = Config.append(JSON.parse(options.override))
|
|
16
15
|
}
|
|
@@ -20,7 +19,7 @@ module.exports = async function (test, options) {
|
|
|
20
19
|
const codecept = new Codecept(config, options)
|
|
21
20
|
|
|
22
21
|
try {
|
|
23
|
-
codecept.init(testRoot)
|
|
22
|
+
await codecept.init(testRoot)
|
|
24
23
|
|
|
25
24
|
await codecept.bootstrap()
|
|
26
25
|
codecept.loadTests(test)
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
// For Node version >=10.5.0, have to use experimental flag
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { tryOrDefault } from '../utils.js'
|
|
3
|
+
import output from '../output.js'
|
|
4
|
+
import store from '../store.js'
|
|
5
|
+
import event from '../event.js'
|
|
6
|
+
import Workers from '../workers.js'
|
|
7
|
+
import Codecept from '../codecept.js'
|
|
8
|
+
import { getMachineInfo } from './info.js'
|
|
9
|
+
|
|
10
|
+
export default async function (workerCount, selectedRuns, options) {
|
|
9
11
|
process.env.profile = options.profile
|
|
10
12
|
|
|
11
|
-
const suiteArr = []
|
|
12
|
-
const passedTestArr = []
|
|
13
|
-
const failedTestArr = []
|
|
14
|
-
const skippedTestArr = []
|
|
15
|
-
const stepArr = []
|
|
16
|
-
|
|
17
13
|
const { config: testConfig, override = '' } = options
|
|
18
14
|
const overrideConfigs = tryOrDefault(() => JSON.parse(override), {})
|
|
19
15
|
const by = options.suites ? 'suite' : 'test'
|
|
@@ -27,72 +23,27 @@ module.exports = async function (workerCount, selectedRuns, options) {
|
|
|
27
23
|
|
|
28
24
|
const numberOfWorkers = parseInt(workerCount, 10)
|
|
29
25
|
|
|
30
|
-
output.print(`CodeceptJS v${
|
|
26
|
+
output.print(`CodeceptJS v${Codecept.version()} ${output.standWithUkraine()}`)
|
|
31
27
|
output.print(`Running tests in ${output.styles.bold(numberOfWorkers)} workers...`)
|
|
32
28
|
output.print()
|
|
29
|
+
store.hasWorkers = true
|
|
33
30
|
|
|
34
31
|
const workers = new Workers(numberOfWorkers, config)
|
|
35
32
|
workers.overrideConfig(overrideConfigs)
|
|
36
33
|
|
|
37
|
-
workers.on(event.
|
|
38
|
-
suiteArr.push(suite)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
workers.on(event.step.passed, (step) => {
|
|
42
|
-
stepArr.push(step)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
workers.on(event.step.failed, (step) => {
|
|
46
|
-
stepArr.push(step)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
workers.on(event.test.failed, (test) => {
|
|
50
|
-
failedTestArr.push(test)
|
|
34
|
+
workers.on(event.test.failed, test => {
|
|
51
35
|
output.test.failed(test)
|
|
52
36
|
})
|
|
53
37
|
|
|
54
|
-
workers.on(event.test.passed,
|
|
55
|
-
passedTestArr.push(test)
|
|
38
|
+
workers.on(event.test.passed, test => {
|
|
56
39
|
output.test.passed(test)
|
|
57
40
|
})
|
|
58
41
|
|
|
59
|
-
workers.on(event.test.skipped,
|
|
60
|
-
skippedTestArr.push(test)
|
|
42
|
+
workers.on(event.test.skipped, test => {
|
|
61
43
|
output.test.skipped(test)
|
|
62
44
|
})
|
|
63
45
|
|
|
64
|
-
workers.on(event.all.result,
|
|
65
|
-
// expose test stats after all workers finished their execution
|
|
66
|
-
function addStepsToTest(test, stepArr) {
|
|
67
|
-
stepArr.test.steps.forEach((step) => {
|
|
68
|
-
if (test.steps.length === 0) {
|
|
69
|
-
test.steps.push(step)
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
stepArr.forEach((step) => {
|
|
75
|
-
passedTestArr.forEach((test) => {
|
|
76
|
-
if (step.test.title === test.title) {
|
|
77
|
-
addStepsToTest(test, step)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
failedTestArr.forEach((test) => {
|
|
82
|
-
if (step.test.title === test.title) {
|
|
83
|
-
addStepsToTest(test, step)
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
event.dispatcher.emit(event.workers.result, {
|
|
89
|
-
suites: suiteArr,
|
|
90
|
-
tests: {
|
|
91
|
-
passed: passedTestArr,
|
|
92
|
-
failed: failedTestArr,
|
|
93
|
-
skipped: skippedTestArr,
|
|
94
|
-
},
|
|
95
|
-
})
|
|
46
|
+
workers.on(event.all.result, result => {
|
|
96
47
|
workers.printResults()
|
|
97
48
|
})
|
|
98
49
|
|
|
@@ -100,8 +51,6 @@ module.exports = async function (workerCount, selectedRuns, options) {
|
|
|
100
51
|
if (options.verbose || options.debug) store.debugMode = true
|
|
101
52
|
|
|
102
53
|
if (options.verbose) {
|
|
103
|
-
global.debugMode = true
|
|
104
|
-
const { getMachineInfo } = require('./info')
|
|
105
54
|
await getMachineInfo()
|
|
106
55
|
}
|
|
107
56
|
await workers.bootstrapAll()
|
package/lib/command/run.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { getConfig, printError, getTestRoot, createOutputDir } from './utils.js'
|
|
2
|
+
import Config from '../config.js'
|
|
3
|
+
import store from '../store.js'
|
|
4
|
+
import Codecept from '../codecept.js'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export default async function (test, options) {
|
|
7
7
|
// registering options globally to use in config
|
|
8
8
|
// Backward compatibility for --profile
|
|
9
9
|
// TODO: remove in CodeceptJS 4
|
|
@@ -16,7 +16,7 @@ module.exports = async function (test, options) {
|
|
|
16
16
|
|
|
17
17
|
const configFile = options.config
|
|
18
18
|
|
|
19
|
-
let config = getConfig(configFile)
|
|
19
|
+
let config = await getConfig(configFile)
|
|
20
20
|
if (options.override) {
|
|
21
21
|
config = Config.append(JSON.parse(options.override))
|
|
22
22
|
}
|
|
@@ -26,13 +26,13 @@ module.exports = async function (test, options) {
|
|
|
26
26
|
const codecept = new Codecept(config, options)
|
|
27
27
|
|
|
28
28
|
try {
|
|
29
|
-
codecept.init(testRoot)
|
|
29
|
+
await codecept.init(testRoot)
|
|
30
30
|
await codecept.bootstrap()
|
|
31
31
|
codecept.loadTests(test)
|
|
32
32
|
|
|
33
33
|
if (options.verbose) {
|
|
34
34
|
global.debugMode = true
|
|
35
|
-
const { getMachineInfo } =
|
|
35
|
+
const { getMachineInfo } = await import('./info.js')
|
|
36
36
|
await getMachineInfo()
|
|
37
37
|
}
|
|
38
38
|
|
package/lib/command/utils.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import util from 'util'
|
|
4
|
+
import { mkdirp } from 'mkdirp'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import output from '../output.js'
|
|
7
|
+
import { fileExists, beautify, deepMerge } from '../utils.js'
|
|
8
8
|
|
|
9
9
|
// alias to deep merge
|
|
10
|
-
|
|
10
|
+
export { deepMerge }
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
export async function getConfig(configFile) {
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
const configModule = await import('../config.js')
|
|
15
|
+
const config = configModule.default || configModule
|
|
16
|
+
return await config.load(configFile)
|
|
15
17
|
} catch (err) {
|
|
16
18
|
fail(err.stack)
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
export function readConfig(configFile) {
|
|
21
23
|
try {
|
|
22
24
|
const data = fs.readFileSync(configFile, 'utf8')
|
|
23
25
|
return data
|
|
@@ -29,18 +31,17 @@ module.exports.readConfig = function (configFile) {
|
|
|
29
31
|
function getTestRoot(currentPath) {
|
|
30
32
|
if (!currentPath) currentPath = '.'
|
|
31
33
|
if (!path.isAbsolute(currentPath)) currentPath = path.join(process.cwd(), currentPath)
|
|
32
|
-
currentPath =
|
|
33
|
-
fs.lstatSync(currentPath).isDirectory() || !path.extname(currentPath) ? currentPath : path.dirname(currentPath)
|
|
34
|
+
currentPath = fs.lstatSync(currentPath).isDirectory() || !path.extname(currentPath) ? currentPath : path.dirname(currentPath)
|
|
34
35
|
return currentPath
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
export { getTestRoot }
|
|
37
38
|
|
|
38
39
|
function fail(msg) {
|
|
39
40
|
output.error(msg)
|
|
40
41
|
process.exit(1)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
export { fail }
|
|
44
45
|
|
|
45
46
|
function updateConfig(testsPath, config, extension) {
|
|
46
47
|
const configFile = path.join(testsPath, `codecept.conf.${extension}`)
|
|
@@ -58,7 +59,7 @@ function updateConfig(testsPath, config, extension) {
|
|
|
58
59
|
return fs.writeFileSync(configFile, beautify(`exports.config = ${util.inspect(config, false, 4, false)}`), 'utf-8')
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
export { updateConfig }
|
|
62
63
|
|
|
63
64
|
function safeFileWrite(file, contents) {
|
|
64
65
|
if (fileExists(file)) {
|
|
@@ -69,9 +70,9 @@ function safeFileWrite(file, contents) {
|
|
|
69
70
|
return true
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
export { safeFileWrite }
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
export const captureStream = stream => {
|
|
75
76
|
let oldStream
|
|
76
77
|
let buffer = ''
|
|
77
78
|
|
|
@@ -79,7 +80,7 @@ module.exports.captureStream = (stream) => {
|
|
|
79
80
|
startCapture() {
|
|
80
81
|
buffer = ''
|
|
81
82
|
oldStream = stream.write.bind(stream)
|
|
82
|
-
stream.write =
|
|
83
|
+
stream.write = chunk => (buffer += chunk)
|
|
83
84
|
},
|
|
84
85
|
stopCapture() {
|
|
85
86
|
if (oldStream !== undefined) stream.write = oldStream
|
|
@@ -88,14 +89,14 @@ module.exports.captureStream = (stream) => {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
export const printError = err => {
|
|
92
93
|
output.print('')
|
|
93
94
|
output.error(err.message)
|
|
94
95
|
output.print('')
|
|
95
96
|
output.print(output.colors.grey(err.stack.replace(err.message, '')))
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
export const createOutputDir = (config, testRoot) => {
|
|
99
100
|
let outputDir
|
|
100
101
|
if (path.isAbsolute(config.output)) outputDir = config.output
|
|
101
102
|
else outputDir = path.join(testRoot, config.output)
|
|
@@ -106,7 +107,7 @@ module.exports.createOutputDir = (config, testRoot) => {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
export const findConfigFile = testsPath => {
|
|
110
111
|
const extensions = ['js', 'ts']
|
|
111
112
|
for (const ext of extensions) {
|
|
112
113
|
const configFile = path.join(testsPath, `codecept.conf.${ext}`)
|