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 <davert@testomat.io> Co-authored-by: kobenguyent <kobenguyent@gmail.com>
1 parent 7030c7f commit 9aae736

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')

lib/plugin/screenshotOnFail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const defaultConfig = {
1515
fullPageScreenshots: false,
1616
}
1717

18-
const supportedHelpers = require('./standardActingHelpers')
18+
const supportedHelpers = Container.STANDARD_ACTING_HELPERS
1919

2020
/**
2121
* Creates screenshot on failure. Screenshot is saved into `output` directory.

lib/plugin/standardActingHelpers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
const standardActingHelpers = ['Playwright', 'WebDriver', 'Puppeteer', 'Appium', 'TestCafe']
1+
const Container = require('../container')
2+
// due to using this in internal tooling we won't post deprecation warning
3+
// but please switch to Container.STANDARD_ACTING_HELPERS
4+
const standardActingHelpers = Container.STANDARD_ACTING_HELPERS
25

36
module.exports = standardActingHelpers

lib/plugin/stepByStepReport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const event = require('../event')
1212
const output = require('../output')
1313
const { template, deleteDir } = require('../utils')
1414

15-
const supportedHelpers = require('./standardActingHelpers')
15+
const supportedHelpers = Container.STANDARD_ACTING_HELPERS
1616

1717
const defaultConfig = {
1818
deleteSuccessful: true,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.config = {
2+
tests: './*_test.js',
3+
output: './output',
4+
helpers: {
5+
FileSystem: {},
6+
},
7+
include: {},
8+
bootstrap: false,
9+
mocha: {},
10+
name: 'store-test-and-suite tests',
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const assert = require('assert')
2+
3+
Feature('store-test-and-suite suite')
4+
5+
BeforeSuite(({ suite, test }) => {
6+
assert.strictEqual(suite.title, 'store-test-and-suite suite')
7+
assert(!test)
8+
})
9+
10+
Before(({ test }) => {
11+
assert.strictEqual(test.title, 'test store-test-and-suite test')
12+
test.artifacts.screenshot = 'screenshot'
13+
})
14+
15+
Scenario('test store-test-and-suite test', ({ test }) => {
16+
assert.strictEqual(test.title, 'test store-test-and-suite test')
17+
assert(test.artifacts)
18+
assert(test.meta)
19+
assert.strictEqual(test.artifacts.screenshot, 'screenshot')
20+
test.meta.browser = 'chrome'
21+
})
22+
23+
After(({ test }) => {
24+
assert.strictEqual(test.meta.browser, 'chrome')
25+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { expect } = require('expect')
2+
const exec = require('child_process').exec
3+
const { codecept_dir, codecept_run } = require('./consts')
4+
const debug = require('debug')('codeceptjs:tests')
5+
6+
const config_run_config = (config, grep, verbose = false) => `${codecept_run} ${verbose ? '--verbose' : ''} --config ${codecept_dir}/configs/store-test-and-suite/${config} ${grep ? `--grep "${grep}"` : ''}`
7+
8+
describe('CodeceptJS store-test-and-suite', function () {
9+
this.timeout(10000)
10+
11+
it('should run store-test-and-suite test', done => {
12+
exec(config_run_config('codecept.conf.js'), (err, stdout) => {
13+
debug(stdout)
14+
expect(stdout).toContain('test store-test-and-suite test')
15+
expect(stdout).toContain('OK')
16+
expect(err).toBeFalsy()
17+
done()
18+
})
19+
})
20+
})

0 commit comments

Comments
 (0)