feat(parser): add Vitest/Jest test detection for describe/it/test blocks#54
feat(parser): add Vitest/Jest test detection for describe/it/test blocks#54JF10R wants to merge 3 commits intotirth8205:mainfrom
Conversation
Intercept call_expression nodes with test runner names (describe, it, test, beforeEach, etc.) in test files and create Test nodes with synthetic names from the description string. Recurse into callbacks with enclosing_func set so CALLS edges inside tests are properly attributed, enabling automatic TESTED_BY edge generation. New constant: _TEST_RUNNER_NAMES New method: _get_test_description() New fixture: sample_vitest.test.ts 5 new test methods
- _is_test_function: réutilise _TEST_RUNNER_NAMES au lieu du tuple dupliqué - _get_test_description: docstring condensée, variable intermédiaire retirée - test_vitest_contains_edges: ajout assertion sur les edges CONTAINS - test_vitest_calls_edges: correction message assertion - test_non_test_file_describe_not_special: pattern cohérent avec le repo
There was a problem hiding this comment.
Pull request overview
Adds Vitest/Jest-style test block detection to the Tree-sitter parser so describe/it/test (and hooks) in JS/TS test files produce Test nodes and proper containment/call attribution, enabling much broader automatic TESTED_BY edge generation.
Changes:
- Extend
code_review_graph/parser.pyto detect test-runnercall_expressionnodes in JS/TS test files, create syntheticTestnodes, and recurse into callback bodies with the correctenclosing_func. - Add a Vitest fixture (
sample_vitest.test.ts) that exercises nesteddescribe+it/testblocks and calls into imported production symbols. - Add parser tests validating
Testnode creation plusCONTAINS,CALLS, andTESTED_BYedge generation, and ensure non-test files don’t get special handling.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
code_review_graph/parser.py |
Adds test-runner call interception and description extraction to build Test nodes and attribute internal calls to those tests. |
tests/fixtures/sample_vitest.test.ts |
New TS fixture containing describe/it/test blocks and calls into imported code. |
tests/test_parser.py |
New pytest cases covering test detection and edge generation for Vitest/Jest-style tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ertions - Add _MAX_TEST_DESCRIPTION_LEN = 200 constant; _get_test_description now strips surrounding quotes/backticks, collapses internal whitespace via re.sub, and truncates to the cap to prevent bloated node names - Append @l{line_no} to synthetic test names so identical descriptions under different describe blocks produce unique node names - Add _get_base_call_name() + _TEST_MODIFIER_SUFFIXES to detect describe.only(), it.skip(), test.each(), etc. as proper test runner calls - Replace "describe" in n / "it:" in n substring checks with startswith() in test_vitest_test_detection and test_vitest_contains_edges Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
All 5 review comments addressed in 460f516: parser.py:
Tests:
|
Adds describe/it/test block parsing for JS/TS test files, producing synthetic Test nodes with description labels. Supports modifier suffixes (describe.only, it.skip, test.each) and nested describe/it containment. Co-Authored-By: JF10R <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nfigurable embeddings, MiniMax, Perl) * feat: integrate PR #43 — R language support Adds R language parsing with function extraction (both <- and = assignment), S4/R5 class detection via setClass/setRefClass, library/require/source imports, namespace-qualified calls (dplyr::filter), and testthat test detection. Co-Authored-By: michael-denyer <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR #54 — Vitest/Jest test detection Adds describe/it/test block parsing for JS/TS test files, producing synthetic Test nodes with description labels. Supports modifier suffixes (describe.only, it.skip, test.each) and nested describe/it containment. Co-Authored-By: JF10R <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR #53 — tsconfig path alias resolution Adds TsconfigResolver module that resolves TypeScript path aliases (e.g., @/ -> src/) from tsconfig.json compilerOptions.paths. Also resolves import targets to absolute file paths in IMPORTS_FROM edges. Co-Authored-By: JF10R <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR #58 — .mjs/.astro support Adds .mjs extension mapping to JavaScript and .astro extension mapping to TypeScript for import path resolution. Co-Authored-By: zoneghost7 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR #55 — configurable embedding model Adds CRG_EMBEDDING_MODEL env var and model parameter to embedding functions, allowing users to specify any sentence-transformers compatible model. Changing the model re-embeds all nodes automatically. Co-Authored-By: eugenepro2 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR #45 — MiniMax embedding provider Adds MiniMaxEmbeddingProvider using the embo-01 model (1536 dimensions) with support for distinct task types (db/query), batching, and retry logic. Co-Authored-By: octo-patch <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR #62 — Perl support Adds Perl language parsing with package detection, subroutine extraction, use/require imports, and function call tracking. Includes test fixture and comprehensive test class. Co-Authored-By: potatogim <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: michael-denyer <noreply@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Integrated into main via PR #68. Thank you for the contribution! 🎉 |
…nfigurable embeddings, MiniMax, Perl) * feat: integrate PR tirth8205#43 — R language support Adds R language parsing with function extraction (both <- and = assignment), S4/R5 class detection via setClass/setRefClass, library/require/source imports, namespace-qualified calls (dplyr::filter), and testthat test detection. Co-Authored-By: michael-denyer <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR tirth8205#54 — Vitest/Jest test detection Adds describe/it/test block parsing for JS/TS test files, producing synthetic Test nodes with description labels. Supports modifier suffixes (describe.only, it.skip, test.each) and nested describe/it containment. Co-Authored-By: JF10R <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR tirth8205#53 — tsconfig path alias resolution Adds TsconfigResolver module that resolves TypeScript path aliases (e.g., @/ -> src/) from tsconfig.json compilerOptions.paths. Also resolves import targets to absolute file paths in IMPORTS_FROM edges. Co-Authored-By: JF10R <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR tirth8205#58 — .mjs/.astro support Adds .mjs extension mapping to JavaScript and .astro extension mapping to TypeScript for import path resolution. Co-Authored-By: zoneghost7 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR tirth8205#55 — configurable embedding model Adds CRG_EMBEDDING_MODEL env var and model parameter to embedding functions, allowing users to specify any sentence-transformers compatible model. Changing the model re-embeds all nodes automatically. Co-Authored-By: eugenepro2 <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR tirth8205#45 — MiniMax embedding provider Adds MiniMaxEmbeddingProvider using the embo-01 model (1536 dimensions) with support for distinct task types (db/query), batching, and retry logic. Co-Authored-By: octo-patch <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: integrate PR tirth8205#62 — Perl support Adds Perl language parsing with package detection, subroutine extraction, use/require imports, and function call tracking. Includes test fixture and comprehensive test class. Co-Authored-By: potatogim <noreply@github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: michael-denyer <noreply@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Vitest/Jest test detection (_TEST_RUNNER_NAMES, describe/it/test blocks creating Test nodes) is already in main — parser.py has _TEST_RUNNER_NAMES at line 249 and the test runner detection branch. This PR has been integrated. No revival needed. |
Summary
describe,it,test,beforeEach, etc.) in test files and create properTestnodesenclosing_funccontext so CALLS edges inside tests are properly attributedTESTED_BYedge generation via the existing reverse-edge logicBefore: 1 Test node, 2 TESTED_BY edges across 69 test files
After: 3,205 Test nodes, 18,331 TESTED_BY edges
Root cause
Tree-sitter parses
describe("suite", () => { ... })as acall_expressioncontaining an anonymousarrow_function. The parser found the arrow function but skipped it because_get_name()returnsNonefor anonymous functions. No Test node was ever created.Changes
code_review_graph/parser.py_TEST_RUNNER_NAMESconstant_get_test_description()method to extract the description string from test calls_extract_from_tree()that intercepts test runnercall_expressionnodes in test files, createsTestnodes with synthetic names (e.g.,describe:UserService), and recurses with properenclosing_func_is_test_function()to reuse_TEST_RUNNER_NAMEStests/fixtures/sample_vitest.test.tsDesign decisions
call_expressionlevel (not by modifying arrow function naming), keeping the change localizedcall_name:descriptionformat (e.g.,it:should create a user)describe()in production code is not affecteddescribe→it→ function callsTest plan
pytest tests/test_parser.py -v)🤖 Generated with Claude Code