@starterlib/testing 0.1.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 ADDED
@@ -0,0 +1,64 @@
1
+ # Testing
2
+
3
+ This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 22.1.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
8
+
9
+ ```bash
10
+ ng generate component component-name
11
+ ```
12
+
13
+ For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
14
+
15
+ ```bash
16
+ ng generate --help
17
+ ```
18
+
19
+ ## Building
20
+
21
+ To build the library, run:
22
+
23
+ ```bash
24
+ ng build testing
25
+ ```
26
+
27
+ This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
+
29
+ ### Publishing the Library
30
+
31
+ Once the project is built, you can publish your library by following these steps:
32
+
33
+ 1. Navigate to the `dist` directory:
34
+
35
+ ```bash
36
+ cd dist/testing
37
+ ```
38
+
39
+ 2. Run the `npm publish` command to publish your library to the npm registry:
40
+ ```bash
41
+ npm publish
42
+ ```
43
+
44
+ ## Running unit tests
45
+
46
+ To execute unit tests with the [Vitest](https://vitest.dev/) test runner, use the following command:
47
+
48
+ ```bash
49
+ ng test
50
+ ```
51
+
52
+ ## Running end-to-end tests
53
+
54
+ For end-to-end (e2e) testing, run:
55
+
56
+ ```bash
57
+ ng e2e
58
+ ```
59
+
60
+ Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
61
+
62
+ ## Additional Resources
63
+
64
+ For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
@@ -0,0 +1,69 @@
1
+ import axe from 'axe-core';
2
+
3
+ /**
4
+ * Verification d'accessibilite d'un fragment rendu. Elle sert dans CHAQUE test
5
+ * de composant : une violation qui entre dans la librairie se retrouve dans
6
+ * toutes les SPA qui la consomment.
7
+ *
8
+ * ⚠️ Limite honnete : jsdom ne calcule pas la mise en page, donc la regle de
9
+ * contraste d'axe ne peut pas s'executer ici. Le contraste est couvert
10
+ * autrement, et mieux : `@starterlib/tokens` verifie chaque paire semantique
11
+ * dans les deux themes par calcul WCAG. Desactiver la regle ici n'ouvre donc
12
+ * aucun trou, mais le dire evite de croire qu'elle a tourne.
13
+ */
14
+ const REGLES_INAPPLICABLES_EN_JSDOM = {
15
+ 'color-contrast': { enabled: false },
16
+ };
17
+ function decrire(violation) {
18
+ const cibles = violation.nodes
19
+ .map((noeud) => noeud.target.join(' '))
20
+ .slice(0, 3)
21
+ .join(', ');
22
+ return (` [${violation.impact ?? 'inconnu'}] ${violation.id} : ${violation.help}\n` +
23
+ ` elements : ${cibles}\n` +
24
+ ` aide : ${violation.helpUrl}`);
25
+ }
26
+ /**
27
+ * Execute axe et leve si une violation bloquante subsiste. Le message nomme
28
+ * TOUTES les violations d'un coup, pas la premiere : corriger une regle a la
29
+ * fois sur un composant fait perdre un cycle par violation.
30
+ */
31
+ async function verifierAccessibilite(cible, options = {}) {
32
+ const exemptions = options.exemptions ?? {};
33
+ const regles = { ...REGLES_INAPPLICABLES_EN_JSDOM };
34
+ for (const identifiant of Object.keys(exemptions)) {
35
+ regles[identifiant] = { enabled: false };
36
+ }
37
+ const configuration = { rules: regles };
38
+ const resultats = await axe.run(cible, configuration);
39
+ const bloquantes = options.gravitesBloquantes;
40
+ const violations = bloquantes === undefined
41
+ ? resultats.violations
42
+ : resultats.violations.filter((violation) => violation.impact !== null &&
43
+ violation.impact !== undefined &&
44
+ bloquantes.includes(violation.impact));
45
+ if (violations.length > 0) {
46
+ const detail = violations.map(decrire).join('\n');
47
+ throw new Error(`${violations.length.toString()} violation(s) d'accessibilite :\n${detail}`);
48
+ }
49
+ }
50
+ /** Les regles desactivees et leur raison, pour qu'un test puisse les afficher. */
51
+ const REGLES_DESACTIVEES_PAR_DEFAUT = {
52
+ 'color-contrast': 'jsdom ne calcule pas la mise en page. Le contraste est verifie par calcul ' +
53
+ 'WCAG dans @starterlib/tokens, sur chaque paire semantique et dans les deux themes.',
54
+ };
55
+
56
+ /**
57
+ * @starterlib/testing — surface publique.
58
+ *
59
+ * Le paquet est cree, outille et publiable ; son contenu arrive par vagues
60
+ * (voir docs/plan-librairie.md). Rien n'est exporte tant que rien n'est
61
+ * eprouve : un export vide vaut mieux qu'un composant a moitie monte.
62
+ */
63
+
64
+ /**
65
+ * Generated bundle index. Do not edit.
66
+ */
67
+
68
+ export { REGLES_DESACTIVEES_PAR_DEFAUT, verifierAccessibilite };
69
+ //# sourceMappingURL=starterlib-testing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"starterlib-testing.mjs","sources":["../../../../packages/testing/src/lib/accessibilite.ts","../../../../packages/testing/src/public-api.ts","../../../../packages/testing/src/starterlib-testing.ts"],"sourcesContent":["import axe, { type AxeResults, type ElementContext, type RunOptions, type Result } from 'axe-core';\n\n/**\n * Verification d'accessibilite d'un fragment rendu. Elle sert dans CHAQUE test\n * de composant : une violation qui entre dans la librairie se retrouve dans\n * toutes les SPA qui la consomment.\n *\n * ⚠️ Limite honnete : jsdom ne calcule pas la mise en page, donc la regle de\n * contraste d'axe ne peut pas s'executer ici. Le contraste est couvert\n * autrement, et mieux : `@starterlib/tokens` verifie chaque paire semantique\n * dans les deux themes par calcul WCAG. Desactiver la regle ici n'ouvre donc\n * aucun trou, mais le dire evite de croire qu'elle a tourne.\n */\nconst REGLES_INAPPLICABLES_EN_JSDOM: Readonly<Record<string, { enabled: false }>> = {\n 'color-contrast': { enabled: false },\n};\n\nexport interface OptionsAccessibilite {\n /** Regles a desactiver en plus, chacune avec sa raison ecrite. */\n readonly exemptions?: Readonly<Record<string, string>>;\n /** Niveaux a faire echouer. Par defaut toute violation echoue. */\n readonly gravitesBloquantes?: readonly ('minor' | 'moderate' | 'serious' | 'critical')[];\n}\n\nfunction decrire(violation: Result): string {\n const cibles = violation.nodes\n .map((noeud) => noeud.target.join(' '))\n .slice(0, 3)\n .join(', ');\n return (\n ` [${violation.impact ?? 'inconnu'}] ${violation.id} : ${violation.help}\\n` +\n ` elements : ${cibles}\\n` +\n ` aide : ${violation.helpUrl}`\n );\n}\n\n/**\n * Execute axe et leve si une violation bloquante subsiste. Le message nomme\n * TOUTES les violations d'un coup, pas la premiere : corriger une regle a la\n * fois sur un composant fait perdre un cycle par violation.\n */\nexport async function verifierAccessibilite(\n cible: ElementContext,\n options: OptionsAccessibilite = {},\n): Promise<void> {\n const exemptions = options.exemptions ?? {};\n const regles: Record<string, { enabled: false }> = { ...REGLES_INAPPLICABLES_EN_JSDOM };\n for (const identifiant of Object.keys(exemptions)) {\n regles[identifiant] = { enabled: false };\n }\n\n const configuration: RunOptions = { rules: regles };\n const resultats: AxeResults = await axe.run(cible, configuration);\n\n const bloquantes = options.gravitesBloquantes;\n const violations =\n bloquantes === undefined\n ? resultats.violations\n : resultats.violations.filter(\n (violation) =>\n violation.impact !== null &&\n violation.impact !== undefined &&\n (bloquantes as readonly string[]).includes(violation.impact),\n );\n\n if (violations.length > 0) {\n const detail = violations.map(decrire).join('\\n');\n throw new Error(`${violations.length.toString()} violation(s) d'accessibilite :\\n${detail}`);\n }\n}\n\n/** Les regles desactivees et leur raison, pour qu'un test puisse les afficher. */\nexport const REGLES_DESACTIVEES_PAR_DEFAUT: Readonly<Record<string, string>> = {\n 'color-contrast':\n 'jsdom ne calcule pas la mise en page. Le contraste est verifie par calcul ' +\n 'WCAG dans @starterlib/tokens, sur chaque paire semantique et dans les deux themes.',\n};\n","/**\n * @starterlib/testing — surface publique.\n *\n * Le paquet est cree, outille et publiable ; son contenu arrive par vagues\n * (voir docs/plan-librairie.md). Rien n'est exporte tant que rien n'est\n * eprouve : un export vide vaut mieux qu'un composant a moitie monte.\n */\nexport * from './lib/accessibilite';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;AAUG;AACH,MAAM,6BAA6B,GAAiD;AAClF,IA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S,CAAC,MAAM,KAAK,IAAI;YACzB,SAAS,CAAC,MAAM,KAAK,SAAS;YAC7B,UAAgC,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAC/D;AAEP,IAAA,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;AACzB,QAAA,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AACjD,QAAA,MAAM,IAAI,KAAK,CAAC,CAAA,EAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA,iCAAA,EAAoC,MAAM,CAAA,CAAE,CAAC;IAC9F;AACF;AAEA;AACO,MAAM,6BAA6B,GAAqC;AAC7E,IAAA,gBAAgB,EACd,4EAA4E;QAC5E,oFAAoF;;;AC3ExF;;;;;;AAMG;;ACNH;;AAEG;;"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@starterlib/testing",
3
+ "version": "0.1.0",
4
+ "description": "Outils de test du socle frontal starter : harnais, fixtures, simulateurs. Jamais en dependance de production.",
5
+ "license": "UNLICENSED",
6
+ "sideEffects": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Arnoldkom/starter-web-platform.git",
13
+ "directory": "packages/testing"
14
+ },
15
+ "homepage": "https://github.com/Arnoldkom/starter-web-platform/tree/main/packages/testing#readme",
16
+ "keywords": [
17
+ "starter",
18
+ "socle-frontal",
19
+ "testing"
20
+ ],
21
+ "peerDependencies": {
22
+ "@angular/core": "^22.1.0",
23
+ "@angular/common": "^22.1.0"
24
+ },
25
+ "module": "fesm2022/starterlib-testing.mjs",
26
+ "typings": "types/starterlib-testing.d.ts",
27
+ "exports": {
28
+ "./package.json": {
29
+ "default": "./package.json"
30
+ },
31
+ ".": {
32
+ "types": "./types/starterlib-testing.d.ts",
33
+ "default": "./fesm2022/starterlib-testing.mjs"
34
+ }
35
+ },
36
+ "type": "module",
37
+ "dependencies": {
38
+ "tslib": "^2.3.0"
39
+ }
40
+ }
@@ -0,0 +1,19 @@
1
+ import { ElementContext } from 'axe-core';
2
+
3
+ interface OptionsAccessibilite {
4
+ /** Regles a desactiver en plus, chacune avec sa raison ecrite. */
5
+ readonly exemptions?: Readonly<Record<string, string>>;
6
+ /** Niveaux a faire echouer. Par defaut toute violation echoue. */
7
+ readonly gravitesBloquantes?: readonly ('minor' | 'moderate' | 'serious' | 'critical')[];
8
+ }
9
+ /**
10
+ * Execute axe et leve si une violation bloquante subsiste. Le message nomme
11
+ * TOUTES les violations d'un coup, pas la premiere : corriger une regle a la
12
+ * fois sur un composant fait perdre un cycle par violation.
13
+ */
14
+ declare function verifierAccessibilite(cible: ElementContext, options?: OptionsAccessibilite): Promise<void>;
15
+ /** Les regles desactivees et leur raison, pour qu'un test puisse les afficher. */
16
+ declare const REGLES_DESACTIVEES_PAR_DEFAUT: Readonly<Record<string, string>>;
17
+
18
+ export { REGLES_DESACTIVEES_PAR_DEFAUT, verifierAccessibilite };
19
+ export type { OptionsAccessibilite };