Skip to content

Commit f855c05

Browse files
Merge pull request #1497 from codeflash-ai/fix/jest30-pnpm-resolution
fix: resolve jest-runner from project's node_modules for Jest 30 compatibility
2 parents fc9cdf8 + c262f3c commit f855c05

6 files changed

Lines changed: 153 additions & 154 deletions

File tree

.github/workflows/js-tests.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

codeflash/languages/javascript/parse.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,5 @@ def parse_jest_test_xml(
527527
f"[LOOP-SUMMARY] Results loop_index: min={min_idx}, max={max_idx}, "
528528
f"unique_count={len(unique_loop_indices)}, total_results={len(loop_indices)}"
529529
)
530-
if max_idx == 1 and len(loop_indices) > 1:
531-
logger.warning(
532-
f"[LOOP-WARNING] All {len(loop_indices)} results have loop_index=1. "
533-
"Perf test markers may not have been parsed correctly."
534-
)
535530

536531
return test_results

codeflash/languages/javascript/test_runner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,6 @@ def run_jest_behavioral_tests(
803803
wall_clock_ns = time.perf_counter_ns() - start_time_ns
804804
logger.debug(f"Jest behavioral tests completed in {wall_clock_ns / 1e9:.2f}s")
805805

806-
print(result.stdout)
807-
808806
return result_file_path, result, coverage_json_path, None
809807

810808

@@ -1046,6 +1044,10 @@ def run_jest_benchmarking_tests(
10461044

10471045
# Create result with combined stdout
10481046
result = subprocess.CompletedProcess(args=result.args, returncode=result.returncode, stdout=stdout, stderr="")
1047+
if result.returncode != 0:
1048+
logger.info(f"Jest benchmarking failed with return code {result.returncode}")
1049+
logger.info(f"Jest benchmarking stdout: {result.stdout}")
1050+
logger.info(f"Jest benchmarking stderr: {result.stderr}")
10491051

10501052
except subprocess.TimeoutExpired:
10511053
logger.warning(f"Jest benchmarking timed out after {total_timeout}s")

codeflash/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# These version placeholders will be replaced by uv-dynamic-versioning during build.
2-
__version__ = "0.20.0.post510.dev0+b8932209"
2+
__version__ = "0.20.0.post634.dev0+2d73cf88"

packages/codeflash/runtime/capture.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,26 @@ function checkSharedTimeLimit() {
113113

114114
/**
115115
* Get the current loop index for a specific invocation.
116-
* The loop index represents how many times ALL test files have been run through.
117-
* This is the batch count from the loop-runner.
116+
* When using external loop-runner (Jest), returns the batch number directly.
117+
* When using internal looping (Vitest), tracks and returns the invocation count.
118+
*
118119
* @param {string} invocationKey - Unique key for this test invocation
119-
* @returns {number} The current batch number (loop index)
120+
* @returns {number} The loop index for timing markers (1-based)
120121
*/
121122
function getInvocationLoopIndex(invocationKey) {
122-
// Track local loop count for stopping logic (increments on each call)
123+
// When using external loop-runner, use the batch number directly
124+
// This is reliable because Jest resets module state between batches
125+
const currentBatch = process.env.CODEFLASH_PERF_CURRENT_BATCH;
126+
if (currentBatch !== undefined) {
127+
return parseInt(currentBatch, 10);
128+
}
129+
130+
// For internal looping (Vitest), track the count locally
123131
if (!sharedPerfState.invocationLoopCounts[invocationKey]) {
124132
sharedPerfState.invocationLoopCounts[invocationKey] = 0;
125133
}
126134
++sharedPerfState.invocationLoopCounts[invocationKey];
127-
128-
// Return the batch number as the loop index for timing markers
129-
// This represents how many times all test files have been run through
130-
return parseInt(process.env.CODEFLASH_PERF_CURRENT_BATCH || '1', 10);
135+
return sharedPerfState.invocationLoopCounts[invocationKey];
131136
}
132137

133138
/**
@@ -693,11 +698,9 @@ function capturePerf(funcName, lineId, fn, ...args) {
693698
// If not set, we're in Vitest mode and need to do all loops internally
694699
const hasExternalLoopRunner = process.env.CODEFLASH_PERF_CURRENT_BATCH !== undefined;
695700

696-
// Batched looping: run BATCH_SIZE loops per capturePerf call when using loop-runner
701+
// When using external loop-runner (Jest), execute only once per call - the loop-runner handles batching
697702
// For Vitest (no loop-runner), do all loops internally in a single call
698-
const batchSize = shouldLoop
699-
? (hasExternalLoopRunner ? getPerfBatchSize() : getPerfLoopCount())
700-
: 1;
703+
const batchSize = hasExternalLoopRunner ? 1 : (shouldLoop ? getPerfLoopCount() : 1);
701704

702705
// Initialize runtime tracking for this invocation if needed
703706
if (!sharedPerfState.invocationRuntimes[invocationKey]) {
@@ -719,7 +722,7 @@ function capturePerf(funcName, lineId, fn, ...args) {
719722
break;
720723
}
721724

722-
// Get the loop index (batch number) for timing markers
725+
// Get the loop index for timing markers
723726
const loopIndex = getInvocationLoopIndex(invocationKey);
724727

725728
// Check if we've exceeded max loops for this invocation

0 commit comments

Comments
 (0)