Skip to content

studyplus/test-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test-filter

A smart test filtering tool that defines component usage relationships and runs tests based on those relationships, with specific support for MVC architecture patterns.

Overview

The test-filter tool is designed to optimize CI/CD pipelines by intelligently determining which tests need to be executed based on the files that have changed in a pull request. Instead of running all tests for every change, it analyzes the relationships between different components of your application and only runs the tests that are potentially affected by the changes.

How It Works

The tool operates by:

  1. Component Type Definition: Application files are categorized into component types (e.g., model_type, view_type, controller_type) based on their file paths
  2. Dependency Mapping: Component types can declare dependencies on other component types using the uses field
  3. Change Analysis: When files are modified, the tool determines which component types are affected
  4. Test Selection: Using a dependency graph, it identifies which test component types need to be executed
  5. Test Execution: Only the necessary tests are run, significantly reducing CI execution time

Configuration

The tool is configured using a YAML file (typically .circleci/test-filter.yml) with the following structure:

Basic Configuration

Application Component Types

Define how your application files are categorized:

Test Component Types

Define how your test files are categorized:

test_path_pattern: spec/**/*_spec.rb
base_branch: main

ignores:
  - README.md

app_component_types:
  - name: model_type
    paths:
      - app/models/
      - app/forms/
  - name: view_type
    paths:
      - app/views/
      - app/assets/
      - app/helpers/
  - name: controller_type
    paths:
      - app/controllers/
  - name: job_type
    paths:
      - app/jobs/
      - lib/tasks/

test_component_types:
  - name: test_model_type
    paths:
      - spec/models/
      - spec/forms/
  - name: test_view_type
    paths:
      - spec/helpers/
  - name: test_controller_type
    paths:
      - spec/controllers/
      - spec/requests/
  - name: test_job_type
    paths:
      - spec/jobs/
      - spec/tasks/

Advanced Path Patterns

You can use regular expressions for more complex matching:

test_component_types:
  - name: test_model_type
    paths:
      - spec/models/
      - format: regexp
        value: spec/gateways/.*?course_.*+_spec.rb

Usage Examples

Basic Usage

# Run the test filter with a configuration file
# ./bin/test_filter_run.sh [config-yml-path] [test-command]
./bin/test_filter_run.sh .circleci/test-filter.yml circleci tests run ...

Integration with CircleCI

The tool is designed to integrate seamlessly with CircleCI workflows:

# In your .circleci/config.yml
- run:
    name: Run filtered tests
    command: |
      .circleci/test-filter/bin/test_filter_run.sh \
        .circleci/test-filter.yml \
        circleci tests run

Current Status

⚠️ Note: This tool is currently in active development. The following features are planned but not yet implemented:

  • Orb Integration: CircleCI Orb packaging for easier reuse across projects
  • GitHub Actions Support: Native GitHub Actions integration and marketplace publication

The tool is currently embedded directly in the repository and must be copied manually to other projects.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published