Skip to content

Commit 61ec7ae

Browse files
authored
test: Ensure all rules are exported (eslint#8)
1 parent dc553c4 commit 61ec7ae

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

tests/package/exports.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
import * as exports from "../../src/index.js";
1111
import assert from "node:assert";
1212

13+
import path from "node:path";
14+
import fs from "node:fs/promises";
15+
import { fileURLToPath, pathToFileURL } from "node:url";
16+
17+
//-----------------------------------------------------------------------------
18+
// Helpers
19+
//-----------------------------------------------------------------------------
20+
21+
const filename = fileURLToPath(import.meta.url);
22+
const dirname = path.dirname(filename);
23+
const rulesDir = path.resolve(dirname, "../../src/rules");
24+
1325
//------------------------------------------------------------------------------
1426
// Tests
1527
//------------------------------------------------------------------------------
@@ -24,6 +36,32 @@ describe("Package exports", () => {
2436
]);
2537
});
2638

39+
it("has all available rules exported in the ESLint plugin", async () => {
40+
const allRules = (await fs.readdir(rulesDir))
41+
.filter(name => name.endsWith(".js"))
42+
.map(name => name.slice(0, -".js".length))
43+
.sort();
44+
const exportedRules = exports.default.rules;
45+
46+
assert.deepStrictEqual(
47+
Object.keys(exportedRules).sort(),
48+
allRules,
49+
"Expected all rules to be exported in the ESLint plugin (`plugin.rules` in `src/index.js`)",
50+
);
51+
52+
for (const [ruleName, rule] of Object.entries(exportedRules)) {
53+
assert.strictEqual(
54+
rule,
55+
(
56+
await import(
57+
pathToFileURL(path.resolve(rulesDir, `${ruleName}.js`))
58+
)
59+
).default,
60+
`Expected ${ruleName}.js to be exported under key "${ruleName}" in the ESLint plugin (\`plugin.rules\` in \`src/index.js\`)`,
61+
);
62+
}
63+
});
64+
2765
it("has a CSSLanguage export", () => {
2866
assert.ok(exports.CSSLanguage);
2967
});

tests/plugin/eslint.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ import assert from "node:assert";
1818
//-----------------------------------------------------------------------------
1919

2020
describe("Plugin", () => {
21+
describe("Plugin configs", () => {
22+
Object.keys(css.configs).forEach(configName => {
23+
it(`Using "${configName}" config should not throw`, async () => {
24+
const config = {
25+
files: ["**/*.css"],
26+
language: "css/css",
27+
...css.configs[configName],
28+
};
29+
30+
const eslint = new ESLint({
31+
overrideConfigFile: true,
32+
overrideConfig: config,
33+
});
34+
35+
await eslint.lintText("div {}", { filePath: "test.css" });
36+
});
37+
});
38+
});
39+
2140
describe("Configuration Comments", () => {
2241
const config = {
2342
files: ["*.css"],

0 commit comments

Comments
 (0)