Skip to content

Commit

Permalink
test: Ensure all rules are exported (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored Nov 13, 2024
1 parent dc553c4 commit 61ec7ae
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/package/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
import * as exports from "../../src/index.js";
import assert from "node:assert";

import path from "node:path";
import fs from "node:fs/promises";
import { fileURLToPath, pathToFileURL } from "node:url";

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const rulesDir = path.resolve(dirname, "../../src/rules");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
Expand All @@ -24,6 +36,32 @@ describe("Package exports", () => {
]);
});

it("has all available rules exported in the ESLint plugin", async () => {
const allRules = (await fs.readdir(rulesDir))
.filter(name => name.endsWith(".js"))
.map(name => name.slice(0, -".js".length))
.sort();
const exportedRules = exports.default.rules;

assert.deepStrictEqual(
Object.keys(exportedRules).sort(),
allRules,
"Expected all rules to be exported in the ESLint plugin (`plugin.rules` in `src/index.js`)",
);

for (const [ruleName, rule] of Object.entries(exportedRules)) {
assert.strictEqual(
rule,
(
await import(
pathToFileURL(path.resolve(rulesDir, `${ruleName}.js`))
)
).default,
`Expected ${ruleName}.js to be exported under key "${ruleName}" in the ESLint plugin (\`plugin.rules\` in \`src/index.js\`)`,
);
}
});

it("has a CSSLanguage export", () => {
assert.ok(exports.CSSLanguage);
});
Expand Down
19 changes: 19 additions & 0 deletions tests/plugin/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ import assert from "node:assert";
//-----------------------------------------------------------------------------

describe("Plugin", () => {
describe("Plugin configs", () => {
Object.keys(css.configs).forEach(configName => {
it(`Using "${configName}" config should not throw`, async () => {
const config = {
files: ["**/*.css"],
language: "css/css",
...css.configs[configName],
};

const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: config,
});

await eslint.lintText("div {}", { filePath: "test.css" });
});
});
});

describe("Configuration Comments", () => {
const config = {
files: ["*.css"],
Expand Down

0 comments on commit 61ec7ae

Please sign in to comment.