Skip to content

Commit

Permalink
Improve code examples in README
Browse files Browse the repository at this point in the history
Prefer ESM, considering Stylelint 16.0.0.
  • Loading branch information
ybiquitous committed Nov 22, 2023
1 parent 9693b30 commit 213ee59
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 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");
const myPlugin = require("./my-plugin.js");

const plugins = [myPlugin];

global.testRule = getTestRule({ plugins: ["./"] });
global.testRuleConfigs = getTestRuleConfigs({ plugins: ["./"] });
global.testRule = getTestRule({ plugins });
global.testRuleConfigs = getTestRuleConfigs({ plugins });
```

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

0 comments on commit 213ee59

Please sign in to comment.