Skip to content

Conversation

Dunqing
Copy link
Member

@Dunqing Dunqing commented Oct 7, 2025

Implement a flexible snapshot-based testing framework for oxc_formatter using insta and build-time test generation.

Features

  • Auto-discovery: Tests are automatically discovered from tests/fixtures/ directory
  • Individual test functions: Each fixture file gets its own test function for easy identification
  • Hierarchical options: Support for options.json files at any directory level
  • Multiple option sets: Test the same input with multiple formatting configurations
  • Co-located snapshots: Snapshot files are stored next to test files (e.g., foo.js.snap)
  • Comprehensive README: Detailed documentation for adding and running tests

Implementation

  • build.rs: Scans tests/fixtures/ and generates test functions at build time
  • tests/fixtures/mod.rs: Core test infrastructure with option resolution and snapshot generation
  • tests/README.md: Complete guide for using the test framework
  • Sample tests: Example tests demonstrating JS, JSX, TS, and nested configurations

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

@github-actions github-actions bot added A-formatter Area - Formatter C-test Category - Testing. Code is missing test cases, or a PR is adding them labels Oct 7, 2025
Copy link
Member Author

Dunqing commented Oct 7, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

codspeed-hq bot commented Oct 7, 2025

CodSpeed Performance Report

Merging #14400 will not alter performance

Comparing feat/formatter-snapshot-tests (bb43dc5) with main (9965676)1

Summary

✅ 33 untouched
⏩ 4 skipped2

Footnotes

  1. No successful run was found on main (33b6cde) during the generation of this report, so 9965676 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Dunqing Dunqing force-pushed the feat/formatter-snapshot-tests branch 3 times, most recently from 4209748 to 2b6089c Compare October 9, 2025 02:55
@Dunqing Dunqing marked this pull request as ready for review October 9, 2025 03:42
@Dunqing Dunqing requested review from Copilot and leaysgur October 9, 2025 03:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive snapshot-based testing framework for oxc_formatter using insta and build-time test generation. The framework enables automatic test discovery from fixture files and supports hierarchical configuration through options.json files.

Key changes include:

  • Build-time test generation that scans tests/fixtures/ and creates individual test functions
  • Core test infrastructure with option resolution and snapshot generation capabilities
  • Comprehensive documentation explaining how to add and use the test framework

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/oxc_formatter/tests/mod.rs Adds module declaration for fixtures test infrastructure
crates/oxc_formatter/tests/fixtures/mod.rs Core test infrastructure implementing option parsing, formatting, and snapshot generation
crates/oxc_formatter/tests/README.md Complete documentation guide for using the test framework
crates/oxc_formatter/build.rs Build script that discovers test files and generates test functions at compile time
crates/oxc_formatter/Cargo.toml Adds required dev dependencies for snapshot testing and JSON parsing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Dunqing Dunqing force-pushed the feat/formatter-snapshot-tests branch from 2b6089c to ac1df86 Compare October 9, 2025 06:23
Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented mainly about how to handle options. 👀

Copy link
Contributor

graphite-app bot commented Oct 12, 2025

Merge activity

Implement a flexible snapshot-based testing framework for oxc_formatter using `insta` and build-time test generation.

## Features

- **Auto-discovery**: Tests are automatically discovered from `tests/fixtures/` directory
- **Individual test functions**: Each fixture file gets its own test function for easy identification
- **Hierarchical options**: Support for `options.json` files at any directory level
- **Multiple option sets**: Test the same input with multiple formatting configurations
- **Co-located snapshots**: Snapshot files are stored next to test files (e.g., `foo.js.snap`)
- **Comprehensive README**: Detailed documentation for adding and running tests

## Implementation

