Skip to content

Commit 5900d23

Browse files
committed
test(oxfmt): Misc refactors (#21484)
- Simplify sort_imports test - Add note comment to stdin_pipe test - Update AGENTS.md
1 parent c22cba6 commit 5900d23

File tree

9 files changed

+53
-34
lines changed

9 files changed

+53
-34
lines changed

apps/oxfmt/AGENTS.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,35 @@ npx prettier --config=fmt.json <file>
8080

8181
## Test Organization (`test/` directory)
8282

83-
Tests are organized by domain and colocated with strict structural rules.
84-
85-
- 1:1:1 Rule: Each test directory contains exactly
86-
- 1 test file (`*.test.ts` with the same name with directory)
87-
- 0 or 1 `fixtures/` directory (if needed)
88-
- Snapshots are colocated automatically by Vitest
89-
- No Upward References (except `utils.ts` and `oxfmt` binary)
90-
- Test files may only reference:
91-
- Files within their own directory
92-
- Shared `utils.ts` in parent directories
93-
94-
When adding new tests:
95-
96-
- Place test in the appropriate domain directory
97-
- If the test needs fixtures, create a `fixtures/` subdirectory
98-
- If multiple test cases share a fixture structure, use subdirectories within `fixtures/` (e.g., `fixtures/basic/`, `fixtures/nested/`)
83+
Tests are organized into specific domains, each with its own structure.
84+
85+
### `test/api/`: Formatting result tests
86+
87+
Focuses on verifying formatting output. Use the Node.js API. No fixtures, test inputs are inline in each test file.
88+
89+
- Multiple `*.test.ts` files coexist in a flat directory (no subdirectories)
90+
- Snapshots are colocated in `__snapshots__/` by Vitest
91+
92+
### `test/cli/`: CLI fixture-driven tests
93+
94+
A single `cli.test.ts` auto-discovers and runs all fixture directories via `utils.ts`.
95+
96+
- Each fixture directory contains:
97+
- `options.json` — array of test cases (args, cwd, env, stdin, etc.)
98+
- `fixtures/` — input files for the test cases
99+
- `*.snap.md` — file snapshots (one per test case, named `0.snap.md`, `1.snap.md`, …)
100+
- Adding a new CLI test: create a new directory with `options.json` and `fixtures/`, then run the test to generate snapshots
101+
- If exceptional test cases are required, place a separate `*.test.ts` file for them
102+
103+
### `test/lsp/`: LSP integration tests
104+
105+
Each test directory follows the 1:1:1 rule:
106+
107+
- 1 test file (`*.test.ts` with the same name as the directory)
108+
- 0 or 1 `fixtures/` directory
109+
- Snapshots are colocated in `__snapshots__/` by Vitest
110+
111+
Shared helpers are in `utils.ts` at the `test/lsp/` level.
99112

100113
## After updating `Oxfmtrc` (Under `src/core/oxfmtrc`)
101114

apps/oxfmt/test/cli/sort_imports/0.snap.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
## Command
44
```
5-
oxfmt --check input.ts
5+
oxfmt --check --config custom_groups.json custom_groups.ts
66
```
77

88
## File tree
99
```
10-
- fixtures/
11-
- custom_groups/ <CWD>
12-
- .oxfmtrc.json
13-
- input.ts
14-
- custom_groups_selector_modifiers/
15-
- .oxfmtrc.json
16-
- input.ts
10+
- fixtures/ <CWD>
11+
- custom_groups_selector_modifiers.json
12+
- custom_groups_selector_modifiers.ts
13+
- custom_groups.json
14+
- custom_groups.ts
1715
```
1816

1917
# Result

apps/oxfmt/test/cli/sort_imports/1.snap.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
## Command
44
```
5-
oxfmt --check input.ts
5+
oxfmt --check --config custom_groups_selector_modifiers.json custom_groups_selector_modifiers.ts
66
```
77

88
## File tree
99
```
10-
- fixtures/
11-
- custom_groups/
12-
- .oxfmtrc.json
13-
- input.ts
14-
- custom_groups_selector_modifiers/ <CWD>
15-
- .oxfmtrc.json
16-
- input.ts
10+
- fixtures/ <CWD>
11+
- custom_groups_selector_modifiers.json
12+
- custom_groups_selector_modifiers.ts
13+
- custom_groups.json
14+
- custom_groups.ts
1715
```
1816

1917
# Result

apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups/.oxfmtrc.json renamed to apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups.json

File renamed without changes.

apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups/input.ts renamed to apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups.ts

File renamed without changes.

apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups_selector_modifiers/.oxfmtrc.json renamed to apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups_selector_modifiers.json

File renamed without changes.

apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups_selector_modifiers/input.ts renamed to apps/oxfmt/test/cli/sort_imports/fixtures/custom_groups_selector_modifiers.ts

File renamed without changes.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
[
2-
{ "cwd": "custom_groups", "args": ["--check", "input.ts"] },
3-
{ "cwd": "custom_groups_selector_modifiers", "args": ["--check", "input.ts"] }
2+
{ "args": ["--check", "--config", "custom_groups.json", "custom_groups.ts"] },
3+
{
4+
"args": [
5+
"--check",
6+
"--config",
7+
"custom_groups_selector_modifiers.json",
8+
"custom_groups_selector_modifiers.ts"
9+
]
10+
}
411
]

apps/oxfmt/test/cli/stdin_pipe/stdin_pipe.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const FIXTURE = join(import.meta.dirname, "fixtures", "parser.ts");
77

88
// https://github.com/oxc-project/oxc/issues/17939
99
describe("stdin pipe", () => {
10+
// NOTE: This test uses Unix commands (`cat`, `wc`) via shell pipes.
11+
// On our Windows CI (GitHub Actions), these resolve from Git for Windows in PATH.
12+
// May fail on some Windows environments without Unix tools in PATH.
1013
it("should not report WouldBlock error on large file piped to wc", async () => {
1114
const cmd = `cat "${FIXTURE}" | node "${CLI_PATH}" --stdin-filepath=parser.ts | wc -l`;
1215
const result = await execa({ shell: true, reject: false })`${cmd}`;

0 commit comments

Comments
 (0)