Skip to content

Commit 2d9fcb4

Browse files
author
DavertMik
committed
improved migration
1 parent 422fabc commit 2d9fcb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+848
-961
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default [
2222
...globals.node,
2323
},
2424

25-
ecmaVersion: 2020,
25+
ecmaVersion: 2022,
2626
sourceType: 'module',
2727
},
2828

lib/actor.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import retryStep from './step/retry.js'
44
import { methodsOfObject } from './utils.js'
55
import { TIMEOUT_ORDER } from './timeout.js'
66
import event from './event.js'
7-
import storeModule from './store.js'
8-
const store = storeModule.default || storeModule
7+
import store from './store.js'
98
import output from './output.js'
9+
import Container from './container.js'
1010

1111
/**
1212
* @interface
@@ -71,6 +71,11 @@ class Actor {
7171
* @ignore
7272
*/
7373
export default function (obj = {}, container) {
74+
// Use global container if none provided
75+
if (!container) {
76+
container = Container
77+
}
78+
7479
const actor = container.actor() || new Actor()
7580

7681
// load all helpers once container initialized

lib/ai.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import debugModule from 'debug'
22
const debug = debugModule('codeceptjs:ai')
3-
import outputModule from './output.js'
4-
const output = outputModule.default || outputModule
5-
import eventModule from './event.js'
6-
const event = eventModule.default || eventModule
3+
import output from './output.js'
4+
import event from './event.js'
75
import { removeNonInteractiveElements, minifyHtml, splitByChunks } from './html.js'
86

97
const defaultHtmlConfig = {

lib/codecept.js

Lines changed: 24 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ const __dirname = dirname(__filename)
1111
const require = createRequire(import.meta.url)
1212

1313
import Helper from '@codeceptjs/helper';
14-
import containerModule from './container.js'
15-
const container = containerModule.default || containerModule
16-
import ConfigModule from './config.js'
17-
const Config = ConfigModule.default || ConfigModule
18-
import eventModule from './event.js'
19-
const event = eventModule.default || eventModule
14+
import container from './container.js'
15+
import Config from './config.js'
16+
import event from './event.js'
2017
import runHook from './hooks.js'
2118
import ActorFactory from './actor.js'
22-
import outputModule from './output.js'
23-
const output = outputModule.default || outputModule
19+
import output from './output.js'
2420
import { emptyFolder } from './utils.js'
21+
import { initCodeceptGlobals } from './globals.js'
2522

2623
import storeListener from './listener/store.js'
2724
import stepsListener from './listener/steps.js'
@@ -89,75 +86,23 @@ class Codecept {
8986
* @param {string} dir
9087
*/
9188
async initGlobals(dir) {
92-
global.codecept_dir = dir
93-
global.output_dir = fsPath.resolve(dir, this.config.output)
94-
95-
if (this.config.emptyOutputFolder) emptyFolder(global.output_dir)
96-
97-
if (!this.config.noGlobals) {
98-
// Set up actor global - will use container when available
99-
global.actor = global.codecept_actor = (obj) => {
100-
return ActorFactory(obj, global.container || container)
101-
}
102-
global.Actor = global.actor
103-
// Use dynamic imports for modules to avoid circular dependencies
104-
global.pause = async (...args) => {
105-
const pauseModule = await import('./pause.js')
106-
return (pauseModule.default || pauseModule)(...args)
107-
}
108-
global.within = async (...args) => {
109-
const effectsModule = await import('./effects.js')
110-
return effectsModule.within(...args)
111-
}
112-
global.session = async (...args) => {
113-
const sessionModule = await import('./session.js')
114-
return (sessionModule.default || sessionModule)(...args)
115-
}
116-
const dataTableModule = await import('./data/table.js')
117-
global.DataTable = dataTableModule.default || dataTableModule
118-
global.locate = locator => {
119-
return import('./locator.js').then(locatorModule =>
120-
(locatorModule.default || locatorModule).build(locator)
121-
)
122-
}
123-
global.inject = container.support
124-
global.share = container.share
125-
const secretModule = await import('./secret.js')
126-
global.secret = secretModule.secret || (secretModule.default && secretModule.default.secret)
127-
global.codecept_debug = output.debug
128-
const codeceptjsModule = await import('./index.js') // load all objects
129-
global.codeceptjs = codeceptjsModule.default || codeceptjsModule
130-
131-
// BDD
132-
const stepDefinitionsModule = await import('./mocha/bdd.js')
133-
const stepDefinitions = stepDefinitionsModule.default || stepDefinitionsModule
134-
global.Given = stepDefinitions.Given
135-
global.When = stepDefinitions.When
136-
global.Then = stepDefinitions.Then
137-
global.DefineParameterType = stepDefinitions.defineParameterType
138-
139-
// debug mode
140-
global.debugMode = false
141-
142-
// mask sensitive data
143-
global.maskSensitiveData = this.config.maskSensitiveData || false
144-
}
89+
await initCodeceptGlobals(dir, this.config, container)
14590
}
14691

14792
/**
14893
* Executes hooks.
14994
*/
15095
async runHooks() {
15196
// default hooks
152-
runHook(storeListener.default || storeListener)
153-
runHook(stepsListener.default || stepsListener)
154-
runHook(configListener.default || configListener)
155-
runHook(resultListener.default || resultListener)
156-
runHook(helpersListener.default || helpersListener)
157-
runHook(globalTimeoutListener.default || globalTimeoutListener)
158-
runHook(globalRetryListener.default || globalRetryListener)
159-
runHook(exitListener.default || exitListener)
160-
runHook(emptyRunListener.default || emptyRunListener)
97+
runHook(storeListener)
98+
runHook(stepsListener)
99+
runHook(configListener)
100+
runHook(resultListener)
101+
runHook(helpersListener)
102+
runHook(globalTimeoutListener)
103+
runHook(globalRetryListener)
104+
runHook(exitListener)
105+
runHook(emptyRunListener)
161106

162107
// custom hooks (previous iteration of plugins)
163108
this.config.hooks.forEach(hook => runHook(hook))
@@ -202,7 +147,7 @@ class Codecept {
202147
}
203148
}
204149

205-
if (this.config.gherkin.features && !this.opts.tests) {
150+
if (this.config.gherkin && this.config.gherkin.features && !this.opts.tests) {
206151
if (Array.isArray(this.config.gherkin.features)) {
207152
this.config.gherkin.features.forEach(feature => {
208153
patterns.push(feature)
@@ -236,6 +181,14 @@ class Codecept {
236181
*/
237182
async run(test) {
238183
await container.started()
184+
185+
// Ensure translations are loaded for Gherkin features
186+
try {
187+
const { loadTranslations } = await import('./mocha/gherkin.js')
188+
await loadTranslations()
189+
} catch (e) {
190+
// Ignore if gherkin module not available
191+
}
239192

240193
return new Promise((resolve, reject) => {
241194
const mocha = container.mocha()

lib/command/generate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function test(genPath) {
4646
},
4747
},
4848
])
49-
.then(result => {
49+
.then(async result => {
5050
const testFilePath = path.dirname(path.join(testsPath, config.tests)).replace(/\*\*$/, '')
5151
let testFile = path.join(testFilePath, result.filename)
5252
const ext = path.extname(testFile)

lib/command/info.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import envinfo from 'envinfo'
22

33
import { getConfig, getTestRoot } from './utils.js'
44
import Codecept from '../codecept.js'
5-
import outputModule from '../output.js'
6-
const output = outputModule.default || outputModule
5+
import output from '../output.js'
76
import { execSync } from 'child_process'
87

98
async function getPlaywrightBrowsers() {

lib/command/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default async function (initPath) {
151151
choices: translations,
152152
},
153153
])
154-
.then(result => {
154+
.then(async result => {
155155
if (result.typescript === true) {
156156
isTypeScript = true
157157
extension = isTypeScript === true ? 'ts' : 'js'

lib/command/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import path from 'path'
33
import util from 'util'
44
import { mkdirp } from 'mkdirp'
55

6-
import outputModule from '../output.js'
7-
const output = outputModule.default || outputModule
6+
import output from '../output.js'
87
import { fileExists, beautify, deepMerge } from '../utils.js'
98

109
// alias to deep merge

0 commit comments

Comments
 (0)