Skip to content

Commit cd97e2a

Browse files
committed
Keep oxlint plugin fixtures off the test glob
1 parent ffec09d commit cd97e2a

1 file changed

Lines changed: 37 additions & 27 deletions

File tree

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, test } from "bun:test";
22
import { mkdtemp, rm, writeFile } from "node:fs/promises";
3+
import { tmpdir } from "node:os";
34
import { join } from "node:path";
45

56
const repoRoot = join(import.meta.dirname, "../..");
@@ -34,40 +35,49 @@ function findingsForRule(stdout: string): unknown[] {
3435
return (parsed.diagnostics ?? []).filter((item) => item.code === ruleCode);
3536
}
3637

37-
test("oxlint reports bare mock.module in a *.test.ts file", async () => {
38-
const dir = await mkdtemp(
39-
join(import.meta.dirname, "oxlint-mock-module-banned-"),
40-
);
41-
const file = join(dir, "banned.test.ts");
38+
// bun test ./tests collects leftover *.test.ts under tests/; keep fixtures off that glob.
39+
async function withFixture(
40+
prefix: string,
41+
name: string,
42+
source: string,
43+
run: (file: string) => Promise<void>,
44+
): Promise<void> {
45+
const dir = await mkdtemp(join(tmpdir(), prefix));
46+
const file = join(dir, name);
4247
try {
43-
await writeFile(
44-
file,
45-
`import { mock } from "bun:test";
46-
mock.module("./example.js", () => ({}));
47-
`,
48-
);
49-
const { stdout, stderr } = await runOxlint(file);
50-
expect(findingsForRule(stdout).length, stderr || stdout).toBeGreaterThan(0);
48+
await writeFile(file, source);
49+
await run(file);
5150
} finally {
5251
await rm(dir, { recursive: true, force: true });
5352
}
53+
}
54+
55+
test("oxlint reports bare mock.module in a *.test.ts file", async () => {
56+
await withFixture(
57+
"oxlint-mock-module-banned-",
58+
"banned.test.ts",
59+
`import { mock } from "bun:test";
60+
mock.module("./example.js", () => ({}));
61+
`,
62+
async (file) => {
63+
const { stdout, stderr } = await runOxlint(file);
64+
expect(findingsForRule(stdout).length, stderr || stdout).toBeGreaterThan(
65+
0,
66+
);
67+
},
68+
);
5469
});
5570

5671
test("oxlint is clean when a *.test.ts file only uses withMockedModule", async () => {
57-
const dir = await mkdtemp(
58-
join(import.meta.dirname, "oxlint-mock-module-clean-"),
59-
);
60-
const file = join(dir, "clean.test.ts");
61-
try {
62-
await writeFile(
63-
file,
64-
`import { withMockedModule } from "../helpers/mock-module.ts";
72+
await withFixture(
73+
"oxlint-mock-module-clean-",
74+
"clean.test.ts",
75+
`import { withMockedModule } from "../helpers/mock-module.ts";
6576
await withMockedModule("./example.js", () => ({}));
6677
`,
67-
);
68-
const { stdout, stderr } = await runOxlint(file);
69-
expect(findingsForRule(stdout), stderr || stdout).toEqual([]);
70-
} finally {
71-
await rm(dir, { recursive: true, force: true });
72-
}
78+
async (file) => {
79+
const { stdout, stderr } = await runOxlint(file);
80+
expect(findingsForRule(stdout), stderr || stdout).toEqual([]);
81+
},
82+
);
7383
});

0 commit comments

Comments
 (0)