core

module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: MIT

README

specvital-core

Test file parser library for multiple test frameworks.

Features

  • Multi-framework support: Jest, Vitest, Playwright, Go testing
  • Parallel processing: Concurrent file scanning with configurable worker pool
  • Tree-sitter based: Accurate AST parsing for JavaScript, TypeScript, and Go
  • Performance optimized: Parser pooling and query caching

Installation

go get github.com/specvital/core

Quick Start

package main

import (
    "context"
    "fmt"

    "github.com/specvital/core/pkg/parser"

    // Import strategies to register them
    _ "github.com/specvital/core/pkg/parser/strategies/gotesting"
    _ "github.com/specvital/core/pkg/parser/strategies/jest"
    _ "github.com/specvital/core/pkg/parser/strategies/playwright"
    _ "github.com/specvital/core/pkg/parser/strategies/vitest"
)

func main() {
    ctx := context.Background()

    result, err := parser.Scan(ctx, "./my-project")
    if err != nil {
        panic(err)
    }

    fmt.Printf("Found %d test files with %d tests\n",
        len(result.Inventory.Files),
        result.Inventory.CountTests())
}

API Reference

Scan

Scans a directory for test files and parses them.

result, err := parser.Scan(ctx, rootPath,
    parser.WithWorkers(4),               // Parallel workers (default: GOMAXPROCS)
    parser.WithTimeout(2*time.Minute),   // Scan timeout (default: 5 minutes)
    parser.WithExclude([]string{"fixtures"}), // Additional skip directories
    parser.WithScanPatterns([]string{"**/*.test.ts"}), // Glob patterns to filter
)
DetectTestFiles

Detects test files without parsing.

result, err := parser.DetectTestFiles(ctx, rootPath,
    parser.WithPatterns([]string{"src/**/*.spec.ts"}),
    parser.WithMaxFileSize(5*1024*1024), // 5MB max
    parser.WithSkipPatterns([]string{"node_modules", ".git"}),
)

Supported Test Patterns

Framework File Patterns Test Functions
Jest *.test.ts, *.spec.ts, __tests__/* describe, it, test
Vitest Same as Jest + vitest.config.ts describe, it, test
Playwright *.test.ts + playwright.config.ts test, test.describe
Go *_test.go func TestXxx, t.Run

Data Structures

Inventory
type Inventory struct {
    RootPath string     // Scanned directory
    Files    []TestFile // Parsed test files
}
TestFile
type TestFile struct {
    Path      string      // File path
    Framework string      // "jest", "vitest", "playwright", "go"
    Language  Language    // "typescript", "javascript", "go"
    Suites    []TestSuite // Test suites (describe blocks)
    Tests     []Test      // Top-level tests
}
TestSuite
type TestSuite struct {
    Name     string      // Suite name
    Location Location    // Source location
    Status   TestStatus  // "", "skipped", "only", etc.
    Suites   []TestSuite // Nested suites
    Tests    []Test      // Tests in this suite
}
Test
type Test struct {
    Name     string     // Test name
    Location Location   // Source location
    Status   TestStatus // "", "skipped", "only", "pending", "fixme"
}

Performance

  • Parser pooling via sync.Pool for concurrent parsing
  • Query compilation caching for repeated tree-sitter queries
  • Configurable worker count for parallel file processing
  • Context-based cancellation and timeout support

Development

Running Tests
# Unit tests only
just test unit

# Integration tests (clones real GitHub repos)
just test integration

# All tests
just test
Integration Tests

Integration tests validate the parser against real open-source repositories:

  • Single-framework repos: testing-library/react, vite, playwright, gin
  • Complex cases: next.js, storybook, turborepo, grafana, trpc, prisma, remix, etcd

Repositories are shallow-cloned and cached in tests/integration/testdata/cache/.

To update golden snapshots after parser changes:

go test -tags integration ./tests/integration/... -update

License

MIT

Directories

Path Synopsis
pkg
domain
Package domain defines the core types for test file representation.
Package domain defines the core types for test file representation.
parser/framework
Package framework provides a unified framework definition system for test framework detection and parsing.
Package framework provides a unified framework definition system for test framework detection and parsing.
parser/framework/matchers
Package matchers provides reusable matcher implementations for framework detection.
Package matchers provides reusable matcher implementations for framework detection.
parser/strategies/all
Package all imports all parser strategies for side-effect registration.
Package all imports all parser strategies for side-effect registration.
parser/strategies/cargotest
Package cargotest implements Rust cargo test framework support.
Package cargotest implements Rust cargo test framework support.
parser/strategies/junit5
Package junit5 implements JUnit 5 (Jupiter) test framework support for Java test files.
Package junit5 implements JUnit 5 (Jupiter) test framework support for Java test files.
parser/strategies/nunit
Package nunit implements NUnit test framework support for C# test files.
Package nunit implements NUnit test framework support for C# test files.
parser/strategies/rspec
Package rspec implements RSpec test framework support for Ruby test files.
Package rspec implements RSpec test framework support for Ruby test files.
parser/strategies/shared/dotnetast
Package dotnetast provides shared C# AST traversal utilities for .NET test framework parsers.
Package dotnetast provides shared C# AST traversal utilities for .NET test framework parsers.
parser/strategies/shared/javaast
Package javaast provides shared Java AST traversal utilities for test framework parsers.
Package javaast provides shared Java AST traversal utilities for test framework parsers.
parser/strategies/shared/pyast
Package pyast provides shared Python AST traversal utilities for test framework parsers.
Package pyast provides shared Python AST traversal utilities for test framework parsers.
parser/strategies/shared/rubyast
Package rubyast provides utilities for working with Ruby AST nodes.
Package rubyast provides utilities for working with Ruby AST nodes.
parser/strategies/xunit
Package xunit implements xUnit test framework support for C# test files.
Package xunit implements xUnit test framework support for C# test files.
parser/tspool
Package tspool provides tree-sitter parsers for concurrent parsing.
Package tspool provides tree-sitter parsers for concurrent parsing.
source
Package source provides abstractions for reading files from various data sources.
Package source provides abstractions for reading files from various data sources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL