Skip to content

Commit 9aae736

Browse files
DavertMikDavertMikkobenguyent
authored
injecting test & siute to container (#4785)
* injecting test & siute to container * added container const * fix: export STANDARD_ACTING_HELPERS type --------- Co-authored-by: DavertMik <[email protected]> Co-authored-by: kobenguyent <[email protected]>
1 parent 7030c7f commit 9aae736

File tree

16 files changed

+97
-14
lines changed

16 files changed

+97
-14
lines changed

lib/codecept.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ class Codecept {
202202
}
203203
const done = () => {
204204
event.emit(event.all.result, container.result())
205-
event.emit(event.all.after)
205+
event.emit(event.all.after, this)
206206
resolve()
207207
}
208208

209209
try {
210-
event.emit(event.all.before)
210+
event.emit(event.all.before, this)
211211
mocha.run(() => done())
212212
} catch (e) {
213213
output.error(e.stack)

lib/command/check.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { getConfig, getTestRoot } = require('./utils')
22
const Codecept = require('../codecept')
33
const output = require('../output')
4-
const standardActingHelpers = require('../plugin/standardActingHelpers')
54
const store = require('../store')
65
const container = require('../container')
76
const figures = require('figures')
@@ -23,6 +22,7 @@ module.exports = async function (options) {
2322
container: false,
2423
pageObjects: false,
2524
plugins: false,
25+
ai: true, // we don't need to check AI
2626
helpers: false,
2727
setup: false,
2828
tests: false,
@@ -51,6 +51,8 @@ module.exports = async function (options) {
5151
checks.container = err
5252
}
5353

54+
const standardActingHelpers = container.STANDARD_ACTING_HELPERS
55+
5456
printCheck('container', checks['container'])
5557

5658
if (codecept) {
@@ -83,6 +85,13 @@ module.exports = async function (options) {
8385
}
8486
}
8587

88+
if (config?.ai?.request) {
89+
checks.ai = true
90+
printCheck('ai', checks['ai'], 'AI configuration is enabled, request function is set')
91+
} else {
92+
printCheck('ai', checks['ai'], 'AI is disabled')
93+
}
94+
8695
printCheck('tests', checks['tests'], `Total: ${numTests} tests`)
8796

8897
store.dryRun = true
@@ -170,7 +179,7 @@ function printCheck(name, value, comment = '') {
170179
}
171180

172181
if (value instanceof Error) {
173-
comment = `${comment} ${chalk.red.italic(value.message)}`.trim()
182+
comment = `${comment} ${chalk.red(value.message)}`.trim()
174183
}
175184

176185
output.print(status, name.toUpperCase(), chalk.dim(comment))

lib/command/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { getConfig, getTestRoot } = require('./utils')
55
const Codecept = require('../codecept')
66
const container = require('../container')
77
const output = require('../output')
8-
const actingHelpers = [...require('../plugin/standardActingHelpers'), 'REST']
8+
const actingHelpers = [...container.STANDARD_ACTING_HELPERS, 'REST']
99

1010
/**
1111
* Prepare data and generate content of definitions file

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Codecept = require('../codecept')
44
const Container = require('../container')
55
const event = require('../event')
66
const output = require('../output')
7-
const webHelpers = require('../plugin/standardActingHelpers')
7+
const webHelpers = Container.STANDARD_ACTING_HELPERS
88

99
module.exports = async function (path, options) {
1010
// Backward compatibility for --profile

lib/container.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ let container = {
3434
* Dependency Injection Container
3535
*/
3636
class Container {
37+
/**
38+
* Get the standard acting helpers of CodeceptJS Container
39+
*
40+
*/
41+
static get STANDARD_ACTING_HELPERS() {
42+
return ['Playwright', 'WebDriver', 'Puppeteer', 'Appium', 'TestCafe']
43+
}
3744
/**
3845
* Create container with all required helpers and support objects
3946
*

lib/helper/AI.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const ora = require('ora-classic')
33
const fs = require('fs')
44
const path = require('path')
55
const ai = require('../ai')
6-
const standardActingHelpers = require('../plugin/standardActingHelpers')
76
const Container = require('../container')
87
const { splitByChunks, minifyHtml } = require('../html')
98
const { beautify } = require('../utils')
109
const output = require('../output')
1110
const { registerVariable } = require('../pause')
1211

12+
const standardActingHelpers = Container.STANDARD_ACTING_HELPERS
13+
1314
const gtpRole = {
1415
user: 'user',
1516
}

lib/mocha/asyncWrapper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ module.exports.injected = function (fn, suite, hookName) {
145145
const opts = suite.opts || {}
146146
const retries = opts[`retry${ucfirst(hookName)}`] || 0
147147

148+
const currentTest = hookName === 'before' || hookName === 'after' ? suite?.ctx?.currentTest : null
149+
148150
promiseRetry(
149151
async (retry, number) => {
150152
try {
151153
recorder.startUnlessRunning()
152-
await fn.call(this, getInjectedArguments(fn))
154+
await fn.call(this, { ...getInjectedArguments(fn), suite, test: currentTest })
153155
await recorder.promise().catch(err => retry(err))
154156
} catch (err) {
155157
retry(err)

lib/mocha/inject.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const getInjectedArguments = (fn, test) => {
55
const testArgs = {}
66
const params = parser.getParams(fn) || []
77
const objects = container.support()
8+
89
for (const key of params) {
910
testArgs[key] = {}
1011
if (test && test.inject && test.inject[key]) {
@@ -18,6 +19,10 @@ const getInjectedArguments = (fn, test) => {
1819
testArgs[key] = container.support(key)
1920
}
2021

22+
if (test) {
23+
testArgs.suite = test?.parent
24+
testArgs.test = test
25+
}
2126
return testArgs
2227
}
2328

lib/plugin/autoDelay.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const Container = require('../container')
22
const store = require('../store')
33
const recorder = require('../recorder')
44
const event = require('../event')
5-
const log = require('../output').log
6-
const supportedHelpers = require('./standardActingHelpers').slice()
5+
const { log } = require('../output')
6+
const standardActingHelpers = Container.STANDARD_ACTING_HELPERS
77

88
const methodsToDelay = ['click', 'fillField', 'checkOption', 'pressKey', 'doubleClick', 'rightClick']
99

lib/plugin/pageInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fs = require('fs')
33
const Container = require('../container')
44
const recorder = require('../recorder')
55
const event = require('../event')
6-
const supportedHelpers = require('./standardActingHelpers')
6+
const supportedHelpers = Container.STANDARD_ACTING_HELPERS
77
const { scanForErrorMessages } = require('../html')
88
const { output } = require('..')
99
const { humanizeString, ucfirst } = require('../utils')

0 commit comments

Comments
 (0)