Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code examples in README #86

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ Add the preset to your `jest.config.js` or `jest` field in `package.json`:
}
```

### Adjust setup globally

Optionally, you can avoid specifying `plugins` in every schema by defining your own setup file to configure the `testRule`/`testRuleConfigs` functions.
This is useful if you have many tests. There are two additional steps to do this:

1. Create `jest.setup.js` in the root of your project. Provide `plugins` option to `getTestRule`/`getTestRuleConfigs`:

```js
const { getTestRule, getTestRuleConfigs } = require("jest-preset-stylelint");
import { getTestRule, getTestRuleConfigs } from "jest-preset-stylelint";
import myPlugin from "./my-plugin.js";

const plugins = [myPlugin];

global.testRule = getTestRule({ plugins: ["./"] });
global.testRuleConfigs = getTestRuleConfigs({ plugins: ["./"] });
global.testRule = getTestRule({ plugins });
global.testRuleConfigs = getTestRuleConfigs({ plugins });
```
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

2. Add `jest.setup.js` to your `jest.config.js` or `jest` field in `package.json`:

```json
{
"preset": "jest-preset-stylelint",
"setupFiles": ["jest.setup.js"]
"setupFiles": ["<rootDir>/jest.setup.js"]
}
```

Expand All @@ -57,10 +62,16 @@ For example, we can test a plugin that enforces and autofixes kebab-case class s

```js
// my-plugin.test.js
const { messages, ruleName } = require(".");
import myPlugin from "./my-plugin.js";

const plugins = [myPlugin];
const {
ruleName,
rule: { messages }
} = myPlugin;

testRule({
plugins: ["."],
plugins,
ruleName,
config: [true, { type: "kebab" }],
fix: true,
Expand Down Expand Up @@ -120,7 +131,7 @@ For example:

```js
testRuleConfigs({
plugins: ["."],
plugins,
ruleName,

accept: [
Expand Down
Loading