Skip to content

Commit

Permalink
Add tests for docs (#94)
Browse files Browse the repository at this point in the history
* Add test for exported rules

* Add test for exported configs

* Write tests for docs
  • Loading branch information
igorkamyshev authored Apr 5, 2022
1 parent 43c4d53 commit 06d6583
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 16 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.10.0
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,43 @@ To configure individual rules:
}
```

### Available presets
### Available rules by preset

#### plugin:effector/recommended

This preset is recommended for most projects.

- [effector/enforce-store-naming-convention](rules/enforce-store-naming-convention/enforce-store-naming-convention.md)
- [effector/enforce-effect-naming-convention](rules/enforce-effect-naming-convention/enforce-effect-naming-convention.md)
- [effector/no-getState](rules/no-getState/no-getState.md)
- [effector/no-useless-methods](rules/no-useless-methods/no-useless-methods.md)
- [effector/no-unnecessary-duplication](rules/no-unnecessary-duplication/no-unnecessary-duplication.md)
- [effector/prefer-sample-over-forward-with-mapping](rules/prefer-sample-over-forward-with-mapping/prefer-sample-over-forward-with-mapping.md)
- [effector/no-ambiguity-target](rules/no-ambiguity-target/no-ambiguity-target.md)
- [effector/no-watch](rules/no-watch/no-watch.md)
- [effector/no-unnecessary-combination](rules/no-unnecessary-combination/no-unnecessary-combination.md)
- [effector/no-duplicate-on](rules/no-duplicate-on/no-duplicate-on.md)
- [effector/keep-options-order](rules/keep-options-order/keep-options-order.md)

#### plugin:effector/scope

This preset is recommended for projects that use [Fork API](https://effector.dev/docs/api/effector/scope). You can read more about Fork API in [an article](https://dev.to/effector/the-best-part-of-effector-4c27).

- [effector/strict-effect-handlers](rules/strict-effect-handlers/strict-effect-handlers.md)

#### plugin:effector/react

This preset is recommended for projects that use [React](https://reactjs.org) with Effector.

- [effector/enforce-gate-naming-convention](rules/enforce-gate-naming-convention/enforce-gate-naming-convention.md)

#### plugin:effector/future

This preset contains rules wich enforce _future-effector_ code-style.

### Supported rules

- [effector/enforce-store-naming-convention](rules/enforce-store-naming-convention/enforce-store-naming-convention.md)
- [effector/enforce-effect-naming-convention](rules/enforce-effect-naming-convention/enforce-effect-naming-convention.md)
- [effector/enforce-gate-naming-convention](rules/enforce-gate-naming-convention/enforce-gate-naming-convention.md)
- [effector/no-unnecessary-duplication](rules/no-unnecessary-duplication/no-unnecessary-duplication.md)
- [effector/no-unnecessary-combination](rules/no-unnecessary-combination/no-unnecessary-combination.md)
- [effector/no-useless-methods](rules/no-useless-methods/no-useless-methods.md)
- [effector/prefer-sample-over-forward-with-mapping](rules/prefer-sample-over-forward-with-mapping/prefer-sample-over-forward-with-mapping.md)
- [effector/no-forward](rules/no-forward/no-forward.md)
- [effector/no-guard](rules/no-guard/no-guard.md)
- [effector/no-ambiguity-target](rules/no-ambiguity-target/no-ambiguity-target.md)
- [effector/no-duplicate-on](rules/no-duplicate-on/no-duplicate-on.md)
- [effector/no-getState](rules/no-getState/no-getState.md)
- [effector/no-watch](rules/no-watch/no-watch.md)
- [effector/prefer-sample-over-forward-with-mapping](rules/prefer-sample-over-forward-with-mapping/prefer-sample-over-forward-with-mapping.md)
- [effector/strict-effect-handlers](rules/strict-effect-handlers/strict-effect-handlers.md)
- [effector/keep-options-order](rules/keep-options-order/keep-options-order.md)

## Maintenance

Expand Down
84 changes: 84 additions & 0 deletions docs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { readFile, readdir } = require("fs/promises");
const { join } = require("path");

const plugin = require("./index");

describe("docs", () => {
test("any rule should have valid doc.md", async () => {
await Promise.all([
Object.entries(plugin.rules).map(async ([ruleName]) => {
const ruleFiles = await readdir(join(__dirname, "rules", ruleName));

// File exists
expect(ruleFiles).toContain(`${ruleName}.md`);

const ruleDocFile = await readFile(
join(__dirname, "rules", ruleName, `${ruleName}.md`),
"utf8"
);

// File has valid title
expect(ruleDocFile).toContain(`effector/${ruleName}`);
}),
]);
});

test("any rule should have like in main README.md", async () => {
const readmeContent = await readFile(join(__dirname, "README.md"), "utf8");

await Promise.all([
Object.entries(plugin.rules).map(async ([ruleName]) => {
// Link exists
expect(readmeContent).toContain(
`- [effector/${ruleName}](rules/${ruleName}/${ruleName}.md)`
);
}),
]);
});

test("any config should be presented in main README.md", async () => {
const readmeContent = await readFile(join(__dirname, "README.md"), "utf8");

await Promise.all([
Object.entries(plugin.configs).map(async ([configName]) => {
expect(readmeContent).toContain(`#### plugin:effector/${configName}`);
}),
]);
});

test("any config should have list of rules in main README.md", async () => {
const readmeContent = await readFile(join(__dirname, "README.md"), "utf8");

await Promise.all([
Object.entries(plugin.configs).map(async ([configName, config]) => {
const [_, readmeContentAfterConfigDocSectionStart] =
readmeContent.split(`#### plugin:effector/${configName}`);

const [readmeContentConfigDocSection] =
readmeContentAfterConfigDocSectionStart.split("###");

const includedRuleNames = Object.keys(config.rules).map((fullName) =>
fullName.replace("effector/", "")
);

const excludedRules = Object.keys(plugin.rules).filter(
(rule) => !includedRuleNames.includes(rule)
);

// Has links to included rules
for (const ruleName of includedRuleNames) {
expect(readmeContentConfigDocSection).toContain(
`- [effector/${ruleName}](rules/${ruleName}/${ruleName}.md)`
);
}

// Does not have links to excluded rules
for (const ruleName of excludedRules) {
expect(readmeContentConfigDocSection).not.toContain(
`- [effector/${ruleName}](rules/${ruleName}/${ruleName}.md)`
);
}
}),
]);
});
});

0 comments on commit 06d6583

Please sign in to comment.