@jterrazz/test 15.1.1 → 15.3.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.
- package/README.md +38 -29
- package/dist/ambiguity.js +23 -4
- package/dist/artifacts.js +108 -163
- package/dist/browser/index.js +2796 -0
- package/dist/checker.js +470 -29
- package/dist/index.d.ts +1434 -609
- package/dist/index.js +3696 -2745
- package/dist/intercept.js +117 -59
- package/dist/oxlint.cjs +481 -35
- package/dist/oxlint.d.cts +13 -1
- package/dist/oxlint.d.ts +13 -1
- package/dist/oxlint.js +481 -35
- package/dist/playwright.adapter.js +96 -22
- package/dist/{queue.js → stream.js} +61 -2
- package/dist/vitest.d.ts +130 -2
- package/dist/vitest.js +433 -3
- package/package.json +37 -5
package/dist/oxlint.js
CHANGED
|
@@ -169,9 +169,6 @@ function walk(root, visit) {
|
|
|
169
169
|
} else if (isNode(value)) walk(value, visit);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
function isNode(value) {
|
|
173
|
-
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
174
|
-
}
|
|
175
172
|
/** The source start offset of a node or comment (oxlint `start`, else `range[0]`). */
|
|
176
173
|
function nodeStart(node) {
|
|
177
174
|
if (node === void 0) return -1;
|
|
@@ -218,6 +215,27 @@ function importSourceVisitor(onSource) {
|
|
|
218
215
|
ImportExpression: fromSourceField
|
|
219
216
|
};
|
|
220
217
|
}
|
|
218
|
+
/** Is this value an AST node — an object carrying a `type` string? */
|
|
219
|
+
function isNode(value) {
|
|
220
|
+
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A node's child by key, or `undefined` when the key holds something else.
|
|
224
|
+
*
|
|
225
|
+
* Every rule reaches for `node.parent`, `node.id`, `node.value`; the node shape
|
|
226
|
+
* types them as `unknown`, so each reach was an assertion of its own. One
|
|
227
|
+
* guarded read is the same answer, checked once.
|
|
228
|
+
*/
|
|
229
|
+
function child(node, key) {
|
|
230
|
+
const value = node?.[key];
|
|
231
|
+
return isNode(value) ? value : void 0;
|
|
232
|
+
}
|
|
233
|
+
/** The name of an identifier node, or `undefined` for anything else. */
|
|
234
|
+
function identifierName(node) {
|
|
235
|
+
if (node?.type !== "Identifier") return;
|
|
236
|
+
const { name } = node;
|
|
237
|
+
return typeof name === "string" ? name : void 0;
|
|
238
|
+
}
|
|
221
239
|
//#endregion
|
|
222
240
|
//#region src/lint/manifest.ts
|
|
223
241
|
/**
|
|
@@ -262,7 +280,7 @@ const RULE_DOCS = {
|
|
|
262
280
|
},
|
|
263
281
|
"a2-known-constructors": {
|
|
264
282
|
channel: "statique",
|
|
265
|
-
convention: "
|
|
283
|
+
convention: "Six constructeurs et seulement six : `specification.api()`, `specification.jobs()`, `specification.cli(bin)`, `specification.integration()`, `specification.website()`, `specification.mobile()` ; tout autre membre (`.app`, `.http`, `.stack`…) est une erreur. Un composant rendu ne démarre rien : c’est une chaîne, pas un membre de ce record.",
|
|
266
284
|
family: "A",
|
|
267
285
|
id: "A2",
|
|
268
286
|
rationale: "Une surface fermée empêche l’invention de constructeurs parallèles et garde l’API mémorisable."
|
|
@@ -346,7 +364,7 @@ const RULE_DOCS = {
|
|
|
346
364
|
},
|
|
347
365
|
"c1-domain-structure": {
|
|
348
366
|
channel: "statique",
|
|
349
|
-
convention: "La forme de l’arbre `specs/` se déclare via l’option `depth` : `facet-domain` (défaut — `*.test.ts` à la profondeur facet/domain, `*.specification.ts` au root de la facette), `facet` (test au root de la facette OU un dossier domaine plus bas, jamais plus profond), `mirror` (test à toute profondeur ≥ 1, nommé d’après son dossier), `off`. Dans tous les modes, `off` compris : un dossier à underscore initial est du SOL, jamais un domaine — aucune spec ne vit dedans. Une exception, et une seule : le sol peut être du CODE, et un `<module>.test.ts` posé À CÔTÉ du `<module>.ts` qu’il teste y est légal (c’est la loi I2) ; un test sans module voisin, ou un `*.specification.ts`, reste une violation.",
|
|
367
|
+
convention: "La forme de l’arbre `specs/` se déclare via l’option `depth` : `facet-domain` (défaut — `*.test.ts` à la profondeur facet/domain, `*.specification.ts` au root de la facette), `facet` (test au root de la facette OU un dossier domaine plus bas, jamais plus profond), `mirror` (test à toute profondeur ≥ 1, nommé d’après son dossier), `off`. Dans tous les modes, `off` compris : un dossier à underscore initial est du SOL, jamais un domaine — aucune spec ne vit dedans. Une exception, et une seule : le sol peut être du CODE, et un `<module>.test.ts` posé À CÔTÉ du `<module>.ts` qu’il teste y est légal (c’est la loi I2) ; un test sans module voisin, ou un `*.specification.ts`, reste une violation. Un `.test.tsx` est hors de portée : une unité rendue se spécifie à côté de son composant, jamais dans un arbre facette/domaine — c’est I2 qui tient son voisinage.",
|
|
350
368
|
family: "C",
|
|
351
369
|
id: "C1",
|
|
352
370
|
rationale: "Une profondeur fixe rend la place de chaque fichier prévisible et détectable statiquement."
|
|
@@ -463,6 +481,36 @@ const RULE_DOCS = {
|
|
|
463
481
|
id: "D15",
|
|
464
482
|
rationale: "Un statut isolé ne fige que le code de réponse et jette tout le reste du payload ; le golden complet capture la forme entière et sa grammaire de tokens (complète d12w, qui exige un amas de sondes de corps et manque le cas de la sonde de statut solitaire)."
|
|
465
483
|
},
|
|
484
|
+
"e5-no-simulated-dom": {
|
|
485
|
+
channel: "statique",
|
|
486
|
+
convention: "Un fichier de test ne déclare pas de DOM simulé : la pragma `@vitest-environment happy-dom|jsdom` est une erreur. Portée : les rôles qui EXÉCUTENT un test (`module`, `component`, `specification`) — une config de projet est le domaine de E5b.",
|
|
487
|
+
facet: "component",
|
|
488
|
+
family: "E",
|
|
489
|
+
fix: "Déplacer le test à côté de son composant en `.test.tsx` et le faire collecter par le projet `component()`.",
|
|
490
|
+
id: "E5",
|
|
491
|
+
rationale: "Un DOM simulé se comporte PRESQUE comme un navigateur, et ce qui est livré est jugé par un vrai : la facette component rend dans le Chromium que la facette website pilote déjà.",
|
|
492
|
+
reach: "tests"
|
|
493
|
+
},
|
|
494
|
+
"e5b-no-simulated-dom-config": {
|
|
495
|
+
channel: "statique",
|
|
496
|
+
convention: "Une config vitest ne déclare pas de DOM simulé : `environment: 'happy-dom'|'jsdom'` est une erreur ; `'node'` et `'edge-runtime'` nomment un vrai runtime et restent hors de portée.",
|
|
497
|
+
facet: "component",
|
|
498
|
+
family: "E",
|
|
499
|
+
fix: "Supprimer `environment` et collecter le rendu avec `component()` ; les tests de module restent sous node.",
|
|
500
|
+
id: "E5b",
|
|
501
|
+
rationale: "La pragma (E5) n’engage qu’un fichier ; la config engage tout ce que le projet collecte — c’est ainsi qu’un dépôt hérite d’un DOM simulé que personne n’a choisi test par test.",
|
|
502
|
+
reach: "config"
|
|
503
|
+
},
|
|
504
|
+
"e6-component-project-helper": {
|
|
505
|
+
channel: "statique",
|
|
506
|
+
convention: "Un projet navigateur vient de `component()` : dans une config vitest, une clé `browser` sous `test` qui n'est pas dans un appel à `component(...)` est une erreur. Une clé `browser` ailleurs (un `define`, un enregistrement d'env) n'est pas un bloc de projet et reste hors de portée.",
|
|
507
|
+
facet: "component",
|
|
508
|
+
family: "E",
|
|
509
|
+
fix: "Remplacer le bloc par `component({ vite })` et ne garder que ce qui appartient au projet.",
|
|
510
|
+
id: "E6",
|
|
511
|
+
rationale: "Le provider épinglé à la version exacte du runner, le service worker servi depuis l’installation du framework, la transformation JSX du Vite courant, le pré-bundling d’un cache froid et les dossiers d’artefacts sont autant de runs qui passent ici et échouent sur la machine suivante.",
|
|
512
|
+
reach: "config"
|
|
513
|
+
},
|
|
466
514
|
"f1-no-subpath-import": {
|
|
467
515
|
channel: "statique",
|
|
468
516
|
convention: "Tout s’importe depuis `@jterrazz/test` ; un import de `@jterrazz/test/<subpath>` est une erreur, sauf les subpaths que la map `exports` du paquet publie — `@jterrazz/test/oxlint` (plugin de lint) et `@jterrazz/test/vitest` (surface de configuration du runner) — exemptés partout. La liste est LUE du manifeste, jamais recopiée dans la règle.",
|
|
@@ -479,7 +527,7 @@ const RULE_DOCS = {
|
|
|
479
527
|
},
|
|
480
528
|
"f3-specs-public-entry": {
|
|
481
529
|
channel: "statique",
|
|
482
|
-
convention: "Depuis `specs/`, seul l’import en profondeur des INTERNES du framework est interdit : un chemin relatif résolvant dans `src/{specification,integrations,vitest,lint}/` du dépôt du framework, ou tout `@jterrazz/test/<subpath>` que la map `exports` du paquet ne publie pas — les subpaths publiés sont exemptés, LUS du manifeste comme en F1, qui en tient la liste. Les imports de la source de SA PROPRE app par un consommateur sont toujours permis (c’est le motif documenté)
|
|
530
|
+
convention: "Depuis `specs/`, seul l’import en profondeur des INTERNES du framework est interdit : un chemin relatif résolvant dans `src/{specification,integrations,vitest,lint}/` du dépôt du framework, ou tout `@jterrazz/test/<subpath>` que la map `exports` du paquet ne publie pas — les subpaths publiés sont exemptés, LUS du manifeste comme en F1, qui en tient la liste. Les imports de la source de SA PROPRE app par un consommateur sont toujours permis (c’est le motif documenté). Aucune exception de dossier : une sonde qui ne peut pas atteindre son sujet par l’entrée publique est un test de module à côté de son module, pas une spec.",
|
|
483
531
|
family: "F",
|
|
484
532
|
id: "F3",
|
|
485
533
|
rationale: "Tester par la surface publique garde les specs découplées des chemins internes du framework, sans gêner le consommateur qui importe sa propre app."
|
|
@@ -498,6 +546,26 @@ const RULE_DOCS = {
|
|
|
498
546
|
id: "F5",
|
|
499
547
|
rationale: "Cantonner les fixtures aux tests empêche la donnée de test de fuir dans le code de prod."
|
|
500
548
|
},
|
|
549
|
+
"f6-no-foreign-test-runtime": {
|
|
550
|
+
channel: "statique",
|
|
551
|
+
convention: "Un fichier de test n’importe pas de second runtime de test : `@testing-library/*`, `happy-dom`, `jsdom`, `vitest/browser`, `vitest-browser-*` et `@vitest/browser*` sont des erreurs. Portée : les rôles qui EXÉCUTENT un test (`module`, `component`, `specification`) — la config d’un projet fixture et un module de providers sous `specs/` nomment légitimement l’adaptateur.",
|
|
552
|
+
facet: "component",
|
|
553
|
+
family: "F",
|
|
554
|
+
fix: "Passer par la facette qui remplace le seam : `component.render()`, le vocabulaire d’éléments et le visiteur.",
|
|
555
|
+
id: "F6",
|
|
556
|
+
rationale: "Un test qui importe l’adaptateur parle le dialecte de l’adaptateur : un dépôt finit avec autant de vocabulaires que de seams. Les groupes livrés sont ceux que la facette component REMPLACE ; le reste de la famille suit la vague de règles.",
|
|
557
|
+
reach: "tests"
|
|
558
|
+
},
|
|
559
|
+
"g4-no-dom-in-module-test": {
|
|
560
|
+
channel: "statique",
|
|
561
|
+
convention: "Un test de module ne touche aucun global du DOM : `document`, `window`, `navigator`, `HTMLElement` référencés en position de VALEUR dans un fichier de rôle `module` HORS de `specs/` sont une erreur. Un nom en position de type (`x as HTMLElement`) et un garde `typeof window` n’atteignent aucun document et restent hors de portée ; tant que le rôle `spec` n’existe pas, `module` couvre aussi les `.test.ts` de `specs/`, que la règle laisse donc passer.",
|
|
562
|
+
facet: "component",
|
|
563
|
+
family: "G",
|
|
564
|
+
fix: "Renommer le test en `.test.tsx` à côté du composant qu’il rend, et le faire collecter par `component()`.",
|
|
565
|
+
id: "G4",
|
|
566
|
+
rationale: "Un test de module tourne sous node, où `document` n’existe pas : un test qui en réclame un ne teste pas un module, il rend quelque chose — et il a désormais un endroit où aller.",
|
|
567
|
+
reach: "module"
|
|
568
|
+
},
|
|
501
569
|
"i1-layer-boundaries": {
|
|
502
570
|
channel: "statique",
|
|
503
571
|
convention: "Le projet DÉCLARE ses couches sous `src/` via l’option `layers` (paquets autorisés, imports internes, un dossier = une dépendance, seams) ; tout import hors des arêtes déclarées est une erreur. Sans carte de couches, la règle est inerte.",
|
|
@@ -507,9 +575,11 @@ const RULE_DOCS = {
|
|
|
507
575
|
},
|
|
508
576
|
"i2-sibling-test-naming": {
|
|
509
577
|
channel: "statique",
|
|
510
|
-
convention: "Le test de `<fichier>.ts` est `<fichier>.test.ts` à côté de lui ; un `.test.ts` mal nommé, ou un dossier `__tests__/`, est une erreur.",
|
|
578
|
+
convention: "Le test de `<fichier>.ts` est `<fichier>.test.ts` à côté de lui ; un `.test.ts` mal nommé, ou un dossier `__tests__/`, est une erreur. Une unité RENDUE obéit à la même loi où qu’elle vive : un `.test.tsx` est voisin du `.tsx` qu’il rend, ou du `.ts` du hook ou de la fonction DOM dont il porte l’hôte.",
|
|
511
579
|
family: "I",
|
|
580
|
+
fix: "Poser le test à côté de l’unité qu’il couvre, sous le même basename.",
|
|
512
581
|
id: "I2",
|
|
582
|
+
reach: "tests",
|
|
513
583
|
rationale: "Des tests voisins (parité avec le `foo_test.go` de Go) gardent test et code ensemble et découvrables."
|
|
514
584
|
},
|
|
515
585
|
"i4-no-vi-mock-in-src": {
|
|
@@ -549,6 +619,39 @@ const RULE_DOCS = {
|
|
|
549
619
|
* visits data fixtures nor reads two files at once, so these ship separately.
|
|
550
620
|
*/
|
|
551
621
|
const CHECKER_PASSES = [
|
|
622
|
+
{
|
|
623
|
+
channel: "checker",
|
|
624
|
+
convention: "Chaque membre du workspace qui a des tests À LUI (un script `test` qui ne délègue pas aux membres, ou un `*.test.ts(x)` hors de l’arbre d’un autre paquet) déclare une config vitest (`vitest.config.*`). La passe MEMBRE juge le membre lui-même, avec ou sans arbre `specs/` ; une racine qui ne fait que déléguer ne doit rien.",
|
|
625
|
+
facet: "shared",
|
|
626
|
+
family: "E",
|
|
627
|
+
fix: "Écrire `export default defineSpecConfig()` dans le membre — le préréglage porte les budgets, le dossier d’artefacts et l’exclusion de `_fixtures/`.",
|
|
628
|
+
id: "E3",
|
|
629
|
+
name: "e3-config-present",
|
|
630
|
+
rationale: "Sans config, le budget de 5 s de vitest et un `_fixtures/` non exclu font tourner les tests du membre : le défaut n’est pas choisi, il est hérité.",
|
|
631
|
+
reach: "config"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
channel: "checker",
|
|
635
|
+
convention: "La passe MEMBRE relit la règle E5b là où oxlint peut ne pas atteindre la config d’un membre : `environment: 'happy-dom'|'jsdom'` dans un `vitest.config.*` est une erreur.",
|
|
636
|
+
facet: "component",
|
|
637
|
+
family: "E",
|
|
638
|
+
fix: "Supprimer `environment` et collecter le rendu avec `component()`.",
|
|
639
|
+
id: "E5b",
|
|
640
|
+
name: "e5b-no-simulated-dom-config-member",
|
|
641
|
+
rationale: "La passe statique ne voit que ce que la configuration oxlint du dépôt lui donne ; la passe membre part du manifeste racine et atteint chaque membre déclaré.",
|
|
642
|
+
reach: "config"
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
channel: "checker",
|
|
646
|
+
convention: "Un membre ne déclare aucune dépendance que `@jterrazz/test` porte déjà (`msw`, `vitest-mock-extended` ; `yaml` en devDependencies seulement — en dépendance de production c’est la bibliothèque du produit) ni aucun seam retiré (`happy-dom`, `jsdom`, `@testing-library/*`, `@playwright/test`, `mockdate`). Les peers optionnels — `playwright`, `vite`, `react`, `better-sqlite3`, `pg`, `redis`, `testcontainers`… — sont déclarés par le consommateur, à dessein.",
|
|
647
|
+
facet: "shared",
|
|
648
|
+
family: "F",
|
|
649
|
+
fix: "Retirer la déclaration : une transitive est déjà résolue par le paquet ; un seam retiré a une facette qui le remplace (`component()`, `website()`, `clock`, `intercept()`). Les deux cas ont leur propre phrase dans le diagnostic.",
|
|
650
|
+
id: "F8",
|
|
651
|
+
name: "f8-no-seam-dependency",
|
|
652
|
+
rationale: "Une déclaration en double laisse deux versions d’un même seam coexister, et un seam retiré garde un vocabulaire que le framework a remplacé.",
|
|
653
|
+
reach: "config"
|
|
654
|
+
},
|
|
552
655
|
{
|
|
553
656
|
channel: "checker",
|
|
554
657
|
convention: "Tout `{{token}}` dans une fixture `_expected/` — ou dans un flux attendu d’un document `<cas>.spec.yaml` — appartient au vocabulaire figé ; un token inconnu est une erreur.",
|
|
@@ -840,14 +943,19 @@ function sortKey(entry) {
|
|
|
840
943
|
];
|
|
841
944
|
}
|
|
842
945
|
[
|
|
843
|
-
...Object.entries(RULE_DOCS).map(([name, doc]) =>
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
946
|
+
...Object.entries(RULE_DOCS).map(([name, doc]) => {
|
|
947
|
+
const entry = {
|
|
948
|
+
channel: doc.channel,
|
|
949
|
+
convention: doc.convention,
|
|
950
|
+
family: doc.family,
|
|
951
|
+
id: doc.id,
|
|
952
|
+
name,
|
|
953
|
+
rationale: doc.rationale
|
|
954
|
+
};
|
|
955
|
+
if ("fix" in doc) entry.fix = doc.fix;
|
|
956
|
+
if ("reach" in doc) entry.reach = doc.reach;
|
|
957
|
+
return entry;
|
|
958
|
+
}),
|
|
851
959
|
...CHECKER_PASSES,
|
|
852
960
|
...RUNTIME_RULES,
|
|
853
961
|
...PROCESS_RULES
|
|
@@ -859,6 +967,55 @@ function sortKey(entry) {
|
|
|
859
967
|
return av.localeCompare(bv);
|
|
860
968
|
});
|
|
861
969
|
//#endregion
|
|
970
|
+
//#region src/lint/role.ts
|
|
971
|
+
/** The four ground names — what the specs of a row stand ON, never a spec. */
|
|
972
|
+
const GROUND = /* @__PURE__ */ new Set([
|
|
973
|
+
"_expected",
|
|
974
|
+
"_fixtures",
|
|
975
|
+
"_requests",
|
|
976
|
+
"_seeds"
|
|
977
|
+
]);
|
|
978
|
+
/** A vitest config, whatever extension the project writes it in. */
|
|
979
|
+
const CONFIG = /^vitest\.config\.[cm]?[jt]s$/u;
|
|
980
|
+
/**
|
|
981
|
+
* The kind of file this path names.
|
|
982
|
+
*
|
|
983
|
+
* The suffix decides, and the order matters: a `*.specification.ts` is a
|
|
984
|
+
* specification wherever it sits, ground swallows anything under it that is not
|
|
985
|
+
* a test of its own module, and `.tsx` versus `.ts` is what tells a RENDERED
|
|
986
|
+
* unit from a plain one — the same distinction the two project helpers collect
|
|
987
|
+
* on, so a file is judged by the rules of the project that actually runs it.
|
|
988
|
+
*/
|
|
989
|
+
function roleOf(filename) {
|
|
990
|
+
const parts = segments(filename);
|
|
991
|
+
const base = parts.at(-1) ?? "";
|
|
992
|
+
const inSpecs = isUnderSpecs(filename);
|
|
993
|
+
if (base.endsWith(".specification.ts") || base.endsWith(".specification.tsx")) return {
|
|
994
|
+
inSpecs,
|
|
995
|
+
role: "specification"
|
|
996
|
+
};
|
|
997
|
+
if (CONFIG.test(base)) return {
|
|
998
|
+
inSpecs,
|
|
999
|
+
role: "config"
|
|
1000
|
+
};
|
|
1001
|
+
if (base.endsWith(".test.tsx")) return {
|
|
1002
|
+
inSpecs,
|
|
1003
|
+
role: "component"
|
|
1004
|
+
};
|
|
1005
|
+
if (base.endsWith(".test.ts")) return {
|
|
1006
|
+
inSpecs,
|
|
1007
|
+
role: "module"
|
|
1008
|
+
};
|
|
1009
|
+
if (parts.slice(0, -1).some((segment) => GROUND.has(segment))) return {
|
|
1010
|
+
inSpecs,
|
|
1011
|
+
role: "ground"
|
|
1012
|
+
};
|
|
1013
|
+
return {
|
|
1014
|
+
inSpecs,
|
|
1015
|
+
role: "other"
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
//#endregion
|
|
862
1019
|
//#region src/lint/rules/a1-specification-file.ts
|
|
863
1020
|
const SPECIFICATION_SUFFIX$2 = ".specification.ts";
|
|
864
1021
|
/**
|
|
@@ -869,10 +1026,15 @@ const SPECIFICATION_SUFFIX$2 = ".specification.ts";
|
|
|
869
1026
|
* Framework-internal unit tests of the constructors themselves (this repo's
|
|
870
1027
|
* `src/**\/*.test.ts`) disable the rule via a config override — for consumers
|
|
871
1028
|
* the rule is universal.
|
|
1029
|
+
*
|
|
1030
|
+
* The A family does not reach a `component`-role file. A rendered unit has no
|
|
1031
|
+
* runner to create: no server to start, no database to isolate, no binary to
|
|
1032
|
+
* find — which is why the component facet has no constructor and no
|
|
1033
|
+
* specification file for A1 to point at.
|
|
872
1034
|
*/
|
|
873
1035
|
const a1SpecificationFile = {
|
|
874
1036
|
create(context) {
|
|
875
|
-
if (context.filename.endsWith(SPECIFICATION_SUFFIX$2)) return {};
|
|
1037
|
+
if (context.filename.endsWith(SPECIFICATION_SUFFIX$2) || roleOf(context.physicalFilename).role === "component") return {};
|
|
876
1038
|
return { CallExpression(node) {
|
|
877
1039
|
const member = specificationMember(node);
|
|
878
1040
|
if (member !== void 0) context.report({
|
|
@@ -890,19 +1052,22 @@ const a1SpecificationFile = {
|
|
|
890
1052
|
};
|
|
891
1053
|
//#endregion
|
|
892
1054
|
//#region src/lint/rules/a2-known-constructors.ts
|
|
893
|
-
/** The
|
|
1055
|
+
/** The six constructors, and only six (A2 — see docs/13-linting.md). */
|
|
894
1056
|
const KNOWN_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
895
1057
|
"api",
|
|
896
1058
|
"cli",
|
|
1059
|
+
"integration",
|
|
897
1060
|
"jobs",
|
|
898
1061
|
"mobile",
|
|
899
1062
|
"website"
|
|
900
1063
|
]);
|
|
901
1064
|
/**
|
|
902
1065
|
* CONVENTIONS A2 — `specification.api()`, `specification.jobs()`,
|
|
903
|
-
* `specification.cli()`, `specification.
|
|
904
|
-
* `specification.mobile()` are the only
|
|
905
|
-
* (`specification.app`, `.http`, `.stack`, …) is
|
|
1066
|
+
* `specification.cli()`, `specification.integration()`,
|
|
1067
|
+
* `specification.website()` and `specification.mobile()` are the only
|
|
1068
|
+
* members. Any other access (`specification.app`, `.http`, `.stack`, …) is
|
|
1069
|
+
* flagged at the member site. A rendered component has no constructor: it
|
|
1070
|
+
* starts nothing, so it is a chain, not a member of this record.
|
|
906
1071
|
*/
|
|
907
1072
|
const a2KnownConstructors = {
|
|
908
1073
|
create(context) {
|
|
@@ -919,7 +1084,7 @@ const a2KnownConstructors = {
|
|
|
919
1084
|
},
|
|
920
1085
|
meta: {
|
|
921
1086
|
docs: RULE_DOCS["a2-known-constructors"],
|
|
922
|
-
messages: { unknownConstructor: "specification.{{member}} does not exist — the only constructors are specification.api(), specification.jobs(), specification.cli(), specification.website() and specification.mobile() (A2 — see docs/13-linting.md)." },
|
|
1087
|
+
messages: { unknownConstructor: "specification.{{member}} does not exist — the only constructors are specification.api(), specification.jobs(), specification.cli(), specification.integration(), specification.website() and specification.mobile() (A2 — see docs/13-linting.md)." },
|
|
923
1088
|
type: "problem"
|
|
924
1089
|
}
|
|
925
1090
|
};
|
|
@@ -2839,6 +3004,122 @@ const d15wStatusOnlyProbe = {
|
|
|
2839
3004
|
}
|
|
2840
3005
|
};
|
|
2841
3006
|
//#endregion
|
|
3007
|
+
//#region src/lint/rules/e5-no-simulated-dom.ts
|
|
3008
|
+
/** The pragma vitest reads to swap a test file's environment. */
|
|
3009
|
+
const PRAGMA = /@vitest-environment\s+(?<environment>[\w-]+)/u;
|
|
3010
|
+
/** The two simulated DOMs. */
|
|
3011
|
+
const SIMULATED$1 = /* @__PURE__ */ new Set(["happy-dom", "jsdom"]);
|
|
3012
|
+
/** The roles that RUN a test file — the only ones a pragma steers. */
|
|
3013
|
+
const REACHED$1 = /* @__PURE__ */ new Set([
|
|
3014
|
+
"component",
|
|
3015
|
+
"module",
|
|
3016
|
+
"specification"
|
|
3017
|
+
]);
|
|
3018
|
+
/**
|
|
3019
|
+
* CONVENTIONS E5 — no simulated DOM, stated per file.
|
|
3020
|
+
*
|
|
3021
|
+
* `@vitest-environment happy-dom` buys a document that behaves almost like a
|
|
3022
|
+
* browser's: almost is the whole problem, because what ships is judged by a
|
|
3023
|
+
* real one. The component facet renders in the Chromium the website facet
|
|
3024
|
+
* already drives, so the pragma has nothing left to buy.
|
|
3025
|
+
*/
|
|
3026
|
+
const e5NoSimulatedDom = {
|
|
3027
|
+
create(context) {
|
|
3028
|
+
if (!REACHED$1.has(roleOf(context.physicalFilename).role)) return {};
|
|
3029
|
+
return { Program(node) {
|
|
3030
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
3031
|
+
const environment = PRAGMA.exec(comment.value)?.groups?.environment;
|
|
3032
|
+
if (environment !== void 0 && SIMULATED$1.has(environment)) context.report({
|
|
3033
|
+
data: { environment },
|
|
3034
|
+
messageId: "pragma",
|
|
3035
|
+
node
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
} };
|
|
3039
|
+
},
|
|
3040
|
+
meta: {
|
|
3041
|
+
docs: RULE_DOCS["e5-no-simulated-dom"],
|
|
3042
|
+
messages: { pragma: "`@vitest-environment {{environment}}` simulates a browser this framework can open for real — a rendered thing is a `.test.tsx` beside its component, collected by the `component()` project (E5 — docs/13-linting.md#e5-no-simulated-dom)." },
|
|
3043
|
+
type: "problem"
|
|
3044
|
+
}
|
|
3045
|
+
};
|
|
3046
|
+
//#endregion
|
|
3047
|
+
//#region src/lint/rules/e5b-no-simulated-dom-config.ts
|
|
3048
|
+
/** The two simulated DOMs. */
|
|
3049
|
+
const SIMULATED = /* @__PURE__ */ new Set(["happy-dom", "jsdom"]);
|
|
3050
|
+
/**
|
|
3051
|
+
* CONVENTIONS E5b — the same ban, where a project states it for a whole tree.
|
|
3052
|
+
*
|
|
3053
|
+
* The pragma (E5) is one file's; `environment: 'happy-dom'` in a config is
|
|
3054
|
+
* every file the project collects, which is how a repository ends up with a
|
|
3055
|
+
* simulated DOM nobody ever chose per test. `'node'` and `'edge-runtime'` are
|
|
3056
|
+
* out of reach: they name a real runtime, not a drawing of one.
|
|
3057
|
+
*/
|
|
3058
|
+
const e5bNoSimulatedDomConfig = {
|
|
3059
|
+
create(context) {
|
|
3060
|
+
if (roleOf(context.physicalFilename).role !== "config") return {};
|
|
3061
|
+
return { Program(node) {
|
|
3062
|
+
walk(node, (candidate) => {
|
|
3063
|
+
if (candidate.type !== "Property" || propertyKeyName(candidate) !== "environment") return;
|
|
3064
|
+
const environment = stringValue(child(candidate, "value"));
|
|
3065
|
+
if (environment !== void 0 && SIMULATED.has(environment)) context.report({
|
|
3066
|
+
data: { environment },
|
|
3067
|
+
messageId: "configured",
|
|
3068
|
+
node: candidate
|
|
3069
|
+
});
|
|
3070
|
+
});
|
|
3071
|
+
} };
|
|
3072
|
+
},
|
|
3073
|
+
meta: {
|
|
3074
|
+
docs: RULE_DOCS["e5b-no-simulated-dom-config"],
|
|
3075
|
+
messages: { configured: "`environment: '{{environment}}'` gives every file of this project a drawing of a browser — a rendered thing is a `.test.tsx` beside its component, collected by `component()` (E5b — docs/13-linting.md#e5b-no-simulated-dom-config)." },
|
|
3076
|
+
type: "problem"
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3079
|
+
//#endregion
|
|
3080
|
+
//#region src/lint/rules/e6-component-project-helper.ts
|
|
3081
|
+
/** Is this property the RUNNER's browser block, rather than a key that shares its name? */
|
|
3082
|
+
function isRunnerBrowserBlock(node) {
|
|
3083
|
+
for (let current = child(node, "parent"); current !== void 0; current = child(current, "parent")) if (current.type === "Property" && propertyKeyName(current) === "test") return true;
|
|
3084
|
+
return false;
|
|
3085
|
+
}
|
|
3086
|
+
/** Is this node inside a call to `component(...)`? */
|
|
3087
|
+
function insideComponentCall(node) {
|
|
3088
|
+
for (let current = child(node, "parent"); current !== void 0; current = child(current, "parent")) if (current.type === "CallExpression" && identifierName(child(current, "callee")) === "component") return true;
|
|
3089
|
+
return false;
|
|
3090
|
+
}
|
|
3091
|
+
/**
|
|
3092
|
+
* CONVENTIONS E6 — a browser project comes from `component()`.
|
|
3093
|
+
*
|
|
3094
|
+
* A hand-rolled `browser: { … }` block is a project that has to rediscover
|
|
3095
|
+
* everything the seam already knows: the provider pinned to the runner's exact
|
|
3096
|
+
* version, the service worker served from the framework's own install, the JSX
|
|
3097
|
+
* transform the current Vite actually uses, the dependencies a cold cache must
|
|
3098
|
+
* pre-bundle, and the artefact directories Browser Mode otherwise leaks at the
|
|
3099
|
+
* repository root. Every one of those is a run that fails on the second
|
|
3100
|
+
* machine, so the helper owns them and a config states only what is its own.
|
|
3101
|
+
*/
|
|
3102
|
+
const e6ComponentProjectHelper = {
|
|
3103
|
+
create(context) {
|
|
3104
|
+
if (roleOf(context.physicalFilename).role !== "config") return {};
|
|
3105
|
+
return { Program(node) {
|
|
3106
|
+
walk(node, (candidate) => {
|
|
3107
|
+
if (candidate.type !== "Property" || propertyKeyName(candidate) !== "browser") return;
|
|
3108
|
+
if (!isRunnerBrowserBlock(candidate)) return;
|
|
3109
|
+
if (!insideComponentCall(candidate)) context.report({
|
|
3110
|
+
messageId: "handRolled",
|
|
3111
|
+
node: candidate
|
|
3112
|
+
});
|
|
3113
|
+
});
|
|
3114
|
+
} };
|
|
3115
|
+
},
|
|
3116
|
+
meta: {
|
|
3117
|
+
docs: RULE_DOCS["e6-component-project-helper"],
|
|
3118
|
+
messages: { handRolled: "Use `component({ vite })` — the provider, the worker and the pipeline are its, and a hand-rolled `browser:` block is the run that passes here and fails on the next machine (E6 — docs/13-linting.md#e6-component-project-helper)." },
|
|
3119
|
+
type: "problem"
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3122
|
+
//#endregion
|
|
2842
3123
|
//#region src/lint/package-exports.ts
|
|
2843
3124
|
/**
|
|
2844
3125
|
* The subpaths this package actually publishes, read from its OWN
|
|
@@ -3013,16 +3294,14 @@ const FRAMEWORK_LAYERS = /* @__PURE__ */ new Set([
|
|
|
3013
3294
|
*
|
|
3014
3295
|
* Distinct from F1 (which judges the same specifiers from any file): F3 is the
|
|
3015
3296
|
* specs-specific guard that also reaches relative framework-internal paths.
|
|
3016
|
-
*
|
|
3017
|
-
*
|
|
3297
|
+
* There is no folder exception: a probe that cannot reach its subject through
|
|
3298
|
+
* the public entry is a module test beside its module, not a spec.
|
|
3018
3299
|
*/
|
|
3019
3300
|
const f3SpecsPublicEntry = {
|
|
3020
3301
|
create(context) {
|
|
3021
|
-
|
|
3022
|
-
if (anchor === void 0) return {};
|
|
3302
|
+
if (specsAnchor(context.filename) === void 0) return {};
|
|
3023
3303
|
const published = new Set(declaredSubpaths());
|
|
3024
3304
|
const exempt = published.size === 0 ? "none" : [...published].join(", ");
|
|
3025
|
-
const underIntegrations = anchor.relative[0] === "integrations";
|
|
3026
3305
|
return { ...importSourceVisitor(({ node, source }) => {
|
|
3027
3306
|
if (source.startsWith(`${PACKAGE}/`)) {
|
|
3028
3307
|
if (published.has(source)) return;
|
|
@@ -3040,7 +3319,6 @@ const f3SpecsPublicEntry = {
|
|
|
3040
3319
|
if (marker === -1 && !source.startsWith("src/")) return;
|
|
3041
3320
|
const layer = (marker === -1 ? source.slice(4) : source.slice(marker + 5)).split("/")[0] ?? "";
|
|
3042
3321
|
if (!FRAMEWORK_LAYERS.has(layer)) return;
|
|
3043
|
-
if (underIntegrations && layer === "integrations") return;
|
|
3044
3322
|
context.report({
|
|
3045
3323
|
data: {
|
|
3046
3324
|
published: exempt,
|
|
@@ -3053,7 +3331,7 @@ const f3SpecsPublicEntry = {
|
|
|
3053
3331
|
},
|
|
3054
3332
|
meta: {
|
|
3055
3333
|
docs: RULE_DOCS["f3-specs-public-entry"],
|
|
3056
|
-
messages: { deepImport: "specs/ must not deep-import framework internals — reach the framework via its public entry (@jterrazz/test, or src/index.js in this repo), not \"{{source}}\" (F3 — see docs/13-linting.md). Exempt: the published subpaths {{published}}
|
|
3334
|
+
messages: { deepImport: "specs/ must not deep-import framework internals — reach the framework via its public entry (@jterrazz/test, or src/index.js in this repo), not \"{{source}}\" (F3 — see docs/13-linting.md). Exempt: the published subpaths {{published}}. A probe whose subject is not on the public entry is a module test beside its module." },
|
|
3057
3335
|
type: "problem"
|
|
3058
3336
|
}
|
|
3059
3337
|
};
|
|
@@ -3110,6 +3388,164 @@ const f5FixturesOnlyFromTests = {
|
|
|
3110
3388
|
}
|
|
3111
3389
|
};
|
|
3112
3390
|
//#endregion
|
|
3391
|
+
//#region src/lint/rules/f6-no-foreign-test-runtime.ts
|
|
3392
|
+
const GROUPS = [
|
|
3393
|
+
{
|
|
3394
|
+
fix: "`component.render()` and the element vocabulary render in a real browser — the queries are the same nouns, and they run against what ships",
|
|
3395
|
+
matches: (source) => source === "@testing-library" || source.startsWith("@testing-library/")
|
|
3396
|
+
},
|
|
3397
|
+
{
|
|
3398
|
+
fix: "a drawing of a browser proves what a browser does not — a rendered thing is a `.test.tsx` beside its component, collected by `component()`",
|
|
3399
|
+
matches: (source) => source === "happy-dom" || source === "jsdom"
|
|
3400
|
+
},
|
|
3401
|
+
{
|
|
3402
|
+
fix: "Browser Mode is the seam, not the surface — `component.render()` owns the locators, the visitor and the ARIA tree",
|
|
3403
|
+
matches: (source) => source === "vitest/browser" || source.startsWith("vitest-browser-") || source.startsWith("@vitest/browser")
|
|
3404
|
+
}
|
|
3405
|
+
];
|
|
3406
|
+
/**
|
|
3407
|
+
* The roles that RUN a test — never a fixture app's config or a provider module
|
|
3408
|
+
* that happens to sit under `specs/`. A fixture project's own `vitest.config.ts`
|
|
3409
|
+
* has to name the provider, and a `providers.tsx` has to import the adapter it
|
|
3410
|
+
* wraps: neither is a spec speaking a second dialect.
|
|
3411
|
+
*/
|
|
3412
|
+
const REACHED = /* @__PURE__ */ new Set([
|
|
3413
|
+
"component",
|
|
3414
|
+
"module",
|
|
3415
|
+
"specification"
|
|
3416
|
+
]);
|
|
3417
|
+
/**
|
|
3418
|
+
* CONVENTIONS F6 — a test file imports no second test runtime.
|
|
3419
|
+
*
|
|
3420
|
+
* Every seam the framework owns is one a spec must not reach around: a test
|
|
3421
|
+
* that imports the adapter speaks the adapter's dialect, and a repository ends
|
|
3422
|
+
* up with as many vocabularies as it has seams. The groups the rule carries are
|
|
3423
|
+
* the ones the component facet REPLACES.
|
|
3424
|
+
*/
|
|
3425
|
+
const f6NoForeignTestRuntime = {
|
|
3426
|
+
create(context) {
|
|
3427
|
+
if (!REACHED.has(roleOf(context.physicalFilename).role)) return {};
|
|
3428
|
+
return { ...importSourceVisitor(({ node, source }) => {
|
|
3429
|
+
const group = GROUPS.find((candidate) => candidate.matches(source));
|
|
3430
|
+
if (group !== void 0) context.report({
|
|
3431
|
+
data: {
|
|
3432
|
+
fix: group.fix,
|
|
3433
|
+
source
|
|
3434
|
+
},
|
|
3435
|
+
messageId: "foreignRuntime",
|
|
3436
|
+
node
|
|
3437
|
+
});
|
|
3438
|
+
}) };
|
|
3439
|
+
},
|
|
3440
|
+
meta: {
|
|
3441
|
+
docs: RULE_DOCS["f6-no-foreign-test-runtime"],
|
|
3442
|
+
messages: { foreignRuntime: "`{{source}}` is a second test runtime in a test file: {{fix}} (F6 — docs/13-linting.md#f6-no-foreign-test-runtime)." },
|
|
3443
|
+
type: "problem"
|
|
3444
|
+
}
|
|
3445
|
+
};
|
|
3446
|
+
//#endregion
|
|
3447
|
+
//#region src/lint/rules/g4-no-dom-in-module-test.ts
|
|
3448
|
+
/** The globals that only exist where a document does. */
|
|
3449
|
+
const DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
3450
|
+
"document",
|
|
3451
|
+
"HTMLElement",
|
|
3452
|
+
"navigator",
|
|
3453
|
+
"window"
|
|
3454
|
+
]);
|
|
3455
|
+
/** The node kinds that BIND a name, and the key each one binds it under. */
|
|
3456
|
+
const BINDINGS = {
|
|
3457
|
+
CatchClause: "param",
|
|
3458
|
+
ClassDeclaration: "id",
|
|
3459
|
+
FunctionDeclaration: "id",
|
|
3460
|
+
ImportDefaultSpecifier: "local",
|
|
3461
|
+
ImportNamespaceSpecifier: "local",
|
|
3462
|
+
ImportSpecifier: "local",
|
|
3463
|
+
VariableDeclarator: "id"
|
|
3464
|
+
};
|
|
3465
|
+
/**
|
|
3466
|
+
* Every name this file declares for itself.
|
|
3467
|
+
*
|
|
3468
|
+
* A file-wide set rather than a scope chain: the rule only needs to know that
|
|
3469
|
+
* `document` is the test's own binding somewhere, and a name shadowed in one
|
|
3470
|
+
* scope is not a global in another. It can only under-report, which is the
|
|
3471
|
+
* right direction for a guard.
|
|
3472
|
+
*/
|
|
3473
|
+
function declaredNames(root) {
|
|
3474
|
+
const names = /* @__PURE__ */ new Set();
|
|
3475
|
+
const add = (node) => {
|
|
3476
|
+
const name = identifierName(node);
|
|
3477
|
+
if (name !== void 0) names.add(name);
|
|
3478
|
+
};
|
|
3479
|
+
walk(root, (node) => {
|
|
3480
|
+
const key = BINDINGS[node.type];
|
|
3481
|
+
if (key !== void 0) add(child(node, key));
|
|
3482
|
+
const { params } = node;
|
|
3483
|
+
if (Array.isArray(params)) {
|
|
3484
|
+
for (const parameter of params) if (isNode(parameter)) add(parameter);
|
|
3485
|
+
}
|
|
3486
|
+
});
|
|
3487
|
+
return names;
|
|
3488
|
+
}
|
|
3489
|
+
/** The node kinds a name sits in when it is a TYPE, not a value the test reaches. */
|
|
3490
|
+
const TYPE_POSITIONS = /* @__PURE__ */ new Set([
|
|
3491
|
+
"TSInterfaceHeritage",
|
|
3492
|
+
"TSQualifiedName",
|
|
3493
|
+
"TSTypeQuery",
|
|
3494
|
+
"TSTypeReference"
|
|
3495
|
+
]);
|
|
3496
|
+
/** Is this identifier read as a value, rather than named as a property, a key or a type? */
|
|
3497
|
+
function isValueReference(node) {
|
|
3498
|
+
const parent = child(node, "parent");
|
|
3499
|
+
if (parent === void 0) return true;
|
|
3500
|
+
if (TYPE_POSITIONS.has(parent.type)) return false;
|
|
3501
|
+
if (parent.type === "UnaryExpression" && parent.operator === "typeof") return false;
|
|
3502
|
+
if (parent.type === "MemberExpression") return child(parent, "property") !== node || parent.computed === true;
|
|
3503
|
+
if (parent.type === "Property") return child(parent, "value") === node || parent.computed === true;
|
|
3504
|
+
return true;
|
|
3505
|
+
}
|
|
3506
|
+
/**
|
|
3507
|
+
* CONVENTIONS G4 — a module test touches no DOM.
|
|
3508
|
+
*
|
|
3509
|
+
* A module test runs under node, where `document` does not exist: a test that
|
|
3510
|
+
* reaches for one is not testing a module, it is rendering something, and the
|
|
3511
|
+
* place for that is a `.test.tsx` beside the component.
|
|
3512
|
+
*
|
|
3513
|
+
* Reach is the `module` role OUTSIDE `specs/`: a `.test.tsx` is the rendered
|
|
3514
|
+
* kind and lives in a page, where those globals are what it is there to use;
|
|
3515
|
+
* and under `specs/` an api or cli spec is a `.test.ts` too until the `spec`
|
|
3516
|
+
* role exists, so the guard stops at the tree it can judge.
|
|
3517
|
+
*
|
|
3518
|
+
* A name in a TYPE position (`x as HTMLElement`) and a `typeof window` guard
|
|
3519
|
+
* name no document: neither reaches one, and a module that must run in both
|
|
3520
|
+
* runtimes is tested by exactly that guard.
|
|
3521
|
+
*/
|
|
3522
|
+
const g4NoDomInModuleTest = {
|
|
3523
|
+
create(context) {
|
|
3524
|
+
const identity = roleOf(context.physicalFilename);
|
|
3525
|
+
if (identity.role !== "module" || identity.inSpecs) return {};
|
|
3526
|
+
let declared = /* @__PURE__ */ new Set();
|
|
3527
|
+
return {
|
|
3528
|
+
Identifier(node) {
|
|
3529
|
+
const name = identifierName(node);
|
|
3530
|
+
if (name === void 0 || !DOM_GLOBALS.has(name) || declared.has(name) || !isValueReference(node)) return;
|
|
3531
|
+
context.report({
|
|
3532
|
+
data: { name },
|
|
3533
|
+
messageId: "domGlobal",
|
|
3534
|
+
node
|
|
3535
|
+
});
|
|
3536
|
+
},
|
|
3537
|
+
Program(node) {
|
|
3538
|
+
declared = declaredNames(node);
|
|
3539
|
+
}
|
|
3540
|
+
};
|
|
3541
|
+
},
|
|
3542
|
+
meta: {
|
|
3543
|
+
docs: RULE_DOCS["g4-no-dom-in-module-test"],
|
|
3544
|
+
messages: { domGlobal: "`{{name}}` does not exist where a module test runs — a rendered thing is a `.test.tsx` beside its component, collected by the `component()` project (G4 — docs/13-linting.md#g4-no-dom-in-module-test)." },
|
|
3545
|
+
type: "problem"
|
|
3546
|
+
}
|
|
3547
|
+
};
|
|
3548
|
+
//#endregion
|
|
3113
3549
|
//#region src/lint/rules/i1-layer-boundaries.ts
|
|
3114
3550
|
const TEST_OR_FIXTURES = /\.(?:test|fixtures)\.[cm]?[jt]sx?$/u;
|
|
3115
3551
|
function matchesPackage(source, packages) {
|
|
@@ -3242,21 +3678,25 @@ const i1LayerBoundaries = {
|
|
|
3242
3678
|
//#region src/lint/rules/i2-sibling-test-naming.ts
|
|
3243
3679
|
const TEST_FILE$1 = /\.test\.[cm]?[jt]sx?$/u;
|
|
3244
3680
|
/**
|
|
3245
|
-
* CONVENTIONS I2 —
|
|
3246
|
-
* `<file>.test.ts` next to it (Go's `foo_test.go` parity).
|
|
3247
|
-
*
|
|
3681
|
+
* CONVENTIONS I2 — a unit's test is its NEIGHBOUR: the test of `<file>.ts` is
|
|
3682
|
+
* `<file>.test.ts` next to it (Go's `foo_test.go` parity). A rendered unit
|
|
3683
|
+
* answers to the same law wherever it lives: a `.test.tsx` sits beside the
|
|
3684
|
+
* `.tsx` it renders, or the `.ts` of the hook or DOM function it hosts. Flags,
|
|
3685
|
+
* on visited files:
|
|
3248
3686
|
*
|
|
3249
3687
|
* - a `src/**` test whose neighbour module `<file>.ts` does not exist;
|
|
3688
|
+
* - a `component`-role test (`*.test.tsx`) with no neighbour of any tree;
|
|
3250
3689
|
* - any file living in a `__tests__/` directory under `src/`;
|
|
3251
3690
|
* - any file under a root-level `tests/` directory (the only test roots are
|
|
3252
|
-
* sibling
|
|
3691
|
+
* sibling tests under `src/` and product specifications in `specs/`).
|
|
3253
3692
|
*/
|
|
3254
3693
|
const i2SiblingTestNaming = {
|
|
3255
3694
|
create(context) {
|
|
3256
3695
|
const file = context.physicalFilename;
|
|
3257
3696
|
const parts = segments(file);
|
|
3258
3697
|
return { Program(node) {
|
|
3259
|
-
|
|
3698
|
+
const rendered = roleOf(file).role === "component";
|
|
3699
|
+
if (parts.includes("src") || rendered) {
|
|
3260
3700
|
if (parts.includes("__tests__")) context.report({
|
|
3261
3701
|
messageId: "testsDir",
|
|
3262
3702
|
node
|
|
@@ -3268,8 +3708,8 @@ const i2SiblingTestNaming = {
|
|
|
3268
3708
|
".js"
|
|
3269
3709
|
].map((extension) => file.replace(TEST_FILE$1, extension));
|
|
3270
3710
|
if (!neighbours.some(isFile)) context.report({
|
|
3271
|
-
data: { expected: neighbours[0]?.split(/[/\\]/u).at(-1) ?? "" },
|
|
3272
|
-
messageId: "orphanTest",
|
|
3711
|
+
data: { expected: neighbours[rendered ? 1 : 0]?.split(/[/\\]/u).at(-1) ?? "" },
|
|
3712
|
+
messageId: rendered ? "orphanComponent" : "orphanTest",
|
|
3273
3713
|
node
|
|
3274
3714
|
});
|
|
3275
3715
|
}
|
|
@@ -3286,6 +3726,7 @@ const i2SiblingTestNaming = {
|
|
|
3286
3726
|
meta: {
|
|
3287
3727
|
docs: RULE_DOCS["i2-sibling-test-naming"],
|
|
3288
3728
|
messages: {
|
|
3729
|
+
orphanComponent: "A component test must sit NEXT to what it renders — no neighbour \"{{expected}}\" found (I2 — see docs/13-linting.md). A hook or a DOM function is the `.ts` of the same basename, with its Host in the test file.",
|
|
3289
3730
|
orphanTest: "A src/ module test must sit NEXT to the module it tests — no neighbour \"{{expected}}\" found (I2 — see docs/13-linting.md). A test needing more than its module is a specification: move it to specs/.",
|
|
3290
3731
|
rootTests: "A root-level tests/ directory is banned — module tests are siblings under src/, product specifications live in specs/ (I2 — see docs/13-linting.md).",
|
|
3291
3732
|
testsDir: "__tests__/ directories are banned under src/ — the test of <file>.ts is its neighbour <file>.test.ts (I2 — see docs/13-linting.md)."
|
|
@@ -3528,11 +3969,16 @@ const plugin = {
|
|
|
3528
3969
|
"d12w-response-body-probe": d12wResponseBodyProbe,
|
|
3529
3970
|
"d13w-unfrozen-negative-fixture": d13wUnfrozenNegativeFixture,
|
|
3530
3971
|
"d15w-status-only-probe": d15wStatusOnlyProbe,
|
|
3972
|
+
"e5-no-simulated-dom": e5NoSimulatedDom,
|
|
3973
|
+
"e5b-no-simulated-dom-config": e5bNoSimulatedDomConfig,
|
|
3974
|
+
"e6-component-project-helper": e6ComponentProjectHelper,
|
|
3531
3975
|
"f1-no-subpath-import": f1NoSubpathImport,
|
|
3532
3976
|
"f2-no-test-imports-in-prod": f2NoTestImportsInProd,
|
|
3533
3977
|
"f3-specs-public-entry": f3SpecsPublicEntry,
|
|
3534
3978
|
"f4-no-test-to-test-import": f4NoTestToTestImport,
|
|
3535
3979
|
"f5-fixtures-only-from-tests": f5FixturesOnlyFromTests,
|
|
3980
|
+
"f6-no-foreign-test-runtime": f6NoForeignTestRuntime,
|
|
3981
|
+
"g4-no-dom-in-module-test": g4NoDomInModuleTest,
|
|
3536
3982
|
"i1-layer-boundaries": i1LayerBoundaries,
|
|
3537
3983
|
"i2-sibling-test-naming": i2SiblingTestNaming,
|
|
3538
3984
|
"i4-no-vi-mock-in-src": i4NoViMockInSrc,
|