Skip to content

refactor: eliminate internal globals in favor of store singleton#5506

Open
DavertMik wants to merge 3 commits into4.xfrom
chore/remove-globals
Open

refactor: eliminate internal globals in favor of store singleton#5506
DavertMik wants to merge 3 commits into4.xfrom
chore/remove-globals

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

Summary

  • Add store.initialize() with immutable required fields (codeceptDir, outputDir, workerMode) that are frozen via Object.defineProperty after initialization
  • Replace all internal global.* reads with store properties or direct ESM imports (~70 call sites across 44 files)
  • Migrate process.env flags (RUNS_WITH_WORKERS, FEATURE_ONLY, SCENARIO_ONLY) to store session config
  • Keep user-facing DSL globals (Feature, Scenario, Before, etc.) and backward-compat writes for external plugins

Store field categories

Category Fields Lifecycle
Required codeceptDir, outputDir, workerMode Set once via initialize(), frozen, never cleared
Session config debugMode, timeouts, autoRetries, dryRun, featureOnly, scenarioOnly, maskSensitiveData Per-session, mutable
State onPause, currentTest, currentStep, currentSuite Tracks live execution

What was eliminated

Global Replacement Sites changed
global.codecept_dir store.codeceptDir ~30
global.output_dir store.outputDir ~22
global.container import container ~15
global.debugMode store.debugMode 3
global.__playwrightSelectorsRegistered module-level let 1
global.__codeceptConfigListenerInitialized module-level let 1
global.codecept_debug removed (dead code) 1
process.env.RUNS_WITH_WORKERS store.workerMode 4
process.env.FEATURE_ONLY store.featureOnly 1
process.env.SCENARIO_ONLY store.scenarioOnly 2
global.maskSensitiveData store.maskSensitiveData 1

Test plan

  • Framework boots and initializes correctly
  • store.initialize() freezes required fields (verified with direct test)
  • Acceptance tests with Playwright config run without framework errors
  • Full acceptance test suite
  • Worker mode tests

🤖 Generated with Claude Code

DavertMik and others added 3 commits April 6, 2026 01:19
…direct imports

Replace all internal global variable usage with proper ESM patterns:
- Add store.initialize() method with immutable required fields (codeceptDir, outputDir, workerMode)
- Replace global.codecept_dir/output_dir reads with store.codeceptDir/outputDir (~55 sites)
- Replace global.container reads with direct container imports (~15 sites)
- Replace global.debugMode with store.debugMode in WebDriver/Puppeteer
- Replace process.env.RUNS_WITH_WORKERS with store.workerMode
- Replace process.env.FEATURE_ONLY/SCENARIO_ONLY with store.featureOnly/scenarioOnly
- Replace global.maskSensitiveData with store.maskSensitiveData
- Convert singleton guard globals to module-level variables
- Remove dead global.codecept_debug
- Keep user-facing DSL globals (Feature, Scenario, etc.) and backward compat writes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ration

These were set in 3.x codecept.js but never ported to 4.x globals.js.
Needed for CJS helpers that use `const Helper = codecept_helper`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- noGlobals: true skips ALL globals including Mocha DSL (Feature, Scenario, etc.)
- noGlobals: false (default for existing projects) prints deprecation warning
- New projects generated via `codeceptjs init` get noGlobals: true by default
- Store noGlobals flag in store so initMochaGlobals respects it

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant