@@ -11,17 +11,14 @@ const __dirname = dirname(__filename)
1111const require = createRequire ( import . meta. url )
1212
1313import 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'
2017import runHook from './hooks.js'
2118import ActorFactory from './actor.js'
22- import outputModule from './output.js'
23- const output = outputModule . default || outputModule
19+ import output from './output.js'
2420import { emptyFolder } from './utils.js'
21+ import { initCodeceptGlobals } from './globals.js'
2522
2623import storeListener from './listener/store.js'
2724import 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 ( )
0 commit comments