Skip to content

Commit

Permalink
fix: Update docs & generation script (#21)
Browse files Browse the repository at this point in the history
* build(deps): bump ini from 1.3.5 to 1.3.7 (#8)

Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.7)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix-readme > Re-implement table generation script

* docs/rules > Add missing docs for rules & contributors entry

* fix-readme > Resolve & Update table generation

* docs > add a readme for expect-expect rule

* docs > add a readme for no-identical-title rule

* docs > Fix codeblock to match testcafe syntax

* build(deps): bump y18n from 4.0.0 to 4.0.1 (#9)

* build(deps): bump handlebars from 4.7.6 to 4.7.7 (#10)

* build(deps): bump lodash from 4.17.19 to 4.17.21 (#11)

* build(deps): bump hosted-git-info from 2.8.8 to 2.8.9 (#12)

* build(deps): bump lodash from 4.17.20 to 4.17.21 in /example (#13)

* build(deps): bump normalize-url from 5.3.0 to 5.3.1 (#15)

* build(deps): bump trim-newlines from 3.0.0 to 3.0.1 (#16)

* build(deps): bump glob-parent from 5.1.1 to 5.1.2 (#17)

* build(deps): bump glob-parent from 5.1.1 to 5.1.2 in /example (#18)

* build(deps): bump path-parse from 1.0.6 to 1.0.7 (#19)

* build(deps): bump tmpl from 1.0.4 to 1.0.5 (#20)

* build(deps): bump ws from 7.2.5 to 7.5.5 (#25)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
codejedi365 and dependabot[bot] authored Sep 29, 2021
1 parent 9774193 commit 1dedf5a
Show file tree
Hide file tree
Showing 7 changed files with 875 additions and 203 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extendi

🛠 indicates that a rule is fixable.

<!-- __BEGIN AUTOGENERATED TABLE__ -->Name | ✔️ | 🛠 | Description
----- | ----- | ----- | -----
[expectExpect](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/expectExpect.md) | ✔️ | | Ensure tests have at least one expect
[noDebug](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/noDebug.md) | ✔️ | | Don't allow `t.debug()` to be committed to the repository.
[noIdenticalTitle](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/noIdenticalTitle.md) | ✔️ | | Don't use identical titles for your tests
[noOnly](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/noOnly.md) | ✔️ | | Don't allow `test.only` to be added to the repository
[noSkip](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/noSkip.md) | ✔️ | | Don't allow `test.skip` or `fixture.skip` to be added to the repository
<!-- __END AUTOGENERATED TABLE__ -->
<!-- __BEGIN AUTOGENERATED RULES TABLE__ -->
| Name | ✔️ | 🛠 | Description |
| ----- | ----- | ----- | ----------- |
| [expectExpect](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/expectExpect.md) | ✔️ | | Ensure tests have at least one expect |
| [noDebug](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noDebug.md) | ✔️ | | Don't allow `t.debug()` to be committed to the repository. |
| [noIdenticalTitle](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noIdenticalTitle.md) | ✔️ | | Don't use identical titles for your tests |
| [noOnly](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noOnly.md) | ✔️ | | Don't allow `test.only` to be added to the repository |
| [noSkip](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noSkip.md) | ✔️ | | Don't allow `test.skip` or `fixture.skip` to be added to the repository |
<!-- __END AUTOGENERATED RULES TABLE__ -->
45 changes: 26 additions & 19 deletions build/generate-readme-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@

const fs = require("fs");
const path = require("path");
const rules = require("..").rules;
const { rules } = require("../lib");
const { repository } = require("../package.json");
const repoURL = repository.url.replace(/^git:\/\//, "");

const README_LOCATION = path.resolve(__dirname, "..", "README.md");
const BEGIN_TABLE_MARKER = "<!-- __BEGIN AUTOGENERATED TABLE__ -->";
const END_TABLE_MARKER = "\n<!-- __END AUTOGENERATED TABLE__ -->";
const BEGIN_TABLE_MARKER = "<!-- __BEGIN AUTOGENERATED RULES TABLE__ -->";
const END_TABLE_MARKER = "<!-- __END AUTOGENERATED RULES TABLE__ -->";

const expectedTableLines = Object.keys(rules)
.sort()
.reduce(
(lines, ruleId) => {
const rule = rules[ruleId];

lines.push(
[
`[${ruleId}](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? "✔️" : "",
rule.meta.fixable ? "🛠" : "",
rule.meta.docs.description
].join(" | ")
);
const tr = [
`[${ruleId}](https://${repoURL}/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? "✔️" : "",
rule.meta.fixable ? "🛠" : "",
rule.meta.docs.description
].join(" | ")

lines.push(`| ${tr} |`);

return lines;
},
["Name | ✔️ | 🛠 | Description", "----- | ----- | ----- | -----"]
[
"| Name | ✔️ | 🛠 | Description |",
"| ----- | ----- | ----- | ----------- |"
]
)
.join("\n");

Expand All @@ -45,13 +50,15 @@ const linesStartIndex =
readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
const linesEndIndex = readmeContents.indexOf(END_TABLE_MARKER);

const updatedReadmeContents =
readmeContents.slice(0, linesStartIndex) +
expectedTableLines +
readmeContents.slice(linesEndIndex);
const updatedReadmeContents = [
readmeContents.slice(0, linesStartIndex),
expectedTableLines,
readmeContents.slice(linesEndIndex)
].join("\n");

if (module.parent) {
module.exports = updatedReadmeContents;
} else {
if (require.main === module) {
// Run on command line
fs.writeFileSync(README_LOCATION, updatedReadmeContents);
} else {
module.exports = updatedReadmeContents;
}
37 changes: 37 additions & 0 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# All tests should have at least one assertion via t.expect(). (expect-expect)

## Rule Details

This rule aims to ensure a `t.expect()` function call exists within a defined test block. There maybe times in local development you don't have an assertion defined, but this rule aims to prevent a test case from being accidentally committed and falsfully report a pass when it doesn't test any condition.

Examples of **incorrect** code for this rule:

```js
// Example 1: Forgot to add an assertion but provided an action
test('should do stuff', async (t) => {
await t.click(Selector("foo"))
})

// Example 2: empty test scaffolding
test('test something', (t) => {
// TODO: Test something
})
```

Examples of **correct** code for this rule:

```js
test('should change text to clicked', async (t) => {
const text = Selector("bar")
await t.click(Selector("foo"))
await t.expect(text).toEqual("button clicked") // Makes an assertion
})
```

## When Not To Use It

If you don't care if people add empty test cases to your source code repository.

## Further Reading

<https://testcafe.io/documentation/402837/guides/basic-guides/assert>
40 changes: 40 additions & 0 deletions docs/rules/no-identical-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Don&#39;t allow an identical test title to be committed to the repository. (no-identical-title)

## Rule Details

This rule aims to prevent duplicate test names to exist. All tests should have an unique name across the entire repository.

Examples of **incorrect** code for this rule:

```js
test("should see a button to click", async (t) => {
await t.expect(Selector("foo").value).toEqual("Click Me!")
})

// Duplicate title
test("should see a button to click", async (t) => {
await t.click(Selector("foo"))
await t.expect(Selector("foo").value).toEqual("Clicked")
})
```

Examples of **correct** code for this rule:

```js
// 2 different titles
test("should see a button to click", async (t) => {
await t.expect(Selector("foo").value).toEqual("Click Me!")
})
test("should see button text change after clicked", async (t) => {
await t.click(Selector("foo"))
await t.expect(Selector("foo").value).toEqual("Clicked")
})
```

## When Not To Use It

If you don't care if people add tests with the same name to your source code repository.

## Further Reading

<https://testcafe.io/documentation/402831/guides/basic-guides/organize-tests#tests>
Loading

0 comments on commit 1dedf5a

Please sign in to comment.