Disable globalSetup/globalTeardown in generated Jest configs#2006
Open
mohammedahmed18 wants to merge 1 commit intomainfrom
Open
Disable globalSetup/globalTeardown in generated Jest configs#2006mohammedahmed18 wants to merge 1 commit intomainfrom
mohammedahmed18 wants to merge 1 commit intomainfrom
Conversation
Projects often use globalSetup to start infrastructure like Docker containers, databases, or test servers. These are needed for integration tests but not for Codeflash-generated unit tests. When globalSetup fails (e.g., Docker not available), all tests fail with: ``` Error: Jest: Got error running globalSetup - globalSetup.ts reason: Command failed: docker context ls --format json /bin/sh: 1: docker: not found ``` **Root Cause:** Both _create_codeflash_jest_config() and _create_runtime_jest_config() spread the original config without explicitly disabling globalSetup and globalTeardown. This causes generated unit tests to inherit heavyweight integration test setup. **Fix:** Explicitly set globalSetup: undefined and globalTeardown: undefined in both: 1. Codeflash config (for ESM package compatibility) 2. Runtime config (for test roots configuration) Unit tests don't need global setup/teardown - they test isolated functions with mocked dependencies. **Testing:** - ✅ All 6 existing globalSetup tests now pass (were failing before) - ✅ All 34 test_runner tests pass - ✅ Linter passes **Impact:** - Fixes trace ID 4760967c and likely many others - Enables optimization of functions in projects with Docker-dependent globalSetup - Common in projects using testcontainers, database fixtures, or API mocking Fixes issue discovered in budibase optimization run where globalSetup.ts requires Docker to start CouchDB testcontainers. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Projects often use
globalSetupto start infrastructure like Docker containers, databases, or test servers. These are needed for integration tests but not for Codeflash-generated unit tests.When globalSetup fails (e.g., Docker not available), all tests fail:
Root Cause
Both
_create_codeflash_jest_config()and_create_runtime_jest_config()spread the original config without explicitly disablingglobalSetupandglobalTeardown. This causes generated unit tests to inherit heavyweight integration test setup.Note: Tests for this feature already existed in
test_globalsetup_handling.pybut were failing, indicating the feature was planned but never implemented.Solution
Explicitly set
globalSetup: undefinedandglobalTeardown: undefinedin both:Unit tests don't need global setup/teardown - they test isolated functions with mocked dependencies.
Testing
Impact
Files Changed
codeflash/languages/javascript/test_runner.py- Disable globalSetup/globalTeardown in 4 locations🤖 Generated with autonomous debugging agent (autoresearch:debug)