- **build.rs**: Scans `tests/fixtures/` and generates test functions at build time
- **tests/fixtures/mod.rs**: Core test infrastructure with option resolution and snapshot generation
- **tests/README.md**: Complete guide for using the test framework
- **Sample tests**: Example tests demonstrating JS, JSX, TS, and nested configurations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@graphite-app graphite-app bot force-pushed the feat/formatter-snapshot-tests branch from 60d99a2 to bb43dc5 Compare October 12, 2025 15:55
@graphite-app graphite-app bot merged commit bb43dc5 into main Oct 12, 2025
27 checks passed
@graphite-app graphite-app bot deleted the feat/formatter-snapshot-tests branch October 12, 2025 16:01
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Oct 12, 2025
@Boshen Boshen mentioned this pull request Oct 14, 2025
leaysgur added a commit that referenced this pull request Oct 14, 2025
## [0.5.0] - 2025-10-14

### 🚀 Features

- 8077f9b oxfmt: Provide JSON schema for `.oxfmtrc.json` (#14399)
(leaysgur)
- 51ddfa8 oxfmt: Support `.oxfmtrc.json(c)` config file (#14398)
(leaysgur)

### 🐛 Bug Fixes

- c4e12df formatter: Correct checking comments around the return
argument (#14585) (Dunqing)
- 454303b formatter: Check empty lines between arguments incorrectly
(#14584) (Dunqing)
- a5554a8 formatter: Print a line break incorrectly for directives
(#14577) (Dunqing)
- 5db9774 formatter: Correct printing comments that are around the
`StaticMemberExpression` (#14543) (Dunqing)
- 620dbac formatter: No need to wrap a parenthesis for
`TSConditionalType` and `TSFunctionType` when its parent is
`TSUnionType` and it only has one element (#14540) (Dunqing)
- 1aec74f formatter: Missing parenthesis for `ComputedMemberExpression`
when its parent is an `NewExpression` (#14530) (Dunqing)
- 59f1d8f formatter: Missing parenthesis for `PrivateInExpression` when
its parent is an `UnaryExpression` (#14529) (Dunqing)
- b06059e formatter: Correct printing comments for logical expression
(#14500) (Dunqing)
- be38095 formatter: Should break even if the right side of the
assignment is a require when it has a leading own line comment (#14499)
(Dunqing)
- 4d55654 formatter: Correct printing comments for the end of union type
(#14498) (Dunqing)
- 4994872 formatter: Correct printing comments for `try` statement
(#14497) (Dunqing)
- 9a4da3d formatter: Should expand the parent if the member chain will
break (#14487) (Dunqing)
- bba9689 formatter: Correct printing comments around the expression of
`ComputedMemberExpression` (#14486) (Dunqing)
- dc5e08a formatter: Correct printing yield argument (#14485) (Dunqing)
- b8a0905 formatter: No need to wrap with parentheses for a type cast
node (#14484) (Dunqing)
- b159215 formatter: Ignore the leading line break for the first
argument of the call expression (#14483) (Dunqing)
- ea8f9ed formatter: Correct checking comments between the operator and
the right side for assignment like nodes (#14482) (Dunqing)
- 4f19504 formatter: Block comments without a leading linebreak that are
around the operator of the conditional expression should be printed
as-is (#14474) (Dunqing)
- ef77997 formatter: Correct printing comments for `for` statements
(#14473) (Dunqing)
- 31595c3 formatter: Correct printing comments for assignment pattern
(#14469) (Dunqing)
- 0f19be0 oxfmt: Normalize path delimiter on Windows (#14463) (leaysgur)
- 5856bc9 oxc_formatter: Fix arrow_parentheses: 'avoid' > 'as-needed'
(#14462) (leaysgur)

### 🚜 Refactor

- 7bc86f4 formatter: Simplify foramtting import and export (#14576)
(Dunqing)
- 29c3cf2 formatter: Remove `SiblingNode` (#14551) (Dunqing)
- 893bdac formatter: Improve printing comments for special nodes
(#14544) (Dunqing)
- 97bb964 formatter: Improve line break detaching logic in SourceText
(#14539) (Dunqing)

### 🧪 Testing

- bb43dc5 formatter: Add snapshot-based test infrastructure (#14400)
(Dunqing)

Co-authored-by: leaysgur <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants