eslint-plugin-executable-stories-jest 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-executable-stories-jest",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ESLint rules for executable-stories-jest: step context, doc.story in test/it",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
|
-
"
|
|
19
|
+
"skills",
|
|
20
|
+
"README.md",
|
|
21
|
+
"bin"
|
|
20
22
|
],
|
|
21
23
|
"repository": {
|
|
22
24
|
"type": "git",
|
|
@@ -43,11 +45,15 @@
|
|
|
43
45
|
"tsup": "^8.5.1",
|
|
44
46
|
"typescript": "^5.9.3",
|
|
45
47
|
"vitest": "^4.0.18",
|
|
46
|
-
"eslint-config-executable-stories": "0.2.0"
|
|
48
|
+
"eslint-config-executable-stories": "0.2.0",
|
|
49
|
+
"executable-stories-vitest": "7.0.2"
|
|
47
50
|
},
|
|
48
51
|
"engines": {
|
|
49
52
|
"node": ">=22"
|
|
50
53
|
},
|
|
54
|
+
"bin": {
|
|
55
|
+
"intent": "./bin/intent.js"
|
|
56
|
+
},
|
|
51
57
|
"scripts": {
|
|
52
58
|
"build": "tsup",
|
|
53
59
|
"type-check": "node -e \"const fs=require('fs');const {execSync}=require('child_process');const p=require('path').resolve(process.cwd(),'../executable-stories-jest/package.json');if(!fs.existsSync(p)){console.log('Skipping type-check: executable-stories-jest not in workspace');process.exit(0);}execSync('pnpm --filter executable-stories-jest run build && tsc --noEmit',{stdio:'inherit'});\"",
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: eslint-jest-rules
|
|
3
|
+
description: >
|
|
4
|
+
ESLint flat config plugin for executable-stories-jest. Two rules:
|
|
5
|
+
require-story-context-for-steps (steps must be inside story callback),
|
|
6
|
+
require-test-context-for-doc-story (doc.story must be inside test/it).
|
|
7
|
+
Recommended config enables both at error level.
|
|
8
|
+
type: core
|
|
9
|
+
library: eslint-plugin-executable-stories-jest
|
|
10
|
+
library_version: "0.1.0"
|
|
11
|
+
sources:
|
|
12
|
+
- "jagreehal/executable-stories:packages/eslint-plugin-executable-stories-jest/src/index.ts"
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# ESLint Plugin: executable-stories-jest
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// eslint.config.mjs
|
|
21
|
+
import jestStories from "eslint-plugin-executable-stories-jest";
|
|
22
|
+
|
|
23
|
+
export default [
|
|
24
|
+
// Option A: Use recommended config
|
|
25
|
+
...jestStories.configs.recommended,
|
|
26
|
+
|
|
27
|
+
// Option B: Manual configuration
|
|
28
|
+
{
|
|
29
|
+
plugins: {
|
|
30
|
+
"executable-stories-jest": jestStories,
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
"executable-stories-jest/require-story-context-for-steps": "error",
|
|
34
|
+
"executable-stories-jest/require-test-context-for-doc-story": "error",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Core Patterns
|
|
41
|
+
|
|
42
|
+
### Rule: require-story-context-for-steps
|
|
43
|
+
|
|
44
|
+
Ensures step functions (`given`, `when`, `then`, `and`, `but` and aliases) are called inside a `story()` or `doc.story(..., callback)`.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Fails lint
|
|
48
|
+
it("my test", () => {
|
|
49
|
+
given("something"); // Error: must be inside story() or doc.story()
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Passes lint
|
|
53
|
+
it("my test", () => {
|
|
54
|
+
story.init();
|
|
55
|
+
story.given("something");
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Rule: require-test-context-for-doc-story
|
|
60
|
+
|
|
61
|
+
Ensures `doc.story(title)` is called inside a `test()` or `it()` callback.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Fails lint
|
|
65
|
+
function setup() {
|
|
66
|
+
doc.story("My story"); // Error: must be inside test/it callback
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Fails lint
|
|
70
|
+
it("my test", () => {
|
|
71
|
+
doc.story(); // Error: requires a title argument
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Passes lint
|
|
75
|
+
it("my test", () => {
|
|
76
|
+
doc.story("My story");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Also detects modifiers: it.only, it.skip, it.todo, it.concurrent, it.failing
|
|
80
|
+
it.only("focused test", () => {
|
|
81
|
+
doc.story("My story"); // Passes lint
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Common Mistakes
|
|
86
|
+
|
|
87
|
+
### HIGH Using legacy .eslintrc instead of flat config
|
|
88
|
+
|
|
89
|
+
Wrong:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"plugins": ["executable-stories-jest"],
|
|
94
|
+
"rules": {
|
|
95
|
+
"executable-stories-jest/require-story-context-for-steps": "error"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Correct:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// eslint.config.mjs (flat config)
|
|
104
|
+
import jestStories from "eslint-plugin-executable-stories-jest";
|
|
105
|
+
|
|
106
|
+
export default [...jestStories.configs.recommended];
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This plugin only supports ESLint 9 flat config.
|
|
110
|
+
|
|
111
|
+
Source: packages/eslint-plugin-executable-stories-jest/src/index.ts
|