-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Summary
Extract test blocks from TypeScript/JavaScript test files using tree-sitter. Handles Jest and Vitest patterns.
New file
src/specleft/discovery/miners/typescript/tests.py
import uuid
from specleft.discovery.models import SupportedLanguage, MinerResult, DiscoveredItem, ItemKind, TestFunctionMeta
from specleft.discovery.context import MinerContext
class TypeScriptTestMiner:
miner_id = uuid.UUID("aa5151b6-3805-419c-a726-a56755300dda")
name = "typescript_test_functions"
languages = frozenset({SupportedLanguage.TYPESCRIPT, SupportedLanguage.JAVASCRIPT})
def mine(self, ctx: MinerContext) -> MinerResult: ...Detection rules
File targeting: use ctx.file_index.files_matching("*.test.ts", "*.spec.ts", "*.test.js", "*.spec.js", "*.test.tsx", "*.spec.tsx") — do NOT walk the filesystem directly.
Tree-sitter query (via ctx.registry.parse(file_path)): call expressions where callee name is it or test. For nested describe("name", () => { it("name", ...) }), capture the describe block name.
Framework detection: read from ctx.frameworks.get(SupportedLanguage.TYPESCRIPT, []) or ctx.frameworks.get(SupportedLanguage.JAVASCRIPT, []) — do NOT re-parse package.json.
Typed metadata
Each item's metadata dict must conform to TestFunctionMeta:
TestFunctionMeta(
framework = "jest", # from ctx.frameworks
class_name = "Auth", # describe block name → class_name field
call_style = "it",
has_todo = False,
has_docstring = False,
is_parametrized = False,
)name: the string literal passed to it() / test() (e.g. "returns 401 for invalid token")
language: SupportedLanguage.TYPESCRIPT or SupportedLanguage.JAVASCRIPT based on file extension
confidence: 0.9 for known framework + .spec. filename; 0.7 otherwise
Acceptance criteria
-
describe("Auth", () => { it("logs in valid user", ...) })→ item withname="logs in valid user",class_name="Auth"in metadata -
.tsfiles getlanguage=SupportedLanguage.TYPESCRIPT;.jsfiles getSupportedLanguage.JAVASCRIPT - Each item's
metadatavalidates againstTestFunctionMeta -
it.todo("pending test")→has_todo=True -
test("does thing", async () => {})→call_style="test" - Uses
ctx.file_index.files_matching()— does not walk filesystem - Uses
ctx.frameworks— does not re-parsepackage.json - Tests in
tests/discovery/miners/test_typescript_tests.py - Update scenarios and tests in
features/feature-spec-discovery.mdto cover the functionality introduced by this issue