Skip to content

Commit 68f9aa1

Browse files
committed
Dynamically generate config test cases
1 parent 11d7ce8 commit 68f9aa1

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

test/config.test.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,17 @@ describe("Recommended config", () => {
1818
};
1919
`;
2020

21-
const runLintTest = async (eslintInstance, code) => {
22-
const results = await eslintInstance.lintText(code);
23-
24-
assert.strictEqual(results.length, 1);
25-
assert.ok(results[0].messages);
26-
assert.ok(
27-
results[0].messages.some(
28-
(message) =>
29-
message.ruleId ===
30-
"react-you-might-not-need-an-effect/you-might-not-need-an-effect",
31-
),
32-
);
33-
};
34-
35-
it("Flat", async () => {
36-
await runLintTest(
37-
new ESLint({
21+
const testCases = [
22+
{
23+
name: "Flat",
24+
eslint: new ESLint({
3825
// Use `overrideConfig` so it ignores the project's config
3926
overrideConfig: [plugin.configs.recommended],
4027
}),
41-
code,
42-
);
43-
});
44-
45-
it("Legacy", async () => {
46-
await runLintTest(
47-
new LegacyESLint({
28+
},
29+
{
30+
name: "Legacy",
31+
eslint: new LegacyESLint({
4832
overrideConfig: {
4933
extends: [
5034
"plugin:react-you-might-not-need-an-effect/legacy-recommended",
@@ -56,7 +40,22 @@ describe("Recommended config", () => {
5640
},
5741
},
5842
}),
59-
code,
60-
);
43+
},
44+
];
45+
46+
testCases.forEach(({ name, eslint }) => {
47+
it(name, async () => {
48+
const results = await eslint.lintText(code);
49+
50+
assert.strictEqual(results.length, 1);
51+
assert.ok(results[0].messages);
52+
assert.ok(
53+
results[0].messages.some(
54+
(message) =>
55+
message.ruleId ===
56+
"react-you-might-not-need-an-effect/you-might-not-need-an-effect",
57+
),
58+
);
59+
});
6160
});
6261
});

0 commit comments

Comments
 (0)