core

module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 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
)

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/gtest
Package gtest implements Google Test framework support for C++ test files.
Package gtest implements Google Test framework support for C++ test files.
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/kotest
Package kotest implements Kotest test framework support for Kotlin test files.
Package kotest implements Kotest test framework support for Kotlin test files.
parser/strategies/minitest
Package minitest implements Minitest test framework support for Ruby test files.
Package minitest implements Minitest test framework support for Ruby test files.
parser/strategies/mstest
Package mstest implements MSTest framework support for C# test files.
Package mstest implements MSTest framework support for C# 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/phpunit
Package phpunit implements PHPUnit test framework support for PHP test files.
Package phpunit implements PHPUnit test framework support for PHP 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/configutil
Package configutil provides shared utilities for parsing framework config files.
Package configutil provides shared utilities for parsing framework config 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/kotlinast
Package kotlinast provides shared Kotlin AST traversal utilities for test framework parsers.
Package kotlinast provides shared Kotlin AST traversal utilities for test framework parsers.
parser/strategies/shared/phpast
Package phpast provides shared PHP AST traversal utilities for test framework parsers.
Package phpast provides shared PHP 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/shared/swiftast
Package swiftast provides shared Swift AST traversal utilities for test framework parsers.
Package swiftast provides shared Swift AST traversal utilities for test framework parsers.
parser/strategies/testng
Package testng implements TestNG test framework support for Java test files.
Package testng implements TestNG test framework support for Java test files.
parser/strategies/xctest
Package xctest implements XCTest framework support for Swift test files.
Package xctest implements XCTest framework support for Swift test files.
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