@@ -11,17 +11,14 @@ const __dirname = dirname(__filename)
11
11
const require = createRequire ( import . meta. url )
12
12
13
13
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'
20
17
import runHook from './hooks.js'
21
18
import ActorFactory from './actor.js'
22
- import outputModule from './output.js'
23
- const output = outputModule . default || outputModule
19
+ import output from './output.js'
24
20
import { emptyFolder } from './utils.js'
21
+ import { initCodeceptGlobals } from './globals.js'
25
22
26
23
import storeListener from './listener/store.js'
27
24
import stepsListener from './listener/steps.js'
@@ -89,75 +86,23 @@ class Codecept {
89
86
* @param {string } dir
90
87
*/
91
88
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 )
145
90
}
146
91
147
92
/**
148
93
* Executes hooks.
149
94
*/
150
95
async runHooks ( ) {
151
96
// 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 )
161
106
162
107
// custom hooks (previous iteration of plugins)
163
108
this . config . hooks . forEach ( hook => runHook ( hook ) )
@@ -202,7 +147,7 @@ class Codecept {
202
147
}
203
148
}
204
149
205
- if ( this . config . gherkin . features && ! this . opts . tests ) {
150
+ if ( this . config . gherkin && this . config . gherkin . features && ! this . opts . tests ) {
206
151
if ( Array . isArray ( this . config . gherkin . features ) ) {
207
152
this . config . gherkin . features . forEach ( feature => {
208
153
patterns . push ( feature )
@@ -236,6 +181,14 @@ class Codecept {
236
181
*/
237
182
async run ( test ) {
238
183
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
+ }
239
192
240
193
return new Promise ( ( resolve , reject ) => {
241
194
const mocha = container . mocha ( )
0 commit comments