@ddd-ts-kit/eslint-plugin 0.87.0 → 0.89.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.
Files changed (66) hide show
  1. package/README.fr.md +8 -2
  2. package/README.md +7 -1
  3. package/dist/presets/create-ddd-ts-kit.js +10 -2
  4. package/dist/presets/create-ddd-ts-kit.js.map +1 -1
  5. package/dist/project/config.d.ts +1 -1
  6. package/dist/project/config.d.ts.map +1 -1
  7. package/dist/project/locate.js +46 -11
  8. package/dist/project/locate.js.map +1 -1
  9. package/dist/rules/rules.d.ts.map +1 -1
  10. package/dist/rules/rules.js +12 -0
  11. package/dist/rules/rules.js.map +1 -1
  12. package/dist/rules/test-assertion-present.d.ts +2 -0
  13. package/dist/rules/test-assertion-present.d.ts.map +1 -0
  14. package/dist/rules/test-assertion-present.js +70 -0
  15. package/dist/rules/test-assertion-present.js.map +1 -0
  16. package/dist/rules/test-no-logic.d.ts +2 -0
  17. package/dist/rules/test-no-logic.d.ts.map +1 -0
  18. package/dist/rules/test-no-logic.js +46 -0
  19. package/dist/rules/test-no-logic.js.map +1 -0
  20. package/dist/rules/test-no-only-no-skip.d.ts +2 -0
  21. package/dist/rules/test-no-only-no-skip.d.ts.map +1 -0
  22. package/dist/rules/test-no-only-no-skip.js +53 -0
  23. package/dist/rules/test-no-only-no-skip.js.map +1 -0
  24. package/dist/rules/test-no-snapshot.d.ts +2 -0
  25. package/dist/rules/test-no-snapshot.d.ts.map +1 -0
  26. package/dist/rules/test-no-snapshot.js +37 -0
  27. package/dist/rules/test-no-snapshot.js.map +1 -0
  28. package/dist/rules/test-refusal-by-code.d.ts +2 -0
  29. package/dist/rules/test-refusal-by-code.d.ts.map +1 -0
  30. package/dist/rules/test-refusal-by-code.js +71 -0
  31. package/dist/rules/test-refusal-by-code.js.map +1 -0
  32. package/dist/rules/test-title-states-a-rule.d.ts +4 -0
  33. package/dist/rules/test-title-states-a-rule.d.ts.map +1 -0
  34. package/dist/rules/test-title-states-a-rule.js +68 -0
  35. package/dist/rules/test-title-states-a-rule.js.map +1 -0
  36. package/dist/support/descendants.d.ts +5 -2
  37. package/dist/support/descendants.d.ts.map +1 -1
  38. package/dist/support/descendants.js +7 -1
  39. package/dist/support/descendants.js.map +1 -1
  40. package/dist/support/stepdown/misplaced-functions.js +9 -1
  41. package/dist/support/stepdown/misplaced-functions.js.map +1 -1
  42. package/dist/support/tests/test-call.d.ts +20 -0
  43. package/dist/support/tests/test-call.d.ts.map +1 -0
  44. package/dist/support/tests/test-call.js +77 -0
  45. package/dist/support/tests/test-call.js.map +1 -0
  46. package/dist/support/tests/title-text.d.ts +7 -0
  47. package/dist/support/tests/title-text.d.ts.map +1 -0
  48. package/dist/support/tests/title-text.js +22 -0
  49. package/dist/support/tests/title-text.js.map +1 -0
  50. package/dist/version.d.ts +1 -1
  51. package/dist/version.js +1 -1
  52. package/docs/rules/errors-factory-name.fr.md +4 -4
  53. package/docs/rules/errors-factory-name.md +3 -3
  54. package/docs/rules/test-assertion-present.fr.md +58 -0
  55. package/docs/rules/test-assertion-present.md +57 -0
  56. package/docs/rules/test-no-logic.fr.md +71 -0
  57. package/docs/rules/test-no-logic.md +70 -0
  58. package/docs/rules/test-no-only-no-skip.fr.md +56 -0
  59. package/docs/rules/test-no-only-no-skip.md +55 -0
  60. package/docs/rules/test-no-snapshot.fr.md +52 -0
  61. package/docs/rules/test-no-snapshot.md +51 -0
  62. package/docs/rules/test-refusal-by-code.fr.md +65 -0
  63. package/docs/rules/test-refusal-by-code.md +64 -0
  64. package/docs/rules/test-title-states-a-rule.fr.md +63 -0
  65. package/docs/rules/test-title-states-a-rule.md +62 -0
  66. package/package.json +1 -1
