Skip to content

Commit c5b8aa6

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent 7252d5f commit c5b8aa6

30 files changed

+253
-64
lines changed

lib/command/generate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Scenario('test something', async ({ {{actor}} }) => {
1818
`
1919

2020
// generates empty test
21-
module.exports.test = function (genPath) {
21+
export const test = function (genPath) {
2222
const testsPath = getTestRoot(genPath)
2323
global.codecept_dir = testsPath
2424
const config = getConfigSync(testsPath)
@@ -107,7 +107,7 @@ export default new {{name}}();
107107
export = {{name}};
108108
`
109109

110-
module.exports.pageObject = function (genPath, opts) {
110+
export const pageObject = function (genPath, opts) {
111111
const testsPath = getTestRoot(genPath)
112112
const config = getConfigSync(testsPath)
113113
const kind = opts.T || 'page'
@@ -227,7 +227,7 @@ class {{name}} extends Helper {
227227
export default {{name}};
228228
`
229229

230-
module.exports.helper = function (genPath) {
230+
export const helper = function (genPath) {
231231
const testsPath = getTestRoot(genPath)
232232

233233
output.print('Creating a new helper')
@@ -269,7 +269,7 @@ helpers: {
269269

270270
const healTemplate = fs.readFileSync(path.join(__dirname, '../template/heal.js'), 'utf8').toString()
271271

272-
module.exports.heal = function (genPath) {
272+
export const heal = function (genPath) {
273273
const testsPath = getTestRoot(genPath)
274274

275275
let configFile = path.join(testsPath, `codecept.conf.${extension}`)

lib/command/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default async function (path) {
7373
output.print('***************************************')
7474
}
7575

76-
module.exports.getMachineInfo = async () => {
76+
export const getMachineInfo = async () => {
7777
const info = {
7878
nodeInfo: await envinfo.helpers.getNodeInfo(),
7979
osInfo: await envinfo.helpers.getOSInfo(),

lib/command/run-workers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// For Node version >=10.5.0, have to use experimental flag
22
import { tryOrDefault } from '../utils.js'
3+
import { getMachineInfo } from './info.js'
34
import output from '../output.js'
45
import store from '../store.js'
56
import event from '../event.js'
@@ -49,7 +50,6 @@ export default async function (workerCount, selectedRuns, options) {
4950
if (options.verbose || options.debug) store.debugMode = true
5051

5152
if (options.verbose) {
52-
import { getMachineInfo } from './info.js'
5353
await getMachineInfo()
5454
}
5555
await workers.bootstrapAll()

lib/command/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getConfig, printError, getTestRoot, createOutputDir } from './utils.js'
2+
import { getMachineInfo } from './info.js'
23
import Config from '../config.js'
34
import store from '../store.js'
45
import Codecept from '../codecept.js'
@@ -32,7 +33,6 @@ export default async function (test, options) {
3233

3334
if (options.verbose) {
3435
global.debugMode = true
35-
import { getMachineInfo } from './info.js'
3636
await getMachineInfo()
3737
}
3838

lib/command/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import util from 'util'
44
import { mkdirp } from 'mkdirp'
55

66
import output from '../output.js'
7+
import Config from '../config.js'
78
import { fileExists, beautify, deepMerge } from '../utils.js'
89

910
// alias to deep merge
1011
export { deepMerge }
1112

1213
export const getConfig = async function (configFile) {
1314
try {
14-
return await (await import('../config.js')).default.load(configFile)
15+
return await Config.load(configFile)
1516
} catch (err) {
1617
fail(err.stack)
1718
}
1819
}
1920

2021
export const getConfigSync = function (configFile) {
2122
try {
22-
return (await import('../config.js')).default.loadSync(configFile)
23+
return Config.loadSync(configFile)
2324
} catch (err) {
2425
fail(err.stack)
2526
}

lib/container.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function checkHelperRequirements(HelperClass) {
294294
async function requireHelperFromModule(helperName, config, HelperClass) {
295295
const moduleName = getHelperModuleName(helperName, config)
296296
if (moduleName.startsWith('./helper/')) {
297-
const mod = await import(moduleName);
297+
const mod = await import(moduleName + '.js');
298298
HelperClass = mod.default || mod;
299299
} else {
300300
// check if the new syntax export default HelperName is used and loads the Helper, otherwise loads the module that used old syntax export = HelperName.
@@ -358,6 +358,44 @@ async function createSupportObjects(config) {
358358
// Return the support objects directly (simplified for ESM conversion)
359359
return supportObjects;
360360
}
361+
362+
async function createPlugins(config, options) {
363+
const plugins = {}
364+
for (const pluginName in config) {
365+
try {
366+
let pluginFn
367+
const pluginConfig = config[pluginName]
368+
369+
if (pluginConfig === false) continue // plugin disabled
370+
371+
// Load plugin module
372+
let moduleName
373+
if (pluginConfig.require) {
374+
moduleName = pluginConfig.require
375+
} else {
376+
moduleName = `./plugin/${pluginName}.js`
377+
}
378+
379+
const mod = await import(moduleName)
380+
pluginFn = mod.default || mod
381+
382+
if (typeof pluginFn === 'function') {
383+
pluginFn(pluginConfig)
384+
plugins[pluginName] = pluginFn
385+
debug(`plugin ${pluginName} loaded`)
386+
}
387+
} catch (err) {
388+
throw new Error(`Could not load plugin ${pluginName} (${err.message})`)
389+
}
390+
}
391+
return plugins
392+
}
393+
394+
async function createActor(actorConfig = {}) {
395+
const actorModule = await import('./actor.js')
396+
const createActorFn = actorModule.default
397+
return createActorFn(actorConfig)
398+
}
361399
async function loadGherkinSteps(paths) {
362400
global.Before = fn => event.dispatcher.on(event.test.started, fn)
363401
global.After = fn => event.dispatcher.on(event.test.finished, fn)

lib/heal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ class Heal {
155155
recorder.throw(error)
156156
}
157157

158-
static setDefaultHealers() {
159-
(await import('./template/heal.js')).default
158+
static async setDefaultHealers() {
159+
return (await import('./template/heal.js')).default
160160
}
161161
}
162162

lib/helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// helper class was moved out from this repository to allow extending from base class
2-
export default (await import('@codeceptjs/helper')).default;
2+
const Helper = await import('@codeceptjs/helper');
3+
export default Helper.default;

lib/mocha/asyncWrapper.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function suiteTestFailedHookError(suite, err, hookName) {
2525
suite.eachTest(test => {
2626
testInstance.err = err
2727
if (hookName) hookName = ucfirst(hookName)
28-
event.emit(event.testInstance.failed, test, err, hookName)
28+
event.emit(event.test.failed, test, err, hookName)
2929
})
3030
}
3131

@@ -63,28 +63,28 @@ export function test(testInstance) {
6363
// check that test should actually fail
6464
try {
6565
assertThrown(err, testInstance.throws)
66-
event.emit(event.testInstance.passed, testInstance)
67-
event.emit(event.testInstance.finished, testInstance)
66+
event.emit(event.test.passed, testInstance)
67+
event.emit(event.test.finished, testInstance)
6868
recorder.add(doneFn)
6969
return
7070
} catch (newErr) {
7171
err = newErr
7272
}
7373
}
7474
testInstance.err = err
75-
event.emit(event.testInstance.failed, testInstance, err)
76-
event.emit(event.testInstance.finished, testInstance)
75+
event.emit(event.test.failed, testInstance, err)
76+
event.emit(event.test.finished, testInstance)
7777
recorder.add(() => doneFn(err))
7878
})
7979

8080
if (isAsyncFunction(testFn)) {
81-
event.emit(event.testInstance.started, testInstance)
81+
event.emit(event.test.started, testInstance)
8282
testFn
8383
.call(testInstance, getInjectedArguments(testFn, testInstance))
8484
.then(() => {
8585
recorder.add('fire testInstance.passed', () => {
86-
event.emit(event.testInstance.passed, testInstance)
87-
event.emit(event.testInstance.finished, testInstance)
86+
event.emit(event.test.passed, testInstance)
87+
event.emit(event.test.finished, testInstance)
8888
})
8989
recorder.add('finish test', doneFn)
9090
})
@@ -98,14 +98,14 @@ export function test(testInstance) {
9898
}
9999

100100
try {
101-
event.emit(event.testInstance.started, testInstance)
101+
event.emit(event.test.started, testInstance)
102102
testFn.call(testInstance, getInjectedArguments(testFn, testInstance))
103103
} catch (err) {
104104
recorder.throw(err)
105105
} finally {
106106
recorder.add('fire testInstance.passed', () => {
107-
event.emit(event.testInstance.passed, testInstance)
108-
event.emit(event.testInstance.finished, testInstance)
107+
event.emit(event.test.passed, testInstance)
108+
event.emit(event.test.finished, testInstance)
109109
})
110110
recorder.add('finish test', doneFn)
111111
recorder.catch()
@@ -129,7 +129,7 @@ export function injected(fn, suite, hookName) {
129129
if (hookName === 'after') {
130130
suiteTestFailedHookError(suite, err, hookName)
131131
suite.eachTest(test => {
132-
event.emit(event.testInstance.after, test)
132+
event.emit(event.test.after, test)
133133
})
134134
}
135135
if (hookName === 'afterSuite') {
@@ -201,14 +201,14 @@ export function injected(fn, suite, hookName) {
201201
export function setup(suite) {
202202
return injectHook(() => {
203203
recorder.startUnlessRunning()
204-
event.emit(event.testInstance.before, enhanceMochaTest(suite?.ctx?.currentTest))
204+
event.emit(event.test.before, enhanceMochaTest(suite?.ctx?.currentTest))
205205
}, suite)
206206
}
207207

208208
export function teardown(suite) {
209209
return injectHook(() => {
210210
recorder.startUnlessRunning()
211-
event.emit(event.testInstance.after, enhanceMochaTest(suite?.ctx?.currentTest))
211+
event.emit(event.test.after, enhanceMochaTest(suite?.ctx?.currentTest))
212212
}, suite)
213213
}
214214

lib/mocha/factory.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class MochaFactory {
1818
mocha = new Mocha(Object.assign(config, opts))
1919
output.process(opts.child)
2020
mocha.ui(scenarioUi)
21+
// mocha.ui('bdd')
2122

2223
Mocha.Runner.prototype.uncaught = function (err) {
2324
if (err) {

0 commit comments

Comments
 (0)