Skip to content

Disable globalSetup/globalTeardown in generated Jest configs#2006

Open
mohammedahmed18 wants to merge 1 commit intomainfrom
fix/disable-globalsetup-for-unit-tests
Open

Disable globalSetup/globalTeardown in generated Jest configs#2006
mohammedahmed18 wants to merge 1 commit intomainfrom
fix/disable-globalsetup-for-unit-tests

Conversation

@mohammedahmed18
Copy link
Copy Markdown
Contributor

Problem

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:

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.

Note: Tests for this feature already existed in test_globalsetup_handling.py but were failing, indicating the feature was planned but never implemented.

Solution

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
  • ✅ Verified fix enables optimization of functions in budibase

Impact

  • Severity: HIGH - Blocking issue for projects using Docker/testcontainers in globalSetup
  • Affected logs: Trace ID 4760967c and likely many others in budibase run
  • Projects affected: Any project using testcontainers, database fixtures, or API mocking in globalSetup
  • Example: Budibase uses globalSetup to start CouchDB testcontainers for integration tests

Files Changed

  • codeflash/languages/javascript/test_runner.py - Disable globalSetup/globalTeardown in 4 locations

🤖 Generated with autonomous debugging agent (autoresearch:debug)

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>
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