Skip to content

Development Guide

This guide walks you through setting up your environment, building the project, running tests, and generating documentation for typstyle.

Prerequisites

  • Rust (stable toolchain) with cargo.
  • Node.js and yarn (for web assets, if modifying web/)

Initial Setup

To build Typstyle CLI:

1
2
3
4
5
6
git clone https://github.com/Enter-tainer/typstyle.git
cd typstyle
# Debug
cargo build
# Release
cargo build --release

To run tests, you need to install cargo-nextest and cargo-insta.

Workspace Layout

  • crates/typstyle/ — formatter CLI
  • crates/typstyle-core/ — core formatting logic
  • crates/typstyle-consistency/ — framework for consistency tests
  • tests/ — code and fixtures for testing core library features
  • web/ — frontend demo

Running Tests

When you change the core library or fixtures, you need to update snapshots with insta.

When you change the CLI, you need to add or update tests in typstyle/tests. Specially, when you add a style arg, you need to write a testcase in test_style_args.rs to ensure it works.

  • List all tests:
1
cargo nextest list --workspace
  • Run all tests and review snapshots:
1
2
cargo nextest run --workspace --no-fail-fast
cargo insta review
  • Run snapshot tests only:
1
2
cargo nextest run --workspace -E 'test([snapshot])' --no-fail-fast --no-default-features
cargo insta review
  • Run tests excluding end-to-end (e2e):
1
cargo nextest run --workspace -E '!test([e2e])' --no-fail-fast
  • Run tests for CLI:
1
cargo nextest run -p typstyle --no-fail-fast

Snapshot Review

When snapshot tests change, review and accept updates:

1
2
3
cargo insta review
# or simply
cargo insta accept

Running Benchmarks

Benchmarks use Criterion.rs.

  • List benchmarks:
1
cargo bench --workspace -- --list
  • Run all benches:
1
cargo bench --workspace

You can check target/criterion/report to see the reports.