eslint-plugin-test-governance 0.6.2 → 0.8.0

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.
@@ -20,14 +20,14 @@ export interface CustomState {
20
20
  /** Options shared by every rule. Set them once in `settings['test-governance']`. */
21
21
  export interface GovernanceOptions {
22
22
  /**
23
- * The test framework of the files the config applies to: `'playwright'`, `'jest'` or `'vitest'`. Required;
24
- * `configs.playwright`, `configs.jest` and `configs.vitest` set it.
23
+ * The test framework of the files the config applies to: `'playwright'`, `'jest'`, `'vitest'`, `'mocha'`,
24
+ * `'cypress'`, `'webdriverio'` or `'node-test'`. Required; each framework's config, such as `configs.mocha`, sets it.
25
25
  */
26
26
  framework: FrameworkName;
27
27
  /**
28
- * Names that are treated as the framework's `test` function. Defaults to `['test']` for Playwright and
29
- * `['test', 'it']` for Jest and Vitest. Your list replaces the default one, so include those names if
30
- * you still need them.
28
+ * Names that are treated as the framework's `test` function. Defaults to `['test']` for Playwright,
29
+ * `['test', 'it']` for Jest and Vitest, and `['it', 'specify', 'test']` for Mocha, Cypress and
30
+ * WebdriverIO. Your list replaces the default one, so include those names if you still need them.
31
31
  */
32
32
  testFunctions?: string[];
33
33
  /** Accepted ticket formats. Defaults to `{ preset: 'any' }`. */
@@ -6,7 +6,9 @@ const KEY_PATTERN = '^[A-Z][A-Z0-9_]+$';
6
6
  const KEY_HINT = 'an uppercase key as it appears in tickets, such as WEB for WEB-123';
7
7
  /** `['"a"', '"b"', '"c"']` as `"a", "b" or "c"`. */
8
8
  const orList = (items) => `${items.slice(0, -1).join(', ')} or ${items.slice(-1).join('')}`;
9
- const FRAMEWORK_HINT = `set it to ${orList(FRAMEWORK_NAMES.map((name) => `"${name}"`))}, or use ${orList(FRAMEWORK_NAMES.map((name) => `configs.${name}`))}`;
9
+ /** How code reads a framework's config: `configs.mocha`, or `configs['node-test']` for a name with a dash. */
10
+ const configAccess = (name) => (/^\w+$/.test(name) ? `configs.${name}` : `configs['${name}']`);
11
+ const FRAMEWORK_HINT = `set it to ${orList(FRAMEWORK_NAMES.map((name) => `"${name}"`))}, or use ${orList(FRAMEWORK_NAMES.map(configAccess))}`;
10
12
  const ticketSpecSchema = {
11
13
  type: 'object',
12
14
  properties: {
@@ -2,7 +2,7 @@
2
2
 
3
3
  📝 Require the marker keyword to match the test's state.
4
4
 
5
- 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🃏 `jest`, 🎭 `playwright`, ⚡ `vitest`.
5
+ 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🌲 `cypress`, 🃏 `jest`, ☕ `mocha`, 🟢 `node-test`, 🎭 `playwright`, ⚡ `vitest`, 🤖 `webdriverio`.
6
6
 
7
7
  💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  📝 Disallow state tags that contradict each other, differ in case or look like typos.
4
4
 
5
- ⚠️ This rule _warns_ in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🃏 `jest`, 🎭 `playwright`, ⚡ `vitest`.
5
+ ⚠️ This rule _warns_ in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🌲 `cypress`, 🃏 `jest`, ☕ `mocha`, 🟢 `node-test`, 🎭 `playwright`, ⚡ `vitest`, 🤖 `webdriverio`.
6
6
 
7
7
  🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  📝 Disallow marker comments that no longer match a test state.
4
4
 
5
- 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🃏 `jest`, 🎭 `playwright`, ⚡ `vitest`.
5
+ 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🌲 `cypress`, 🃏 `jest`, ☕ `mocha`, 🟢 `node-test`, 🎭 `playwright`, ⚡ `vitest`, 🤖 `webdriverio`.
6
6
 
7
7
  💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
8
 
@@ -26,9 +26,9 @@ A `FIXME:` or `TODO:` comment that starts with a valid ticket is treated by wher
26
26
  leftover marker and is reported, since `// FIXME: TRADE-12` above a test usually means the test was
27
27
  fixed and the marker forgotten. Move a work comment into the test body, or onto the line of code it
28
28
  is about.
29
- - Above a Jest or Vitest test that is not a todo, a `TODO:` comment is a tracked work comment about
29
+ - Above a test that is not a todo, in every framework but Playwright, a `TODO:` comment is a tracked work comment about
30
30
  the test and is allowed. `TODO` is the everyday keyword for such comments, so there it is far more
31
- often a note than the forgotten marker of a `test.todo`.
31
+ often a note than the forgotten marker of a todo test.
32
32
 
33
33
  Other markers that read as a sentence, such as `// SKIP: this one is flaky`, are left alone too: the rule
34
34
  counts a comment as prose when its first word is not a valid ticket and more text follows.
@@ -2,7 +2,7 @@
2
2
 
3
3
  📝 Require FIXME and TODO comments in test files to start with a ticket.
4
4
 
5
- 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🃏 `jest`, 🎭 `playwright`, ⚡ `vitest`.
5
+ 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🌲 `cypress`, 🃏 `jest`, ☕ `mocha`, 🟢 `node-test`, 🎭 `playwright`, ⚡ `vitest`, 🤖 `webdriverio`.
6
6
 
7
7
  💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
8
 
@@ -30,9 +30,10 @@ How comments are read:
30
30
  style many teams already use. Anything after the parentheses is a note, as it would be after `TODO: TRADE-512`.
31
31
  - The tickets follow the same rules as markers: the shared ticket format, placeholders such as `TBD`
32
32
  rejected, and no text after the tickets unless `allowNotes` is set.
33
- - A `// FIXME:` marker directly above a `test.fixme(...)`, or a `// TODO:` marker above a Jest or
34
- Vitest `test.todo(...)`, is checked by [`require-ticket`](require-ticket.md) instead, so it is
35
- reported once.
33
+ - A `// FIXME:` marker directly above a `test.fixme(...)`, or a `// TODO:` marker above a todo test,
34
+ such as Jest's `test.todo(...)` or Mocha's `it('title')`, is checked by [`require-ticket`](require-ticket.md) instead, so it is
35
+ reported once. That includes one in the wrong case, `// fixme:` or `// Todo:`, which `require-ticket` asks to write in
36
+ uppercase.
36
37
  - Only test files (a test framework import or a call to a test function) are checked.
37
38
  Application code is left alone, even if your config applies the plugin to it.
38
39
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  📝 Require a ticket marker comment above skipped, fixme and tagged tests.
4
4
 
5
- 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🃏 `jest`, 🎭 `playwright`, ⚡ `vitest`.
5
+ 💼 This rule is enabled in the following [configs](https://github.com/Huldoser/eslint-plugin-test-governance#usage): 🌲 `cypress`, 🃏 `jest`, ☕ `mocha`, 🟢 `node-test`, 🎭 `playwright`, ⚡ `vitest`, 🤖 `webdriverio`.
6
6
 
7
7
  💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
8
 
@@ -17,19 +17,23 @@ A test is in a state when it is:
17
17
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------------------- |
18
18
  | `skip` | `test.skip('title', fn)`, `test.describe.skip`, `test.skip()` in a body, `testInfo.skip()`, `test.step.skip`, `step.skip()` in a step | `// SKIP:` | yes |
19
19
  | `fixme` | `test.fixme(...)`, `test.describe.fixme`, `testInfo.fixme()` | `// FIXME:` | yes |
20
- | `todo` | Jest's and Vitest's `test.todo` | `// TODO:` | yes, in Jest and Vitest |
20
+ | `todo` | Jest's, Vitest's and `node:test`'s `test.todo`, and a Mocha test with only a title, `it('title')` | `// TODO:` | yes, except in Playwright |
21
21
  | `new` | the `@new` tag | `// NEW:` | with `lifecycleTags: true` |
22
22
  | `quarantined` | the `@quarantined` tag | `// QUARANTINED:` | with `lifecycleTags: true` |
23
23
  | `fail`, `slow` | `test.fail(...)`, `test.slow()`, `testInfo.fail()`, `testInfo.slow()` | `// FAIL:`, `// SLOW:` | no |
24
24
  | custom | any tag you list in `customStates` | your keyword | when configured |
25
25
 
26
26
  In Jest and Vitest, `xit`, `xdescribe`, Vitest's `{ skip: true }`, `skipIf(true)`, `context.skip()` and
27
- `context.skip('note')`, in a test or in `beforeEach`, skip a test too, and `test.failing` and `test.fails` put it in the `fail` state. The
27
+ `context.skip('note')`, in a test or in `beforeEach`, skip a test too, and `test.failing` and `test.fails` put it in the `fail` state. In Mocha, Cypress and WebdriverIO, `xit`, `xdescribe` and
28
+ `this.skip()` in a test or hook skip a test too, and Cypress's `{ browser: '!webkit' }` skips it in other
29
+ browsers, which counts as a conditional skip. In `node:test`, `{ skip: 'reason' }`, `t.skip()` and `this.skip()` skip a test, `{ todo: true }`,
30
+ `t.todo()` and `this.todo()` make it a todo, `t.test()` subtests count as tests, and `test.expectFailure` puts it in the `fail` state. The
28
31
  [README](../../README.md#frameworks) lists every form.
29
32
 
30
33
  Tags are read from the title (`'places a limit order @new'`) and from `{ tag: '@new' }` or `{ tag: ['@new', '@smoke'] }`,
31
34
  also when they come from a `const` or an enum declared in the same file, as in `{ tag: TAGS.NEW }`.
32
- Vitest writes tag names without the `@`, so `{ tags: ['new'] }` is the `@new` tag. Tags on a
35
+ Vitest writes tag names without the `@`, so `{ tags: ['new'] }` is the `@new` tag. Cypress tags from
36
+ @cypress/grep keep it: `{ tags: '@new' }`. Tags on a
33
37
  `describe` apply to every test inside it. `states` can rename the tag and marker of `new` and
34
38
  `quarantined`, as in `states: { quarantined: { tag: '@flaky', marker: 'FLAKY' } }`.
35
39
 
@@ -77,8 +81,10 @@ Conditional skips such as `test.skip(browserName === 'webkit', 'Not supported')`
77
81
  permanent platform limit, so they need no ticket unless you set `requireTicketForConditional: true`.
78
82
  A runtime skip under an `if`, a `switch` case, a ternary or `&&` counts as conditional too, since
79
83
  `if (!enabled) test.skip()` does the same as `test.skip(!enabled)`. So does a skip in a `catch` block,
80
- such as `catch { test.skip(true, 'Market data feed is down') }`, and a skip after an early exit such as
81
- `if (ready) return;` or `if (!ok) throw error;` earlier in the same function.
84
+ such as `catch { test.skip(true, 'Market data feed is down') }`, a skip after other code in a `try`
85
+ block that has a `catch`, as in `try { await stat(target); test.skip(); } catch {}`, where an error
86
+ skips past it, and a skip after an early exit such as `if (ready) return;` or `if (!ok) throw error;`
87
+ earlier in the same function.
82
88
 
83
89
  A test or describe whose function a condition picks is a conditional skip too, in every framework. Its
84
90
  title and tags count as usual, and a marker goes above it, or in code without semicolons above the
@@ -191,6 +197,28 @@ it.todo('caps position size at 2% of equity');
191
197
  test.skipIf(true)('fills a stop order when the market opens', () => {});
192
198
  ```
193
199
 
200
+ <!-- example: invalid settings={"framework":"mocha"} -->
201
+
202
+ ```js
203
+ it('settles a trade at T+1', function () {
204
+ this.skip();
205
+ });
206
+ ```
207
+
208
+ <!-- example: invalid settings={"framework":"node-test"} -->
209
+
210
+ ```js
211
+ import { test } from 'node:test';
212
+
213
+ test('liquidates below maintenance', { skip: 'broker sandbox is down' }, () => {});
214
+ ```
215
+
216
+ <!-- example: invalid settings={"framework":"cypress","lifecycleTags":true} -->
217
+
218
+ ```js
219
+ it('places a stop order', { tags: '@quarantined' }, () => {});
220
+ ```
221
+
194
222
  Correct:
195
223
 
196
224
  <!-- example: valid -->
@@ -245,6 +273,32 @@ describe('risk limits', () => {
245
273
  });
246
274
  ```
247
275
 
276
+ <!-- example: valid settings={"framework":"mocha"} -->
277
+
278
+ ```js
279
+ describe('settlement', function () {
280
+ // TODO: TRADE-91
281
+ it('settles a trade on a market holiday');
282
+
283
+ it('settles in the clearing house currency', function () {
284
+ if (!process.env.CLEARING_URL) this.skip();
285
+ });
286
+ });
287
+ ```
288
+
289
+ <!-- example: valid settings={"framework":"node-test"} -->
290
+
291
+ ```js
292
+ import { test } from 'node:test';
293
+
294
+ // SKIP: TRADE-92
295
+ test('liquidates below maintenance', { skip: 'broker sandbox is down' }, () => {});
296
+
297
+ test('nets margin across accounts', (t) => {
298
+ if (!process.env.RISK_URL) t.skip();
299
+ });
300
+ ```
301
+
248
302
  ## Options
249
303
 
250
304
  This rule has no options of its own. It reads the shared options described in the
package/docs/upgrading.md CHANGED
@@ -90,7 +90,7 @@ becomes `extends: ['test-governance/playwright']`.
90
90
  A config that still reads `configs.recommended` fails when it loads:
91
91
 
92
92
  ```text
93
- eslint-plugin-test-governance: configs.recommended was removed in 0.5.0. Use the config for your framework: configs.playwright, configs.jest or configs.vitest. See https://github.com/Huldoser/eslint-plugin-test-governance/blob/main/docs/upgrading.md
93
+ eslint-plugin-test-governance: configs.recommended was removed in 0.5.0. Use the config for your framework: configs.playwright, configs.jest, configs.vitest, configs.mocha, configs.cypress, configs.webdriverio or configs['node-test']. See https://github.com/Huldoser/eslint-plugin-test-governance/blob/main/docs/upgrading.md
94
94
  ```
95
95
 
96
96
  ### The framework option
@@ -121,7 +121,7 @@ Without it, the config fails when it loads:
121
121
 
122
122
  ```text
123
123
  eslint-plugin-test-governance: invalid options:
124
- - framework is required: set it to "playwright", "jest" or "vitest", or use configs.playwright, configs.jest or configs.vitest
124
+ - framework is required: set it to "playwright", "jest", "vitest", "mocha", "cypress", "webdriverio" or "node-test", or use configs.playwright, configs.jest, configs.vitest, configs.mocha, configs.cypress, configs.webdriverio or configs['node-test']
125
125
  ```
126
126
 
127
127
  If you write `settings['test-governance']` yourself instead of calling `configure()`, add `framework`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-test-governance",
3
- "version": "0.6.2",
4
- "description": "ESLint rules that require a ticket comment above skipped, fixme, todo and tagged Playwright, Jest and Vitest tests.",
3
+ "version": "0.8.0",
4
+ "description": "ESLint rules that require a ticket comment above skipped, fixme, todo and tagged Playwright, Jest, Vitest, Mocha, Cypress, WebdriverIO and node:test tests.",
5
5
  "keywords": [
6
6
  "eslint",
7
7
  "eslintplugin",
@@ -9,6 +9,10 @@
9
9
  "playwright",
10
10
  "jest",
11
11
  "vitest",
12
+ "mocha",
13
+ "cypress",
14
+ "webdriverio",
15
+ "node-test",
12
16
  "testing"
13
17
  ],
14
18
  "homepage": "https://github.com/Huldoser/eslint-plugin-test-governance#readme",