Skip to content

Multiple Small fixes on JS/TS codebases - #1720

Merged
Saga4 merged 8 commits into
mainfrom
fix/jest-junit-and-misc
Mar 2, 2026
Merged

Multiple Small fixes on JS/TS codebases#1720
Saga4 merged 8 commits into
mainfrom
fix/jest-junit-and-misc

Conversation

@Saga4

@Saga4 Saga4 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor
  • feat: bundle JUnit XML reporter for Jest, replacing external jest-junit dependency
  • feat: discover const arrow functions exported via named export clauses
  • feat: discover object methods exported via CJS module.exports = variable
  • fix: raise clear error for unsupported JS test frameworks instead of silent fallback
  • feat: add skip_confirm and skip_api_key params to JS init for non-interactive mode
  • fix: show actionable error when JS/TS function exists but is not exported

Saga4 and others added 6 commits March 2, 2026 21:59
…it dependency

Ship a zero-dependency jest-reporter.js inside the codeflash runtime package
instead of requiring the external jest-junit npm package. This ensures the
reporter is always available when codeflash is installed, fixing Jest-based
projects (Strapi, Moleculer) that failed because jest-junit wasn't installed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Post-process find_functions() to mark functions as exported when they appear
in named export clauses like `export { joinBy }`. This fixes discovery for
TypeScript codebases (e.g., Strapi) that define const arrow functions and
export them via a separate export statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve `module.exports = varName` where varName is an object literal
containing methods. For patterns like `const utils = { match() {} };
module.exports = utils;`, the individual methods are now recognized as
exported. This fixes function discovery for CJS libraries like Moleculer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…silent fallback

Add NotImplementedError guard in all 3 test dispatchers (behavioral,
benchmarking, line-profile) for frameworks other than jest and vitest.
Previously, mocha and other frameworks silently fell through to Jest,
causing confusing failures. Now users get a clear error message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eractive mode

Allow init_js_project(), should_modify_package_json_config(), and
collect_js_setup_info() to run without interactive prompts when
skip_confirm=True. Uses auto-detected defaults instead of prompting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rted

When a user targets a function that exists in the file but is not exported,
show a clear message suggesting they add an export statement, instead of
the generic "function not found" error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Saga4
Saga4 requested a review from mohammedahmed18 March 2, 2026 16:36
@claude

claude Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

PR Review Summary

Prek Checks

All checks pass. ruff check and ruff format both passed cleanly.

Mypy

All mypy errors in changed source files are pre-existing (subprocess.run overload issues, CompletedProcess generic params, _get_theme missing return type). No new type errors introduced by this PR.

Code Review

Bug: Dead code with wrong arguments_find_all_functions_via_language_support() in functions_to_optimize.py:186 is defined but never called. It also passes incorrect arguments to discover_functions(): passes (file_path, criteria) but the protocol signature is (source: str, file_path: Path, filter_criteria). If this function is intended for future use, the call should be lang_support.discover_functions(file_path.read_text(encoding="utf-8"), file_path, criteria).

No other runtime bugs, security vulnerabilities, or breaking API changes found. The PR is well-structured:

  • jest-junit → bundled codeflash/jest-reporter migration is clean; _ensure_runtime_files() is called in all three jest runner paths
  • New Mocha runner follows the same patterns as the existing Jest/Vitest runners
  • TreeSitter export detection improvements (named export clauses, CJS re-export object methods) are well-tested
  • skip_confirm / skip_api_key parameters are properly threaded through init functions

Test Coverage

150 tests pass. Coverage for changed source files:

File Stmts Miss Cover
mocha_runner.py (new) 252 26 90%
test_runner.py 522 187 64%
treesitter.py 910 408 55%
init_javascript.py 367 241 34%
functions_to_optimize.py 477 417 13%
support.py 1035 899 13%

New file mocha_runner.py has excellent coverage at 90%. The low percentages on other files reflect large pre-existing modules where only a fraction of the total code is exercised by the targeted tests in this PR.


Last updated: 2026-03-02T12:00:00Z

@codeflash-ai

codeflash-ai Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

⚡️ Codeflash found optimizations for this PR

📄 30% (0.30x) speedup for should_modify_package_json_config in codeflash/cli_cmds/init_javascript.py

⏱️ Runtime : 4.15 milliseconds 3.19 milliseconds (best of 56 runs)

A new Optimization Review has been created.

🔗 Review here

Static Badge

@Saga4
Saga4 merged commit d805c6e into main Mar 2, 2026
25 of 27 checks passed
@Saga4
Saga4 deleted the fix/jest-junit-and-misc branch March 2, 2026 17:26
@codeflash-ai

codeflash-ai Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

⚡️ Codeflash found optimizations for this PR

📄 46% (0.46x) speedup for _extract_mocha_json in codeflash/languages/javascript/mocha_runner.py

⏱️ Runtime : 4.24 milliseconds 2.90 milliseconds (best of 122 runs)

A dependent PR with the suggested changes has been created. Please review:

If you approve, it will be merged into this PR (branch fix/jest-junit-and-misc).

Static Badge

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