Skip to content

Commit c9b4db9

Browse files
committed
test(oxfmt): Rework test/cli tests (#21463)
Switch to a fixture-based testing approach, similar to apps/oxlint.
1 parent ce561a2 commit c9b4db9

300 files changed

Lines changed: 9467 additions & 4343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { join } from "node:path";
2+
import { describe, it } from "vitest";
3+
import { getFixtures, runFixture } from "./utils";
4+
5+
// oxlint-disable valid-title
6+
describe("oxfmt CLI", () => {
7+
const fixtures = getFixtures();
8+
9+
for (const fixture of fixtures) {
10+
// Concurrent across fixtures, sequential within (file writes may conflict)
11+
describe.concurrent(fixture.name, () => {
12+
for (let i = 0; i < fixture.testCases.length; i++) {
13+
const testCase = fixture.testCases[i];
14+
const cwd = testCase.cwd ? ` (cwd: ${testCase.cwd})` : "";
15+
const label = testCase.args.join(" ") + cwd;
16+
17+
it.sequential(label, async ({ expect }) => {
18+
const snapshotPath = join(fixture.dirPath, `${i}.snap.md`);
19+
const snapshot = await runFixture(fixture, testCase);
20+
await expect(snapshot).toMatchFileSnapshot(snapshotPath);
21+
});
22+
}
23+
});
24+
}
25+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check !*.{json,jsonc,ts}
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/ <CWD>
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/
17+
- .oxfmtrc.jsonc
18+
- deep/
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
Checking formatting...
30+
31+
nested/deep/test.js (<time>)
32+
33+
Format issues found in above 1 files. Run without `--check` to fix.
34+
Finished in <time> on 2 files using 1 threads.
35+
```
36+
37+
## stderr
38+
```
39+
40+
```
41+
42+
## File changes
43+
No changes
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check !*.{json,jsonc,ts}
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/ <CWD>
17+
- .oxfmtrc.jsonc
18+
- deep/
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
Checking formatting...
30+
31+
deep/test.js (<time>)
32+
33+
Format issues found in above 1 files. Run without `--check` to fix.
34+
Finished in <time> on 1 files using 1 threads.
35+
```
36+
37+
## stderr
38+
```
39+
40+
```
41+
42+
## File changes
43+
No changes
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check !*.{json,jsonc,ts}
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/
17+
- .oxfmtrc.jsonc
18+
- deep/ <CWD>
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
Checking formatting...
30+
31+
test.js (<time>)
32+
33+
Format issues found in above 1 files. Run without `--check` to fix.
34+
Finished in <time> on 1 files using 1 threads.
35+
```
36+
37+
## stderr
38+
```
39+
40+
```
41+
42+
## File changes
43+
No changes
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check !*.{json,jsonc,ts} --config ./fmt.json
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/ <CWD>
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/
17+
- .oxfmtrc.jsonc
18+
- deep/
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
Checking formatting...
30+
31+
nested/deep/test.js (<time>)
32+
33+
Format issues found in above 1 files. Run without `--check` to fix.
34+
Finished in <time> on 1 files using 1 threads.
35+
```
36+
37+
## stderr
38+
```
39+
40+
```
41+
42+
## File changes
43+
No changes
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check !*.{json,jsonc,ts} --config ./fmt.jsonc
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/ <CWD>
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/
17+
- .oxfmtrc.jsonc
18+
- deep/
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
Checking formatting...
30+
31+
nested/deep/test.js (<time>)
32+
33+
Format issues found in above 1 files. Run without `--check` to fix.
34+
Finished in <time> on 1 files using 1 threads.
35+
```
36+
37+
## stderr
38+
```
39+
40+
```
41+
42+
## File changes
43+
No changes
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check !*.{json,jsonc,ts} --config ./fmt.config.ts
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/ <CWD>
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/
17+
- .oxfmtrc.jsonc
18+
- deep/
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
Checking formatting...
30+
31+
nested/deep/test.js (<time>)
32+
33+
Format issues found in above 1 files. Run without `--check` to fix.
34+
Finished in <time> on 1 files using 1 threads.
35+
```
36+
37+
## stderr
38+
```
39+
40+
```
41+
42+
## File changes
43+
No changes
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Input
2+
3+
## Command
4+
```
5+
oxfmt --check --config NOT_EXISTS.json
6+
```
7+
8+
## File tree
9+
```
10+
- fixtures/ <CWD>
11+
- .oxfmtrc.json
12+
- .oxfmtrc.jsonc
13+
- fmt.config.ts
14+
- fmt.json
15+
- fmt.jsonc
16+
- nested/
17+
- .oxfmtrc.jsonc
18+
- deep/
19+
- test.js
20+
```
21+
22+
# Result
23+
24+
## Exit code
25+
1
26+
27+
## stdout
28+
```
29+
30+
```
31+
32+
## stderr
33+
```
34+
Failed to load configuration file.
35+
Failed to read <cwd>/NOT_EXISTS.json: File not found
36+
```
37+
38+
## File changes
39+
No changes

0 commit comments

Comments
 (0)