codeceptjs 4.0.0-beta.5 → 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 +0 -45
- package/bin/codecept.js +46 -57
- package/lib/actor.js +15 -11
- package/lib/ai.js +6 -5
- package/lib/assert/empty.js +9 -8
- package/lib/assert/equal.js +15 -17
- package/lib/assert/error.js +2 -2
- package/lib/assert/include.js +9 -11
- package/lib/assert/throws.js +1 -1
- package/lib/assert/truth.js +8 -5
- package/lib/assert.js +18 -18
- package/lib/codecept.js +66 -107
- package/lib/colorUtils.js +48 -50
- package/lib/command/check.js +32 -27
- package/lib/command/configMigrate.js +11 -10
- package/lib/command/definitions.js +16 -10
- package/lib/command/dryRun.js +16 -16
- package/lib/command/generate.js +29 -26
- package/lib/command/gherkin/init.js +36 -38
- package/lib/command/gherkin/snippets.js +14 -14
- package/lib/command/gherkin/steps.js +21 -18
- package/lib/command/info.js +8 -8
- package/lib/command/init.js +34 -31
- package/lib/command/interactive.js +11 -10
- package/lib/command/list.js +10 -9
- package/lib/command/run-multiple/chunk.js +5 -5
- package/lib/command/run-multiple/collection.js +5 -5
- package/lib/command/run-multiple/run.js +3 -3
- package/lib/command/run-multiple.js +16 -13
- package/lib/command/run-rerun.js +6 -7
- package/lib/command/run-workers.js +10 -24
- package/lib/command/run.js +8 -8
- package/lib/command/utils.js +20 -18
- package/lib/command/workers/runTests.js +117 -269
- package/lib/config.js +111 -49
- package/lib/container.js +299 -102
- package/lib/data/context.js +6 -5
- package/lib/data/dataScenarioConfig.js +1 -1
- package/lib/data/dataTableArgument.js +1 -1
- package/lib/data/table.js +1 -1
- package/lib/effects.js +94 -10
- package/lib/els.js +11 -9
- package/lib/event.js +11 -10
- package/lib/globals.js +141 -0
- package/lib/heal.js +12 -12
- package/lib/helper/AI.js +1 -1
- package/lib/helper/ApiDataFactory.js +16 -13
- package/lib/helper/FileSystem.js +32 -12
- package/lib/helper/GraphQL.js +1 -1
- package/lib/helper/GraphQLDataFactory.js +1 -1
- package/lib/helper/JSONResponse.js +19 -30
- package/lib/helper/Mochawesome.js +9 -28
- package/lib/helper/Playwright.js +668 -265
- package/lib/helper/Puppeteer.js +284 -169
- package/lib/helper/REST.js +29 -12
- package/lib/helper/WebDriver.js +191 -71
- 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 +1 -1
- 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 +6 -7
- package/lib/listener/exit.js +4 -3
- package/lib/listener/globalRetry.js +5 -5
- package/lib/listener/globalTimeout.js +11 -10
- package/lib/listener/helpers.js +33 -14
- package/lib/listener/mocha.js +3 -4
- package/lib/listener/result.js +4 -5
- package/lib/listener/steps.js +7 -18
- package/lib/listener/store.js +3 -3
- package/lib/locator.js +213 -192
- package/lib/mocha/asyncWrapper.js +108 -75
- package/lib/mocha/bdd.js +99 -13
- package/lib/mocha/cli.js +60 -27
- package/lib/mocha/factory.js +75 -19
- package/lib/mocha/featureConfig.js +1 -1
- package/lib/mocha/gherkin.js +57 -25
- package/lib/mocha/hooks.js +12 -3
- package/lib/mocha/index.js +13 -4
- package/lib/mocha/inject.js +22 -5
- package/lib/mocha/scenarioConfig.js +2 -2
- package/lib/mocha/suite.js +9 -2
- package/lib/mocha/test.js +10 -13
- package/lib/mocha/ui.js +28 -31
- package/lib/output.js +11 -9
- package/lib/parser.js +44 -44
- package/lib/pause.js +15 -16
- package/lib/plugin/analyze.js +19 -12
- package/lib/plugin/auth.js +20 -21
- package/lib/plugin/autoDelay.js +12 -8
- package/lib/plugin/coverage.js +12 -8
- package/lib/plugin/customLocator.js +3 -3
- package/lib/plugin/customReporter.js +3 -2
- package/lib/plugin/heal.js +14 -9
- package/lib/plugin/pageInfo.js +10 -10
- package/lib/plugin/pauseOnFail.js +4 -3
- package/lib/plugin/retryFailedStep.js +47 -5
- package/lib/plugin/screenshotOnFail.js +75 -37
- package/lib/plugin/stepByStepReport.js +14 -14
- package/lib/plugin/stepTimeout.js +4 -3
- package/lib/plugin/subtitles.js +6 -5
- package/lib/recorder.js +33 -23
- package/lib/rerun.js +69 -26
- package/lib/result.js +4 -4
- package/lib/secret.js +18 -17
- package/lib/session.js +95 -89
- package/lib/step/base.js +6 -6
- package/lib/step/config.js +1 -1
- package/lib/step/func.js +3 -3
- package/lib/step/helper.js +3 -3
- package/lib/step/meta.js +4 -4
- package/lib/step/record.js +11 -11
- package/lib/step/retry.js +3 -3
- package/lib/step/section.js +3 -3
- package/lib/step.js +7 -10
- package/lib/steps.js +9 -5
- package/lib/store.js +1 -1
- package/lib/timeout.js +1 -7
- package/lib/transform.js +8 -8
- package/lib/translation.js +32 -18
- package/lib/utils.js +68 -97
- package/lib/workerStorage.js +16 -17
- package/lib/workers.js +145 -171
- package/package.json +63 -57
- package/translations/de-DE.js +2 -2
- package/translations/fr-FR.js +2 -2
- package/translations/index.js +23 -10
- package/translations/it-IT.js +2 -2
- package/translations/ja-JP.js +2 -2
- package/translations/nl-NL.js +2 -2
- package/translations/pl-PL.js +2 -2
- package/translations/pt-BR.js +2 -2
- package/translations/ru-RU.js +2 -2
- package/translations/utils.js +11 -2
- package/translations/zh-CN.js +2 -2
- package/translations/zh-TW.js +2 -2
- package/typings/index.d.ts +7 -18
- package/typings/promiseBasedTypes.d.ts +3769 -5450
- package/typings/types.d.ts +3953 -5778
- package/bin/test-server.js +0 -53
- package/lib/element/WebElement.js +0 -327
- package/lib/helper/Nightmare.js +0 -1486
- package/lib/helper/Protractor.js +0 -1840
- package/lib/helper/TestCafe.js +0 -1391
- 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 -61
- package/lib/listener/retryEnhancer.js +0 -85
- package/lib/plugin/allure.js +0 -15
- package/lib/plugin/autoLogin.js +0 -5
- package/lib/plugin/commentStep.js +0 -141
- package/lib/plugin/eachElement.js +0 -127
- package/lib/plugin/fakerTransform.js +0 -49
- package/lib/plugin/htmlReporter.js +0 -1947
- package/lib/plugin/retryTo.js +0 -16
- package/lib/plugin/selenoid.js +0 -364
- package/lib/plugin/standardActingHelpers.js +0 -6
- package/lib/plugin/tryTo.js +0 -16
- package/lib/plugin/wdio.js +0 -247
- package/lib/test-server.js +0 -323
- package/lib/within.js +0 -90
package/lib/mocha/gherkin.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import Gherkin from '@cucumber/gherkin'
|
|
2
|
+
import { IdGenerator } from '@cucumber/messages'
|
|
3
|
+
import { Context, Suite } from 'mocha'
|
|
4
|
+
import debug from 'debug'
|
|
5
|
+
const debugBdd = debug('codeceptjs:bdd')
|
|
6
|
+
|
|
7
|
+
import event from '../event.js'
|
|
8
|
+
import { injected, setup, teardown, suiteSetup, suiteTeardown } from './asyncWrapper.js'
|
|
9
|
+
import step from '../step/base.js'
|
|
10
|
+
import MetaStep from '../step/meta.js'
|
|
11
|
+
import DataTableArgument from '../data/dataTableArgument.js'
|
|
12
|
+
import transform from '../transform.js'
|
|
13
|
+
import { enhanceMochaSuite } from './suite.js'
|
|
14
|
+
import { createTest } from './test.js'
|
|
15
|
+
import { matchStep } from './bdd.js'
|
|
16
|
+
|
|
17
|
+
const uuidFn = IdGenerator.uuid()
|
|
16
18
|
const builder = new Gherkin.AstBuilder(uuidFn)
|
|
17
19
|
const matcher = new Gherkin.GherkinClassicTokenMatcher()
|
|
18
20
|
const parser = new Gherkin.Parser(builder, matcher)
|
|
19
21
|
parser.stopAtFirstError = false
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
const gherkinParser = (text, file) => {
|
|
22
24
|
const ast = parser.parse(text)
|
|
23
25
|
let currentLanguage
|
|
24
26
|
|
|
25
27
|
if (ast.feature) {
|
|
28
|
+
// Ensure translations are loaded before trying to access them
|
|
26
29
|
currentLanguage = getTranslation(ast.feature.language)
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -39,14 +42,20 @@ module.exports = (text, file) => {
|
|
|
39
42
|
suite.file = file
|
|
40
43
|
suite.timeout(0)
|
|
41
44
|
|
|
42
|
-
suite.beforeEach('codeceptjs.before', ()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
suite.beforeEach('codeceptjs.before', function () {
|
|
46
|
+
// In Mocha, 'this' refers to the current test in beforeEach/afterEach hooks
|
|
47
|
+
setup(this)(() => {})
|
|
48
|
+
})
|
|
49
|
+
suite.afterEach('codeceptjs.after', function () {
|
|
50
|
+
// In Mocha, 'this' refers to the current test in beforeEach/afterEach hooks
|
|
51
|
+
teardown(this)(() => {})
|
|
52
|
+
})
|
|
53
|
+
suite.beforeAll('codeceptjs.beforeSuite', suiteSetup(suite))
|
|
54
|
+
suite.afterAll('codeceptjs.afterSuite', suiteTeardown(suite))
|
|
46
55
|
|
|
47
56
|
const runSteps = async steps => {
|
|
48
57
|
for (const step of steps) {
|
|
49
|
-
const metaStep = new
|
|
58
|
+
const metaStep = new MetaStep(null, step.text)
|
|
50
59
|
metaStep.actor = step.keyword.trim()
|
|
51
60
|
let helperStep
|
|
52
61
|
const setMetaStep = step => {
|
|
@@ -107,7 +116,7 @@ module.exports = (text, file) => {
|
|
|
107
116
|
)
|
|
108
117
|
continue
|
|
109
118
|
}
|
|
110
|
-
if (child.scenario && (currentLanguage ? currentLanguage.contexts.ScenarioOutline
|
|
119
|
+
if (child.scenario && (currentLanguage ? currentLanguage.contexts.ScenarioOutline.includes(child.scenario.keyword) : child.scenario.keyword === 'Scenario Outline')) {
|
|
111
120
|
for (const examples of child.scenario.examples) {
|
|
112
121
|
const fields = examples.tableHeader.cells.map(c => c.value)
|
|
113
122
|
for (const example of examples.tableBody) {
|
|
@@ -184,16 +193,39 @@ function addExampleInTable(exampleSteps, placeholders) {
|
|
|
184
193
|
return steps
|
|
185
194
|
}
|
|
186
195
|
|
|
196
|
+
// Import translations at module level to avoid async in parser
|
|
197
|
+
let translations = null
|
|
198
|
+
async function loadTranslations() {
|
|
199
|
+
if (!translations) {
|
|
200
|
+
// Import container to ensure it's initialized
|
|
201
|
+
const Container = await import('../container.js')
|
|
202
|
+
await Container.default.started()
|
|
203
|
+
|
|
204
|
+
// Now load translations
|
|
205
|
+
const translationsModule = await import('../../translations/index.js')
|
|
206
|
+
translations = translationsModule.default || translationsModule
|
|
207
|
+
}
|
|
208
|
+
return translations
|
|
209
|
+
}
|
|
210
|
+
|
|
187
211
|
function getTranslation(language) {
|
|
188
|
-
|
|
212
|
+
if (!translations) {
|
|
213
|
+
// Translations not loaded yet, return null (will use default)
|
|
214
|
+
return null
|
|
215
|
+
}
|
|
189
216
|
|
|
190
|
-
|
|
217
|
+
const translationKeys = Object.keys(translations)
|
|
218
|
+
for (const availableTranslation of translationKeys) {
|
|
191
219
|
if (!language) {
|
|
192
220
|
break
|
|
193
221
|
}
|
|
194
222
|
|
|
195
223
|
if (availableTranslation.includes(language)) {
|
|
196
|
-
return
|
|
224
|
+
return translations[availableTranslation]
|
|
197
225
|
}
|
|
198
226
|
}
|
|
227
|
+
return null
|
|
199
228
|
}
|
|
229
|
+
|
|
230
|
+
export { loadTranslations }
|
|
231
|
+
export default gherkinParser
|
package/lib/mocha/hooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import event from '../event.js'
|
|
2
|
+
import { serializeError } from '../utils.js'
|
|
3
3
|
// const { serializeTest } = require('./test')
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -102,7 +102,16 @@ class HookConfig {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
export {
|
|
106
|
+
BeforeHook,
|
|
107
|
+
AfterHook,
|
|
108
|
+
BeforeSuiteHook,
|
|
109
|
+
AfterSuiteHook,
|
|
110
|
+
fireHook,
|
|
111
|
+
HookConfig,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default {
|
|
106
115
|
BeforeHook,
|
|
107
116
|
AfterHook,
|
|
108
117
|
BeforeSuiteHook,
|
package/lib/mocha/index.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import Suite from 'mocha/lib/suite.js'
|
|
2
|
+
import Test from 'mocha/lib/test.js'
|
|
3
|
+
import { BeforeHook, AfterHook, BeforeSuiteHook, AfterSuiteHook } from './hooks.js'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export {
|
|
6
|
+
Suite,
|
|
7
|
+
Test,
|
|
8
|
+
BeforeHook,
|
|
9
|
+
AfterHook,
|
|
10
|
+
BeforeSuiteHook,
|
|
11
|
+
AfterSuiteHook,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default {
|
|
6
15
|
Suite,
|
|
7
16
|
Test,
|
|
8
17
|
BeforeHook,
|
package/lib/mocha/inject.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { getParams } from '../parser.js'
|
|
2
|
+
|
|
3
|
+
const getInjectedArguments = async (fn, test, suite) => {
|
|
4
|
+
const containerModule = await import('../container.js')
|
|
5
|
+
const container = containerModule.default || containerModule
|
|
2
6
|
|
|
3
|
-
const getInjectedArguments = (fn, test) => {
|
|
4
|
-
const container = require('../container')
|
|
5
7
|
const testArgs = {}
|
|
6
|
-
const params =
|
|
8
|
+
const params = getParams(fn) || []
|
|
7
9
|
const objects = container.support()
|
|
8
10
|
|
|
9
11
|
for (const key of params) {
|
|
10
12
|
testArgs[key] = {}
|
|
13
|
+
|
|
14
|
+
// Handle special built-in objects first
|
|
15
|
+
if (key === 'suite') {
|
|
16
|
+
if (test) {
|
|
17
|
+
testArgs[key] = test.parent || test
|
|
18
|
+
} else if (suite) {
|
|
19
|
+
testArgs[key] = suite
|
|
20
|
+
}
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
if (key === 'test') {
|
|
24
|
+
testArgs[key] = test
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
|
|
11
28
|
if (test && test.inject && test.inject[key]) {
|
|
12
29
|
// @FIX: need fix got inject
|
|
13
30
|
testArgs[key] = test.inject[key]
|
|
@@ -26,4 +43,4 @@ const getInjectedArguments = (fn, test) => {
|
|
|
26
43
|
return testArgs
|
|
27
44
|
}
|
|
28
45
|
|
|
29
|
-
|
|
46
|
+
export { getInjectedArguments }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { isAsyncFunction } from '../utils.js'
|
|
2
2
|
|
|
3
3
|
/** @class */
|
|
4
4
|
class ScenarioConfig {
|
|
@@ -135,4 +135,4 @@ class ScenarioConfig {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
export default ScenarioConfig
|
package/lib/mocha/suite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import MochaSuite from 'mocha/lib/suite.js'
|
|
2
2
|
/**
|
|
3
3
|
* @typedef {import('mocha')} Mocha
|
|
4
4
|
*/
|
|
@@ -74,7 +74,14 @@ function deserializeSuite(suite) {
|
|
|
74
74
|
return suite
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
export {
|
|
78
|
+
createSuite,
|
|
79
|
+
enhanceMochaSuite,
|
|
80
|
+
serializeSuite,
|
|
81
|
+
deserializeSuite,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default {
|
|
78
85
|
createSuite,
|
|
79
86
|
enhanceMochaSuite,
|
|
80
87
|
serializeSuite,
|
package/lib/mocha/test.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import Test from 'mocha/lib/test.js'
|
|
2
|
+
import Suite from 'mocha/lib/suite.js'
|
|
3
|
+
import { genTestId, serializeError, clearString, relativeDir } from '../utils.js'
|
|
4
|
+
import Step from '../step/base.js'
|
|
5
|
+
import { enhanceMochaSuite } from './suite.js'
|
|
6
|
+
import { test as testWrapper } from './asyncWrapper.js'
|
|
7
7
|
/**
|
|
8
8
|
* Factory function to create enhanced tests
|
|
9
9
|
* @param {string} title - Test title
|
|
@@ -47,6 +47,7 @@ function enhanceMochaTest(test) {
|
|
|
47
47
|
*/
|
|
48
48
|
test.addToSuite = function (suite) {
|
|
49
49
|
enhanceMochaSuite(suite)
|
|
50
|
+
// Get testWrapper from asyncWrapper module
|
|
50
51
|
suite.addTest(testWrapper(this))
|
|
51
52
|
if (test.file && !suite.file) suite.file = test.file
|
|
52
53
|
test.tags = [...(test.tags || []), ...(suite.tags || [])]
|
|
@@ -77,12 +78,6 @@ function deserializeTest(test) {
|
|
|
77
78
|
test.parent = Object.assign(new Suite(test.parent?.title || 'Suite'), test.parent)
|
|
78
79
|
enhanceMochaSuite(test.parent)
|
|
79
80
|
if (test.steps) test.steps = test.steps.map(step => Object.assign(new Step(step.title), step))
|
|
80
|
-
|
|
81
|
-
// Restore the custom fullTitle function to maintain consistency with original test
|
|
82
|
-
if (test.parent) {
|
|
83
|
-
test.fullTitle = () => `${test.parent.title}: ${test.title}`
|
|
84
|
-
}
|
|
85
|
-
|
|
86
81
|
return test
|
|
87
82
|
}
|
|
88
83
|
|
|
@@ -171,7 +166,9 @@ function testToFileName(test, { suffix = '', unique = false } = {}) {
|
|
|
171
166
|
return fileName
|
|
172
167
|
}
|
|
173
168
|
|
|
174
|
-
|
|
169
|
+
export { createTest, testToFileName, enhanceMochaTest, serializeTest, deserializeTest, cloneTest }
|
|
170
|
+
|
|
171
|
+
export default {
|
|
175
172
|
createTest,
|
|
176
173
|
testToFileName,
|
|
177
174
|
enhanceMochaTest,
|
package/lib/mocha/ui.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import escapeRe from 'escape-string-regexp'
|
|
2
|
+
import { test, setup, teardown, suiteSetup, suiteTeardown, injected } from './asyncWrapper.js'
|
|
3
|
+
import ScenarioConfig from './scenarioConfig.js'
|
|
4
|
+
import FeatureConfig from './featureConfig.js'
|
|
5
|
+
import addDataContext from '../data/context.js'
|
|
6
|
+
import { createTest } from './test.js'
|
|
7
|
+
import { createSuite } from './suite.js'
|
|
8
|
+
import { HookConfig, AfterSuiteHook, AfterHook, BeforeSuiteHook, BeforeHook } from './hooks.js'
|
|
9
|
+
import { initMochaGlobals } from '../globals.js'
|
|
10
|
+
import common from 'mocha/lib/interfaces/common.js'
|
|
11
|
+
import container from '../container.js'
|
|
9
12
|
|
|
10
13
|
const setContextTranslation = context => {
|
|
11
|
-
|
|
12
|
-
const
|
|
14
|
+
// Try global container first, then local container instance
|
|
15
|
+
const containerToUse = global.container || container
|
|
16
|
+
if (!containerToUse) return
|
|
17
|
+
|
|
18
|
+
const translation = containerToUse.translation?.() || containerToUse.translation
|
|
19
|
+
const contexts = translation?.value?.('contexts')
|
|
13
20
|
|
|
14
21
|
if (contexts) {
|
|
15
22
|
for (const key of Object.keys(contexts)) {
|
|
@@ -34,7 +41,7 @@ const setContextTranslation = context => {
|
|
|
34
41
|
* @param {Mocha.Suite} suite Root suite.
|
|
35
42
|
* @ignore
|
|
36
43
|
*/
|
|
37
|
-
|
|
44
|
+
export default function (suite) {
|
|
38
45
|
const suites = [suite]
|
|
39
46
|
suite.timeout(0)
|
|
40
47
|
let afterAllHooks
|
|
@@ -43,7 +50,7 @@ module.exports = function (suite) {
|
|
|
43
50
|
let afterEachHooksAreLoaded
|
|
44
51
|
|
|
45
52
|
suite.on('pre-require', (context, file, mocha) => {
|
|
46
|
-
const
|
|
53
|
+
const cmn = common(suites, context, mocha)
|
|
47
54
|
|
|
48
55
|
const addScenario = function (title, opts = {}, fn) {
|
|
49
56
|
const suite = suites[0]
|
|
@@ -65,8 +72,8 @@ module.exports = function (suite) {
|
|
|
65
72
|
|
|
66
73
|
// create dispatcher
|
|
67
74
|
|
|
68
|
-
context.BeforeAll =
|
|
69
|
-
context.AfterAll =
|
|
75
|
+
context.BeforeAll = cmn.before
|
|
76
|
+
context.AfterAll = cmn.after
|
|
70
77
|
|
|
71
78
|
context.run = mocha.options.delay && common.runWithSuite(suite)
|
|
72
79
|
/**
|
|
@@ -94,28 +101,15 @@ module.exports = function (suite) {
|
|
|
94
101
|
|
|
95
102
|
suite.file = file
|
|
96
103
|
suites.unshift(suite)
|
|
97
|
-
suite.beforeEach('codeceptjs.before',
|
|
98
|
-
afterEachHooks.push(['finalize codeceptjs',
|
|
104
|
+
suite.beforeEach('codeceptjs.before', setup(suite))
|
|
105
|
+
afterEachHooks.push(['finalize codeceptjs', teardown(suite)])
|
|
99
106
|
|
|
100
|
-
suite.beforeAll('codeceptjs.beforeSuite',
|
|
101
|
-
afterAllHooks.push(['codeceptjs.afterSuite',
|
|
107
|
+
suite.beforeAll('codeceptjs.beforeSuite', suiteSetup(suite))
|
|
108
|
+
afterAllHooks.push(['codeceptjs.afterSuite', suiteTeardown(suite)])
|
|
102
109
|
|
|
103
110
|
return new FeatureConfig(suite)
|
|
104
111
|
}
|
|
105
112
|
|
|
106
|
-
/**
|
|
107
|
-
* Exclusive test suite - runs only this feature.
|
|
108
|
-
* @global
|
|
109
|
-
* @kind constant
|
|
110
|
-
* @type {CodeceptJS.IFeature}
|
|
111
|
-
*/
|
|
112
|
-
context.Feature.only = function (title, opts) {
|
|
113
|
-
const reString = `^${escapeRe(`${title}:`)}`
|
|
114
|
-
mocha.grep(new RegExp(reString))
|
|
115
|
-
process.env.FEATURE_ONLY = true
|
|
116
|
-
return context.Feature(title, opts)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
113
|
/**
|
|
120
114
|
* Pending test suite.
|
|
121
115
|
* @global
|
|
@@ -208,6 +202,9 @@ module.exports = function (suite) {
|
|
|
208
202
|
|
|
209
203
|
setContextTranslation(context)
|
|
210
204
|
|
|
205
|
+
// Initialize all globals
|
|
206
|
+
initMochaGlobals(context)
|
|
207
|
+
|
|
211
208
|
addDataContext(context)
|
|
212
209
|
})
|
|
213
210
|
|
package/lib/output.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import colors from 'chalk'
|
|
2
|
+
import figures from 'figures'
|
|
3
|
+
import { maskSensitiveData } from 'invisi-data'
|
|
4
4
|
|
|
5
5
|
const styles = {
|
|
6
6
|
error: colors.bgRed.white.bold,
|
|
@@ -21,7 +21,7 @@ let newline = true
|
|
|
21
21
|
* @alias output
|
|
22
22
|
* @namespace
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
const output = {
|
|
25
25
|
colors,
|
|
26
26
|
styles,
|
|
27
27
|
print,
|
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
|
61
61
|
debug(msg) {
|
|
62
62
|
const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
|
|
63
63
|
if (outputLevel >= 2) {
|
|
64
|
-
print(' '.repeat(
|
|
64
|
+
print(' '.repeat(output.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`))
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
|
|
@@ -72,7 +72,7 @@ module.exports = {
|
|
|
72
72
|
log(msg) {
|
|
73
73
|
const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
|
|
74
74
|
if (outputLevel >= 3) {
|
|
75
|
-
print(' '.repeat(
|
|
75
|
+
print(' '.repeat(output.stepShift), styles.log(truncate(` ${_msg}`, output.stepShift)))
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
|
|
@@ -98,7 +98,7 @@ module.exports = {
|
|
|
98
98
|
* @param {string} msg
|
|
99
99
|
*/
|
|
100
100
|
plugin(pluginName, msg = '') {
|
|
101
|
-
|
|
101
|
+
output.debug(`<${pluginName}> ${msg}`)
|
|
102
102
|
},
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -118,14 +118,14 @@ module.exports = {
|
|
|
118
118
|
let stepLine = step.toCliStyled ? step.toCliStyled() : step.toString()
|
|
119
119
|
if (step.metaStep && outputLevel >= 1) {
|
|
120
120
|
// this.stepShift += 2;
|
|
121
|
-
stepLine = colors.dim(truncate(stepLine,
|
|
121
|
+
stepLine = colors.dim(truncate(stepLine, output.stepShift))
|
|
122
122
|
}
|
|
123
123
|
if (step.comment) {
|
|
124
124
|
stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)))
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
const _stepLine = isMaskedData() ? maskSensitiveData(stepLine) : stepLine
|
|
128
|
-
print(' '.repeat(
|
|
128
|
+
print(' '.repeat(output.stepShift), truncate(_stepLine, output.stepShift))
|
|
129
129
|
},
|
|
130
130
|
|
|
131
131
|
/** @namespace */
|
|
@@ -282,3 +282,5 @@ function truncate(msg, gap = 0) {
|
|
|
282
282
|
function isMaskedData() {
|
|
283
283
|
return global.maskSensitiveData === true || false
|
|
284
284
|
}
|
|
285
|
+
|
|
286
|
+
export default output
|
package/lib/parser.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
function _interopDefault(ex) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _interopDefault(ex) {
|
|
2
|
+
return ex && typeof ex === 'object' && 'default' in ex ? ex.default : ex
|
|
3
|
+
}
|
|
4
|
+
import * as acorn from 'acorn'
|
|
5
|
+
import parseFunctionModule from 'parse-function'
|
|
6
|
+
const parseFunction = _interopDefault(parseFunctionModule)
|
|
7
|
+
const parser = parseFunction({ parse: acorn.parse, ecmaVersion: 11, plugins: ['objectRestSpread'] })
|
|
8
|
+
import output from './output.js'
|
|
5
9
|
|
|
6
|
-
parser.use(destructuredArgs)
|
|
10
|
+
parser.use(destructuredArgs)
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
const newFn = fn.toString().replace(/^async/, 'async function')
|
|
10
|
-
return getParams(newFn).join(', ')
|
|
11
|
-
}
|
|
12
|
+
export const getParamsToString = function (fn) {
|
|
13
|
+
const newFn = fn.toString().replace(/^async/, 'async function')
|
|
14
|
+
return getParams(newFn).join(', ')
|
|
15
|
+
}
|
|
12
16
|
|
|
13
17
|
function getParams(fn) {
|
|
14
|
-
if (fn.isSinonProxy) return []
|
|
18
|
+
if (fn.isSinonProxy) return []
|
|
15
19
|
try {
|
|
16
|
-
const reflected = parser.parse(fn)
|
|
20
|
+
const reflected = parser.parse(fn)
|
|
17
21
|
if (reflected.args.length > 1 || reflected.args[0] === 'I') {
|
|
18
|
-
error('Error: old CodeceptJS v2 format detected. Upgrade your project to the new format -> https://bit.ly/codecept3Up')
|
|
22
|
+
output.error('Error: old CodeceptJS v2 format detected. Upgrade your project to the new format -> https://bit.ly/codecept3Up')
|
|
19
23
|
}
|
|
20
|
-
if (reflected.destructuredArgs.length > 0) reflected.args = [...reflected.destructuredArgs]
|
|
21
|
-
const params = reflected.args.map(
|
|
22
|
-
const def = reflected.defaults[p]
|
|
24
|
+
if (reflected.destructuredArgs.length > 0) reflected.args = [...reflected.destructuredArgs]
|
|
25
|
+
const params = reflected.args.map(p => {
|
|
26
|
+
const def = reflected.defaults[p]
|
|
23
27
|
if (def) {
|
|
24
|
-
return `${p}=${def}
|
|
28
|
+
return `${p}=${def}`
|
|
25
29
|
}
|
|
26
|
-
return p
|
|
27
|
-
})
|
|
28
|
-
return params
|
|
30
|
+
return p
|
|
31
|
+
})
|
|
32
|
+
return params
|
|
29
33
|
} catch (err) {
|
|
30
|
-
console.log(`Error in ${fn.toString()}`)
|
|
31
|
-
error(err)
|
|
34
|
+
console.log(`Error in ${fn.toString()}`)
|
|
35
|
+
output.error(err)
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
export { getParams }
|
|
36
40
|
|
|
37
41
|
function destructuredArgs() {
|
|
38
42
|
return (node, result) => {
|
|
39
|
-
result.destructuredArgs = result.destructuredArgs || []
|
|
43
|
+
result.destructuredArgs = result.destructuredArgs || []
|
|
40
44
|
|
|
41
45
|
if (node.type === 'ObjectExpression' && node.properties.length > 0) {
|
|
42
|
-
node.properties.forEach(
|
|
46
|
+
node.properties.forEach(prop => {
|
|
43
47
|
if (prop.value && prop.value.params.length > 0) {
|
|
44
|
-
result.destructuredArgs = parseDestructuredArgs(prop.value)
|
|
48
|
+
result.destructuredArgs = parseDestructuredArgs(prop.value)
|
|
45
49
|
}
|
|
46
|
-
})
|
|
50
|
+
})
|
|
47
51
|
|
|
48
|
-
return result
|
|
52
|
+
return result
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
if (!Array.isArray(node.params)) return result
|
|
52
|
-
result.destructuredArgs = parseDestructuredArgs(node)
|
|
55
|
+
if (!Array.isArray(node.params)) return result
|
|
56
|
+
result.destructuredArgs = parseDestructuredArgs(node)
|
|
53
57
|
|
|
54
|
-
return result
|
|
55
|
-
}
|
|
58
|
+
return result
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
function parseDestructuredArgs(node) {
|
|
59
|
-
const destructuredArgs = []
|
|
60
|
-
node.params.forEach(
|
|
61
|
-
if (
|
|
62
|
-
param.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
param.properties.forEach((prop) => {
|
|
67
|
-
const { name } = prop.value;
|
|
68
|
-
destructuredArgs.push(name);
|
|
69
|
-
});
|
|
63
|
+
const destructuredArgs = []
|
|
64
|
+
node.params.forEach(param => {
|
|
65
|
+
if (param.type === 'ObjectPattern' && param.properties && param.properties.length > 0) {
|
|
66
|
+
param.properties.forEach(prop => {
|
|
67
|
+
const { name } = prop.value
|
|
68
|
+
destructuredArgs.push(name)
|
|
69
|
+
})
|
|
70
70
|
}
|
|
71
|
-
})
|
|
71
|
+
})
|
|
72
72
|
|
|
73
|
-
return destructuredArgs
|
|
73
|
+
return destructuredArgs
|
|
74
74
|
}
|
package/lib/pause.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import colors from 'chalk'
|
|
2
|
+
import readline from 'readline'
|
|
3
|
+
import ora from 'ora-classic'
|
|
4
|
+
import debugModule from 'debug'
|
|
5
|
+
const debug = debugModule('codeceptjs:pause')
|
|
6
|
+
import container from './container.js'
|
|
7
|
+
import history from './history.js'
|
|
8
|
+
import store from './store.js'
|
|
9
|
+
import aiAssistant from './ai.js'
|
|
10
|
+
import recorder from './recorder.js'
|
|
11
|
+
import event from './event.js'
|
|
12
|
+
import output from './output.js'
|
|
13
|
+
import { methodsOfObject, searchWithFusejs } from './utils.js'
|
|
14
14
|
|
|
15
15
|
// npm install colors
|
|
16
16
|
let rl
|
|
@@ -234,6 +234,5 @@ function registerVariable(name, value) {
|
|
|
234
234
|
registeredVariables[name] = value
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
module.exports.registerVariable = registerVariable
|
|
237
|
+
export default pause
|
|
238
|
+
export { registerVariable }
|