@@ -0,0 +1,71 @@
1
+ [English](test-no-logic.md) · **Français**
2
+ <!-- translation-of: test-no-logic.md sha256:f477d5367e9f49c7 -->
3
+
4
+ # ddd-ts-kit/test-no-logic
5
+
6
+ Identifiant d'architecture : `test/no-logic` (ajouté par ce *plugin*). Sévérité par défaut : `warn` dans `recommended` (une erreur à partir de 0.90.0 : `ddd-ts-kit lint` montre ses avertissements sans échouer dessus jusque-là), `error` dans `strict`.
7
+
8
+ S'applique à : chaque fichier de test du projet (`*.spec.ts`, `*.test.ts`, le `test/` d'un contexte).
9
+
10
+ ## Pourquoi
11
+
12
+ Un test se lit sans être exécuté : il prépare un état, agit une fois, vérifie ce qui est vrai ensuite, et échoue pour une seule raison. Un `if` dans un test est un second test caché dans le premier, ou un chemin que le test prend sans dire lequel ; une boucle vérifie plusieurs cas sous un seul titre, et le rapport n'en nomme aucun ; un `try` attrape ce que le lanceur aurait signalé avec sa pile. La logique qu'un test semble demander appartient à ce qu'il utilise : un *builder* décide comment se construit une facture payée, un *fake* décide quand le *mailer* échoue, un *helper* décide ce que contient une page.
13
+
14
+ ## Signalé
15
+
16
+ Dans le corps d'un `it` ou d'un `test`, scénario enveloppé par `pending(...)` compris :
17
+
18
+ - `if`, `switch`, un ternaire
19
+ - `for`, `for ... of`, `for ... in`, `while`, `do`
20
+ - `try`
21
+
22
+ Incorrect :
23
+
24
+ ```ts
25
+ it('accepts every kind', () => {
26
+ for (const kind of kinds) {
27
+ expect(NotificationKind.create(kind).value).toBe(kind);
28
+ }
29
+ });
30
+
31
+ it('refuses a second payment', () => {
32
+ try {
33
+ invoice.pay(at);
34
+ } catch (error) {
35
+ expect(error).toMatchObject({ code: 'INVOICE_ALREADY_PAID' });
36
+ }
37
+ });
38
+ ```
39
+
40
+ Correct :
41
+
42
+ ```ts
43
+ it.each(kinds)('accepts the kind %s', (kind) => {
44
+ expect(NotificationKind.create(kind).value).toBe(kind);
45
+ });
46
+
47
+ it('refuses a second payment', () => {
48
+ given(anInvoice().paid())
49
+ .when((invoice) => invoice.pay(at))
50
+ .thenError('INVOICE_ALREADY_PAID');
51
+ });
52
+ ```
53
+
54
+ ## Détails
55
+
56
+ Les *hooks* (`beforeEach`, `beforeAll`) et les fonctions déclarées à côté des tests ne sont pas jugés : une boucle qui alimente une table dans un *hook*, un *helper* de `test/e2e/support/` qui décide, sont la place de la logique. Un cas par ligne est un `it.each` dont la table est les lignes : le rapport nomme alors chacune.
57
+
58
+ ## Options
59
+
60
+ Aucune.
61
+
62
+ `rules."test/no-logic"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/no-logic -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
63
+
64
+ ## Limites
65
+
66
+ - `&&`, `||` et `??` ne sont pas signalés : `expect(a && b)` est une vérification faible, pas une branche.
67
+ - Une fonction appelée depuis le test et déclarée ailleurs peut contenir n'importe quelle logique : la règle lit le corps du test, la revue lit le *helper*.
68
+
69
+ ## Avec le checker de la CLI
70
+
71
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car lire un test demande un arbre syntaxique.
@@ -0,0 +1,70 @@
1
+ **English** · [Français](test-no-logic.fr.md)
2
+
3
+ # ddd-ts-kit/test-no-logic
4
+
5
+ Architecture id: `test/no-logic` (added by this plugin). Default severity: `warn` in `recommended` (an error from 0.90.0: `ddd-ts-kit lint` shows its warnings without failing on them until then), `error` in `strict`.
6
+
7
+ Applies to: every test file of the project (`*.spec.ts`, `*.test.ts`, the `test/` of a context).
8
+
9
+ ## Why
10
+
11
+ A test is read without being run: it arranges a state, acts once, asserts what is true afterwards, and fails for one reason. An `if` in a test is a second test hiding in the first, or a path the test takes without saying which; a loop asserts several cases under one title, and the report names none of them; a `try` catches what the runner would have reported with its stack. The logic a test seems to need belongs to what it uses: a builder decides how a paid invoice is built, a fake decides when the mailer fails, a helper decides what a page holds.
12
+
13
+ ## Reported
14
+
15
+ Inside the body of an `it` or a `test`, the scenario `pending(...)` wraps included:
16
+
17
+ - `if`, `switch`, a ternary
18
+ - `for`, `for ... of`, `for ... in`, `while`, `do`
19
+ - `try`
20
+
21
+ Incorrect:
22
+
23
+ ```ts
24
+ it('accepts every kind', () => {
25
+ for (const kind of kinds) {
26
+ expect(NotificationKind.create(kind).value).toBe(kind);
27
+ }
28
+ });
29
+
30
+ it('refuses a second payment', () => {
31
+ try {
32
+ invoice.pay(at);
33
+ } catch (error) {
34
+ expect(error).toMatchObject({ code: 'INVOICE_ALREADY_PAID' });
35
+ }
36
+ });
37
+ ```
38
+
39
+ Correct:
40
+
41
+ ```ts
42
+ it.each(kinds)('accepts the kind %s', (kind) => {
43
+ expect(NotificationKind.create(kind).value).toBe(kind);
44
+ });
45
+
46
+ it('refuses a second payment', () => {
47
+ given(anInvoice().paid())
48
+ .when((invoice) => invoice.pay(at))
49
+ .thenError('INVOICE_ALREADY_PAID');
50
+ });
51
+ ```
52
+
53
+ ## Details
54
+
55
+ The hooks (`beforeEach`, `beforeAll`) and the functions declared next to the tests are not judged: a loop that seeds a table in a hook, a helper of `test/e2e/support/` that decides, are where the logic goes. A case per row is an `it.each` whose table is the rows: the report then names each one.
56
+
57
+ ## Options
58
+
59
+ None.
60
+
61
+ `rules."test/no-logic"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/no-logic -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
62
+
63
+ ## Limits
64
+
65
+ - `&&`, `||` and `??` are not reported: `expect(a && b)` is a weak assertion, not a branch.
66
+ - A function called from the test and declared elsewhere may hold any logic: the rule reads the body of the test, the review reads the helper.
67
+
68
+ ## With the CLI checker
69
+
70
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
@@ -0,0 +1,56 @@
1
+ [English](test-no-only-no-skip.md) · **Français**
2
+ <!-- translation-of: test-no-only-no-skip.md sha256:f7350957fb15faab -->
3
+
4
+ # ddd-ts-kit/test-no-only-no-skip
5
+
6
+ Identifiant d'architecture : `test/no-only-no-skip` (ajouté par ce *plugin*). Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : chaque fichier de test du projet (`*.spec.ts`, `*.test.ts`, le `test/` d'un contexte).
9
+
10
+ ## Pourquoi
11
+
12
+ Un test laissé de côté rend l'exécution verte alors que quelque chose n'est pas prouvé. Le `.only` a été écrit pour déboguer un test et oublié : les autres ne tournent plus. `.skip` garde un test dans le fichier alors que rien ne le tient, et le jour où il aurait échoué personne n'est prévenu ; `.skipIf(true)` et `.runIf(false)` sont la même chose avec une condition qui ne change jamais. Le kit nomme plutôt ce qui n'est pas encore prouvé : un `it.todo` dont le titre est le comportement, que `ddd-ts-kit todo` liste et que `story --gate close` refuse tant qu'il appartient à la *story*.
13
+
14
+ ## Signalé
15
+
16
+ - `it.only`, `test.only`, `describe.only`, seul ou après un autre modificateur (`it.concurrent.only`)
17
+ - `it.skip`, `test.skip`, `describe.skip`
18
+ - `it.skipIf`, `it.runIf`, `describe.skipIf`, `describe.runIf` sur une constante (`true`, `false`, une chaîne) ou sur rien
19
+ - `fit`, `xit`, `xtest`, `fdescribe`, `xdescribe`
20
+
21
+ Incorrect :
22
+
23
+ ```ts
24
+ it.only('refuses to pay an invoice twice', () => { ... });
25
+ describe.skip('Invoice', () => { ... });
26
+ it.skipIf(true)('records the payment', () => { ... });
27
+ ```
28
+
29
+ Correct :
30
+
31
+ ```ts
32
+ it('refuses to pay an invoice twice', () => { ... });
33
+ it.todo('refuses to pay an invoice whose customer is closed');
34
+ describe.runIf(process.env['VARNISH_URL'] !== undefined)('through Varnish', () => { ... });
35
+ ```
36
+
37
+ ## Détails
38
+
39
+ `it.todo`, `it.each`, `it.concurrent` et `it.sequential` ne sont pas signalés : ils s'exécutent, ou nomment ce qui reste à écrire. `skipIf` et `runIf` sur une expression ne le sont pas non plus : ils disent où un test s'exécute, comme les tests à travers un cache HTTP s'exécutent là où le *pipeline* en démarre un ; le test y est alors exécuté, pas laissé de côté. Un test faux pour de bon est supprimé, avec la raison dans le *commit*.
40
+
41
+ La règle lit les `it`, `test` et `describe` du lanceur, importés de `vitest` ou de `@jest/globals` ou globaux ; une variable locale du même nom n'est pas jugée.
42
+
43
+ ## Options
44
+
45
+ Aucune.
46
+
47
+ `rules."test/no-only-no-skip"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/no-only-no-skip -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
48
+
49
+ ## Limites
50
+
51
+ - Une fonction du lanceur renommée (`const only = it.only`) ou tirée de `it.extend(...)` n'est pas suivie.
52
+ - Une condition constante sans être un littéral (`const NEVER = false; it.skipIf(!NEVER)`) est lue comme une condition.
53
+
54
+ ## Avec le checker de la CLI
55
+
56
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car lire un test demande un arbre syntaxique.
@@ -0,0 +1,55 @@
1
+ **English** · [Français](test-no-only-no-skip.fr.md)
2
+
3
+ # ddd-ts-kit/test-no-only-no-skip
4
+
5
+ Architecture id: `test/no-only-no-skip` (added by this plugin). Default severity: `error` in `recommended`, `error` in `strict`.
6
+
7
+ Applies to: every test file of the project (`*.spec.ts`, `*.test.ts`, the `test/` of a context).
8
+
9
+ ## Why
10
+
11
+ A test left aside makes the run green while something is not proven. `.only` was written to debug one test and forgotten: the others no longer run. `.skip` keeps a test in the file while nothing holds it, and the day it would have failed nobody is told; `.skipIf(true)` and `.runIf(false)` are the same thing with a condition that never changes. The kit names what is not proven yet instead: an `it.todo` with the behaviour as its title, which `ddd-ts-kit todo` lists and `story --gate close` refuses while one belongs to the story.
12
+
13
+ ## Reported
14
+
15
+ - `it.only`, `test.only`, `describe.only`, alone or after another modifier (`it.concurrent.only`)
16
+ - `it.skip`, `test.skip`, `describe.skip`
17
+ - `it.skipIf`, `it.runIf`, `describe.skipIf`, `describe.runIf` on a constant (`true`, `false`, a string) or on nothing
18
+ - `fit`, `xit`, `xtest`, `fdescribe`, `xdescribe`
19
+
20
+ Incorrect:
21
+
22
+ ```ts
23
+ it.only('refuses to pay an invoice twice', () => { ... });
24
+ describe.skip('Invoice', () => { ... });
25
+ it.skipIf(true)('records the payment', () => { ... });
26
+ ```
27
+
28
+ Correct:
29
+
30
+ ```ts
31
+ it('refuses to pay an invoice twice', () => { ... });
32
+ it.todo('refuses to pay an invoice whose customer is closed');
33
+ describe.runIf(process.env['VARNISH_URL'] !== undefined)('through Varnish', () => { ... });
34
+ ```
35
+
36
+ ## Details
37
+
38
+ `it.todo`, `it.each`, `it.concurrent` and `it.sequential` are not reported: they run, or they name what is to be written. `skipIf` and `runIf` on an expression are not reported either: they say where a test runs, as the tests through an HTTP cache run where the pipeline starts one; the test is then run there, not left aside. A test that is wrong for good is deleted, with the reason in the commit.
39
+
40
+ The rule reads `it`, `test` and `describe` of the runner, imported from `vitest` or `@jest/globals` or global; a local of the same name is not judged.
41
+
42
+ ## Options
43
+
44
+ None.
45
+
46
+ `rules."test/no-only-no-skip"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/no-only-no-skip -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
47
+
48
+ ## Limits
49
+
50
+ - A runner function renamed (`const only = it.only`) or taken from `it.extend(...)` is not followed.
51
+ - A condition that is constant without being a literal (`const NEVER = false; it.skipIf(!NEVER)`) is read as a condition.
52
+
53
+ ## With the CLI checker
54
+
55
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
@@ -0,0 +1,52 @@
1
+ [English](test-no-snapshot.md) · **Français**
2
+ <!-- translation-of: test-no-snapshot.md sha256:40cd387b2b3fb2ba -->
3
+
4
+ # ddd-ts-kit/test-no-snapshot
5
+
6
+ Identifiant d'architecture : `test/no-snapshot` (ajouté par ce *plugin*). Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : chaque fichier de test du projet (`*.spec.ts`, `*.test.ts`, le `test/` d'un contexte).
9
+
10
+ ## Pourquoi
11
+
12
+ Un *snapshot* enregistre ce que le code a produit la première fois, et se renouvelle d'un seul drapeau la fois suivante où il diffère : il ne vérifie rien qu'un lecteur puisse confronter à la règle, et il échoue sur chaque champ dont la règle ne dépend pas. Un test énonce les champs qui comptent, construits dans le test, pour que le lecteur voie la cause du résultat.
13
+
14
+ ## Signalé
15
+
16
+ - `toMatchSnapshot`, `toMatchInlineSnapshot`, `toMatchFileSnapshot`
17
+ - `toThrowErrorMatchingSnapshot`, `toThrowErrorMatchingInlineSnapshot`
18
+
19
+ Incorrect :
20
+
21
+ ```ts
22
+ expect(invoice.toState()).toMatchSnapshot();
23
+ expect(() => invoice.pay(at)).toThrowErrorMatchingInlineSnapshot();
24
+ ```
25
+
26
+ Correct :
27
+
28
+ ```ts
29
+ expect(invoice.toState()).toMatchObject({ status: 'paid', paidAt: at });
30
+
31
+ given(anInvoice().paid())
32
+ .when((invoice) => invoice.pay(at))
33
+ .thenError('INVOICE_ALREADY_PAID');
34
+ ```
35
+
36
+ ## Détails
37
+
38
+ Les contrats que le kit génère (OpenAPI, AsyncAPI, le catalogue d'événements) sont tenus par `ddd-ts-kit docs --check`, qui compare le document généré avec celui qui est *commité* : c'est le seul endroit où un document entier est comparé, et ce n'est pas un test.
39
+
40
+ ## Options
41
+
42
+ Aucune.
43
+
44
+ `rules."test/no-snapshot"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/no-snapshot -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
45
+
46
+ ## Limites
47
+
48
+ - Un `toEqual` sur un gros objet lu dans un fichier de *fixture* est un *snapshot* sous un autre nom, et n'est pas signalé.
49
+
50
+ ## Avec le checker de la CLI
51
+
52
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car lire un test demande un arbre syntaxique.
@@ -0,0 +1,51 @@
1
+ **English** · [Français](test-no-snapshot.fr.md)
2
+
3
+ # ddd-ts-kit/test-no-snapshot
4
+
5
+ Architecture id: `test/no-snapshot` (added by this plugin). Default severity: `error` in `recommended`, `error` in `strict`.
6
+
7
+ Applies to: every test file of the project (`*.spec.ts`, `*.test.ts`, the `test/` of a context).
8
+
9
+ ## Why
10
+
11
+ A snapshot records whatever the code produced the first time, and is renewed with one flag the next time it differs: it asserts nothing a reader can check against the rule, and it fails on every field the rule does not depend on. A test states the fields that matter, built in the test, so that the reader sees the cause of the outcome.
12
+
13
+ ## Reported
14
+
15
+ - `toMatchSnapshot`, `toMatchInlineSnapshot`, `toMatchFileSnapshot`
16
+ - `toThrowErrorMatchingSnapshot`, `toThrowErrorMatchingInlineSnapshot`
17
+
18
+ Incorrect:
19
+
20
+ ```ts
21
+ expect(invoice.toState()).toMatchSnapshot();
22
+ expect(() => invoice.pay(at)).toThrowErrorMatchingInlineSnapshot();
23
+ ```
24
+
25
+ Correct:
26
+
27
+ ```ts
28
+ expect(invoice.toState()).toMatchObject({ status: 'paid', paidAt: at });
29
+
30
+ given(anInvoice().paid())
31
+ .when((invoice) => invoice.pay(at))
32
+ .thenError('INVOICE_ALREADY_PAID');
33
+ ```
34
+
35
+ ## Details
36
+
37
+ The contracts the kit generates (OpenAPI, AsyncAPI, the event catalogue) are held by `ddd-ts-kit docs --check`, which compares the generated document with the committed one: that is the one place a whole document is compared, and it is not a test.
38
+
39
+ ## Options
40
+
41
+ None.
42
+
43
+ `rules."test/no-snapshot"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/no-snapshot -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
44
+
45
+ ## Limits
46
+
47
+ - `toEqual` on a large object read from a fixture file is a snapshot by another name, and is not reported.
48
+
49
+ ## With the CLI checker
50
+
51
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
@@ -0,0 +1,65 @@
1
+ [English](test-refusal-by-code.md) · **Français**
2
+ <!-- translation-of: test-refusal-by-code.md sha256:d0f4cd2f5172b6e2 -->
3
+
4
+ # ddd-ts-kit/test-refusal-by-code
5
+
6
+ Identifiant d'architecture : `test/refusal-by-code` (ajouté par ce *plugin*). Sévérité par défaut : `warn` dans `recommended` (une erreur à partir de 0.90.0 : `ddd-ts-kit lint` montre ses avertissements sans échouer dessus jusque-là), `error` dans `strict`.
7
+
8
+ S'applique à : les *specs* du modèle et de l'application, `test/unit/` d'un contexte, le noyau partagé, `test/e2e/` et `test/acceptance/` (`*.spec.ts`, `*.test.ts`). Les *specs* des adaptateurs (`*.adapter.spec.ts`, `test/integration/`) et de la plateforme ne sont pas jugées.
9
+
10
+ ## Pourquoi
11
+
12
+ Un refus du modèle porte un code et ses faits (`INVOICE_ALREADY_PAID`, `{ invoiceId }`) : le client les reçoit dans le document de problème, le catalogue du contexte les liste, le lecteur du test apprend quelle règle a refusé. Un message est de la prose qu'une reformulation change sans changer la règle ; la classe d'une erreur est une implémentation que les fabriques de `domain/errors/` peuvent fondre dans une autre. Un `toThrow()` sans argument accepte n'importe quel échec, un `TypeError` du test compris.
13
+
14
+ ## Signalé
15
+
16
+ `toThrow` et `toThrowError`, après `expect(action)` ou `expect(promise).rejects`, quand leur argument est :
17
+
18
+ - rien
19
+ - une chaîne, un gabarit ou une expression régulière (un message)
20
+ - une classe, une variable ou `new Error(...)`
21
+
22
+ Incorrect :
23
+
24
+ ```ts
25
+ expect(() => invoice.pay(at)).toThrow('already paid');
26
+ expect(() => invoice.pay(at)).toThrow(InvoiceAlreadyPaid);
27
+ expect(() => Email.create(' ')).toThrow();
28
+ await expect(bus.execute(command)).rejects.toThrowError(/forbidden/);
29
+ ```
30
+
31
+ Correct :
32
+
33
+ ```ts
34
+ given(anInvoice().paid())
35
+ .when((invoice) => invoice.pay(at))
36
+ .thenError('INVOICE_ALREADY_PAID', { invoiceId: 'invoice-1' });
37
+
38
+ expectRefusal(() => Email.create(' '), 'INVALID_EMAIL', { given: ' ' });
39
+
40
+ await expect(bus.execute(command)).rejects.toMatchObject({ code: 'FORBIDDEN' });
41
+
42
+ expectProblem(response, { status: 409, code: 'SLOT_TAKEN' });
43
+ ```
44
+
45
+ ## Détails
46
+
47
+ `expect(action).not.toThrow()` dit qu'une action est acceptée et n'est pas signalé. `toThrow(expect.objectContaining({ code: 'INVOICE_ALREADY_PAID' }))` et `toThrow({ code: ... })` vérifient le code et ne sont pas signalés non plus, même si `thenError` et `expectRefusal` le disent plus court et comparent les faits.
48
+
49
+ Un échec que le test a lui-même injecté (`mailer.failNextWith(outage)`, un *middleware* qui lève) se vérifie comme lui-même, `await expect(bus.execute(command)).rejects.toBe(outage)` : c'est la preuve que cet échec, et pas un autre de même message, est remonté.
50
+
51
+ Un adaptateur, les *specs* d'intégration d'un contexte et la plateforme font face au système extérieur et à la machine : leurs échecs sont techniques (`KEYCLOAK_URL is not set`, `Keycloak answered 403`), leur message est ce qu'un opérateur lit, et c'est ce que leurs *specs* vérifient. Ils ne sont pas jugés.
52
+
53
+ ## Options
54
+
55
+ Aucune.
56
+
57
+ `rules."test/refusal-by-code"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/refusal-by-code -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
58
+
59
+ ## Limites
60
+
61
+ - Un *matcher* du projet qui compare un message (`expectFailure(action, 'message')`) n'est pas lu.
62
+
63
+ ## Avec le checker de la CLI
64
+
65
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car lire un test demande un arbre syntaxique.
@@ -0,0 +1,64 @@
1
+ **English** · [Français](test-refusal-by-code.fr.md)
2
+
3
+ # ddd-ts-kit/test-refusal-by-code
4
+
5
+ Architecture id: `test/refusal-by-code` (added by this plugin). Default severity: `warn` in `recommended` (an error from 0.90.0: `ddd-ts-kit lint` shows its warnings without failing on them until then), `error` in `strict`.
6
+
7
+ Applies to: the specs of the model and of the application, `test/unit/` of a context, the shared kernel, `test/e2e/` and `test/acceptance/` (`*.spec.ts`, `*.test.ts`). The specs of the adapters (`*.adapter.spec.ts`, `test/integration/`) and of the platform are not judged.
8
+
9
+ ## Why
10
+
11
+ A refusal of the model carries a code and its facts (`INVOICE_ALREADY_PAID`, `{ invoiceId }`): the client receives them in the problem document, the catalogue of the context lists them, the reader of the test learns which rule refused. A message is prose that a rewording changes without changing the rule; the class of one error is an implementation the factories of `domain/errors/` may fold into another. A `toThrow()` without an argument accepts any failure, a `TypeError` of the test included.
12
+
13
+ ## Reported
14
+
15
+ `toThrow` and `toThrowError`, after `expect(action)` or `expect(promise).rejects`, when their argument is:
16
+
17
+ - nothing
18
+ - a string, a template or a regular expression (a message)
19
+ - a class, a variable or `new Error(...)`
20
+
21
+ Incorrect:
22
+
23
+ ```ts
24
+ expect(() => invoice.pay(at)).toThrow('already paid');
25
+ expect(() => invoice.pay(at)).toThrow(InvoiceAlreadyPaid);
26
+ expect(() => Email.create(' ')).toThrow();
27
+ await expect(bus.execute(command)).rejects.toThrowError(/forbidden/);
28
+ ```
29
+
30
+ Correct:
31
+
32
+ ```ts
33
+ given(anInvoice().paid())
34
+ .when((invoice) => invoice.pay(at))
35
+ .thenError('INVOICE_ALREADY_PAID', { invoiceId: 'invoice-1' });
36
+
37
+ expectRefusal(() => Email.create(' '), 'INVALID_EMAIL', { given: ' ' });
38
+
39
+ await expect(bus.execute(command)).rejects.toMatchObject({ code: 'FORBIDDEN' });
40
+
41
+ expectProblem(response, { status: 409, code: 'SLOT_TAKEN' });
42
+ ```
43
+
44
+ ## Details
45
+
46
+ `expect(action).not.toThrow()` says that an action is accepted and is not reported. `toThrow(expect.objectContaining({ code: 'INVOICE_ALREADY_PAID' }))` and `toThrow({ code: ... })` assert the code and are not reported either, although `thenError` and `expectRefusal` say it shorter and compare the facts.
47
+
48
+ A failure the test itself injected (`mailer.failNextWith(outage)`, a middleware that throws) is asserted as itself, `await expect(bus.execute(command)).rejects.toBe(outage)`: the proof that this failure, and not another with the same message, came through.
49
+
50
+ An adapter, the integration specs of a context and the platform face the outside system and the machine: their failures are technical (`KEYCLOAK_URL is not set`, `Keycloak answered 403`), their message is what an operator reads, and it is what their specs assert. They are not judged.
51
+
52
+ ## Options
53
+
54
+ None.
55
+
56
+ `rules."test/refusal-by-code"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/refusal-by-code -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
57
+
58
+ ## Limits
59
+
60
+ - A matcher of the project that compares a message (`expectFailure(action, 'message')`) is not read.
61
+
62
+ ## With the CLI checker
63
+
64
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
@@ -0,0 +1,63 @@
1
+ [English](test-title-states-a-rule.md) · **Français**
2
+ <!-- translation-of: test-title-states-a-rule.md sha256:9de5d77beee52337 -->
3
+
4
+ # ddd-ts-kit/test-title-states-a-rule
5
+
6
+ Identifiant d'architecture : `test/title-states-a-rule` (ajouté par ce *plugin*). Sévérité par défaut : `warn` dans `recommended` (une erreur à partir de 0.90.0 : `ddd-ts-kit lint` montre ses avertissements sans échouer dessus jusque-là), `error` dans `strict`.
7
+
8
+ S'applique à : chaque fichier de test du projet (`*.spec.ts`, `*.test.ts`, le `test/` d'un contexte).
9
+
10
+ ## Pourquoi
11
+
12
+ Les titres d'une *spec* en sont la seule partie que toute l'équipe lit : le rapport d'une exécution en échec, la liste qu'imprime `npm test`, la revue. Écrits comme des règles, dans les mots du métier, ils sont la spécification de l'unité, et un nouveau test s'écrit en énonçant une règle de plus. Écrits `should ...`, `test ...` ou d'après une méthode, ils disent que quelque chose est testé sans dire ce qui est vrai, et le lecteur ouvre le corps pour le savoir.
13
+
14
+ ## Signalé
15
+
16
+ Sur un `it` ou un `test`, après les *rows* et le critère que le titre cite (`#US5.02 AC1 ...`, `AC1 ...`, `#FIX-412 ...`) :
17
+
18
+ - un mot qui dit que le test est un test : `should`, `test`, `tests`, `testing`, `works`, `correctly`, `properly`, `successfully`, `as expected`, `make sure`, `ensures that`, `verifies that`, `checks that`
19
+ - un nom de code : un appel (`execute()`, `pay(at)`), un premier mot en camelCase (`issueInvoice`)
20
+ - un premier mot qui ne commence pas par une minuscule (`Refuses`, `The invoice`), sauf s'il est le paramètre d'un titre piloté par une table (`%s`, `$kind`)
21
+ - un titre vide
22
+
23
+ Sur un `describe` : un titre nommé d'après les tests (`tests`, `spec`, `suite`, `should`, un suffixe `Spec` ou `Test`) ou vide.
24
+
25
+ Incorrect :
26
+
27
+ ```ts
28
+ describe('Invoice tests', () => {
29
+ it('should refuse a second payment', () => { ... });
30
+ it('execute() saves the invoice', () => { ... });
31
+ it('Pays the invoice correctly', () => { ... });
32
+ });
33
+ ```
34
+
35
+ Correct :
36
+
37
+ ```ts
38
+ describe('Invoice', () => {
39
+ it('refuses to pay an invoice twice', () => { ... });
40
+ it('saves the invoice and answers its identifier', () => { ... });
41
+ it('#US5.02 AC1 a customer places an order', pending(async () => { ... }));
42
+ it.each(kinds)('%s announces an appointment to come', (kind) => { ... });
43
+ });
44
+ ```
45
+
46
+ ## Détails
47
+
48
+ Un titre tenu dans une variable n'est pas jugé. Un titre en gabarit est lu avec ses expressions comme paramètres : `` `answers ${status} to a caller` `` passe, et de même un titre qui commence par une expression. `describe` prend l'unité sous test, l'agrégat (`Invoice`), le cas d'usage (`Issue invoice`), la route (`POST /invoices`), un fait (`When scheduling publishes scheduling.appointment.booked`) : un nom, dans la casse qu'il a.
49
+
50
+ ## Options
51
+
52
+ Aucune.
53
+
54
+ `rules."test/title-states-a-rule"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/title-states-a-rule -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
55
+
56
+ ## Limites
57
+
58
+ - La règle lit la forme d'un titre, pas son sens : `records the payment` passe, que le test enregistre un paiement ou non. La revue lit le corps.
59
+ - Un verbe est reconnu à sa casse, pas à un dictionnaire : `the invoice is paid` passe.
60
+
61
+ ## Avec le checker de la CLI
62
+
63
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car lire un test demande un arbre syntaxique.
@@ -0,0 +1,62 @@
1
+ **English** · [Français](test-title-states-a-rule.fr.md)
2
+
3
+ # ddd-ts-kit/test-title-states-a-rule
4
+
5
+ Architecture id: `test/title-states-a-rule` (added by this plugin). Default severity: `warn` in `recommended` (an error from 0.90.0: `ddd-ts-kit lint` shows its warnings without failing on them until then), `error` in `strict`.
6
+
7
+ Applies to: every test file of the project (`*.spec.ts`, `*.test.ts`, the `test/` of a context).
8
+
9
+ ## Why
10
+
11
+ The titles of a spec are the only part of it the whole team reads: the report of a failed run, the list `npm test` prints, the review. Written as rules, in the words of the business, they are the specification of the unit, and a new test is written by stating one more rule. Written as `should ...`, `test ...` or after a method, they say that something is tested without saying what is true, and the reader opens the body to find out.
12
+
13
+ ## Reported
14
+
15
+ On an `it` or a `test`, after the rows and the criterion the title cites (`#US5.02 AC1 ...`, `AC1 ...`, `#FIX-412 ...`):
16
+
17
+ - a word that says the test is a test: `should`, `test`, `tests`, `testing`, `works`, `correctly`, `properly`, `successfully`, `as expected`, `make sure`, `ensures that`, `verifies that`, `checks that`
18
+ - a name of code: a call (`execute()`, `pay(at)`), a first word in camelCase (`issueInvoice`)
19
+ - a first word that does not start with a lower-case letter (`Refuses`, `The invoice`), unless it is the placeholder of a table-driven title (`%s`, `$kind`)
20
+ - an empty title
21
+
22
+ On a `describe`: a title named after the tests (`tests`, `spec`, `suite`, `should`, a `Spec` or `Test` suffix) or empty.
23
+
24
+ Incorrect:
25
+
26
+ ```ts
27
+ describe('Invoice tests', () => {
28
+ it('should refuse a second payment', () => { ... });
29
+ it('execute() saves the invoice', () => { ... });
30
+ it('Pays the invoice correctly', () => { ... });
31
+ });
32
+ ```
33
+
34
+ Correct:
35
+
36
+ ```ts
37
+ describe('Invoice', () => {
38
+ it('refuses to pay an invoice twice', () => { ... });
39
+ it('saves the invoice and answers its identifier', () => { ... });
40
+ it('#US5.02 AC1 a customer places an order', pending(async () => { ... }));
41
+ it.each(kinds)('%s announces an appointment to come', (kind) => { ... });
42
+ });
43
+ ```
44
+
45
+ ## Details
46
+
47
+ A title held in a variable is not judged. A template title is read with its expressions as placeholders: `` `answers ${status} to a caller` `` passes, and so does one that starts with an expression. `describe` takes the unit under test, the aggregate (`Invoice`), the use case (`Issue invoice`), the route (`POST /invoices`), a fact (`When scheduling publishes scheduling.appointment.booked`): a noun, in any case.
48
+
49
+ ## Options
50
+
51
+ None.
52
+
53
+ `rules."test/title-states-a-rule"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/title-states-a-rule -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
54
+
55
+ ## Limits
56
+
57
+ - The rule reads the form of a title, not its meaning: `records the payment` passes whether or not the test records a payment. The review reads the body.
58
+ - A verb is recognised by its case, not by a dictionary: `the invoice is paid` passes.
59
+
60
+ ## With the CLI checker
61
+
62
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts-kit/eslint-plugin",
3
- "version": "0.87.0",
3
+ "version": "0.89.0",
4
4
  "description": "AST-accurate ESLint rules for DDD and Clean Architecture in TypeScript: layer and context isolation, domain purity, clean code ordering.",
5
5
  "keywords": [
6
6
  "ddd",