@axelvilleret/e2e-spec-kit 0.0.0-stage → 0.20.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 +167 -2
- package/e2e-specs/README.md +148 -0
- package/e2e-specs/bin/e2e-specs.mjs +4 -0
- package/e2e-specs/docs/commands/README.md +61 -0
- package/e2e-specs/docs/commands/check.md +79 -0
- package/e2e-specs/docs/commands/doctor.md +38 -0
- package/e2e-specs/docs/commands/init.md +60 -0
- package/e2e-specs/docs/commands/propose-fix.md +77 -0
- package/e2e-specs/docs/commands/pull.md +135 -0
- package/e2e-specs/docs/commands/report.md +88 -0
- package/e2e-specs/docs/commands/scripts.md +14 -0
- package/e2e-specs/docs/sources.md +119 -0
- package/e2e-specs/docs/steps.md +87 -0
- package/e2e-specs/lib/control/check.mjs +64 -0
- package/e2e-specs/lib/control/cli.mjs +192 -0
- package/e2e-specs/lib/conventions/conventions.mjs +47 -0
- package/e2e-specs/lib/environments/doctor.mjs +86 -0
- package/e2e-specs/lib/fixes/fix-request.mjs +107 -0
- package/e2e-specs/lib/index.d.mts +220 -0
- package/e2e-specs/lib/index.mjs +13 -0
- package/e2e-specs/lib/journeys/rules.mjs +38 -0
- package/e2e-specs/lib/journeys/skeleton.mjs +26 -0
- package/e2e-specs/lib/mirrors/header.mjs +60 -0
- package/e2e-specs/lib/mirrors/mirror.mjs +146 -0
- package/e2e-specs/lib/mirrors/specs.mjs +51 -0
- package/e2e-specs/lib/mirrors/statuses.mjs +41 -0
- package/e2e-specs/lib/mirrors/steps.mjs +55 -0
- package/e2e-specs/lib/playwright.d.mts +4 -0
- package/e2e-specs/lib/playwright.mjs +60 -0
- package/e2e-specs/lib/reports/report-model.mjs +65 -0
- package/e2e-specs/lib/reports/report.mjs +76 -0
- package/e2e-specs/lib/reports/results.mjs +77 -0
- package/e2e-specs/lib/setup/init.mjs +65 -0
- package/e2e-specs/lib/setup/prerequisites.mjs +21 -0
- package/e2e-specs/lib/setup/source-config.mjs +26 -0
- package/e2e-specs/lib/setup/tests-dir.mjs +1 -0
- package/e2e-specs/lib/setup/tests-folder.mjs +50 -0
- package/e2e-specs/lib/sources/confluence/adf-build.mjs +24 -0
- package/e2e-specs/lib/sources/confluence/adf-read.mjs +100 -0
- package/e2e-specs/lib/sources/confluence/cases.mjs +167 -0
- package/e2e-specs/lib/sources/confluence/client.mjs +118 -0
- package/e2e-specs/lib/sources/confluence/index.mjs +36 -0
- package/e2e-specs/lib/sources/confluence/reports.mjs +106 -0
- package/e2e-specs/lib/sources/confluence/workspace.mjs +47 -0
- package/e2e-specs/lib/sources/markdown/cases.mjs +137 -0
- package/e2e-specs/lib/sources/markdown/index.mjs +25 -0
- package/e2e-specs/lib/sources/markdown/markdown.mjs +76 -0
- package/e2e-specs/lib/sources/markdown/reports.mjs +97 -0
- package/e2e-specs/lib/sources/markdown/workspace.mjs +46 -0
- package/e2e-specs/lib/sources/registry.mjs +34 -0
- package/e2e-specs/lib/text.mjs +17 -0
- package/e2e-specs/lib/upstream/pages/conventions.md +46 -0
- package/e2e-specs/lib/upstream/pages/template.md +33 -0
- package/e2e-specs/lib/upstream/pull.mjs +199 -0
- package/e2e-specs/lib/upstream/test-case.mjs +201 -0
- package/e2e-specs/lib/upstream/workspace.mjs +25 -0
- package/e2e-specs/template/.env.example +2 -0
- package/e2e-specs/template/env +2 -0
- package/e2e-specs/template/gitignore +6 -0
- package/e2e-specs/template/journeys/.gitkeep +0 -0
- package/e2e-specs/template/package.json +14 -0
- package/e2e-specs/template/playwright.config.ts +35 -0
- package/e2e-specs/template/scripts/report.sh +23 -0
- package/e2e-specs/template/scripts/run.sh +33 -0
- package/e2e-specs/template/specs/.gitkeep +0 -0
- package/e2e-specs/template/support/.gitkeep +0 -0
- package/package.json +71 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const KIT_TEST = '@axelvilleret/e2e-spec-kit/playwright';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Les regles qu'un parcours doit tenir, chacune avec son motif. Une regle qui ne tient pas fait
|
|
8
|
+
* jouer ou taire un cas sans que la garde d'execution ne le voie.
|
|
9
|
+
*/
|
|
10
|
+
const RULES = [
|
|
11
|
+
{
|
|
12
|
+
// `test` de Playwright : la garde d'execution ne s'applique pas, un brouillon se joue.
|
|
13
|
+
pattern: /^\s*import\s+(?:test\b|\{[^}]*\btest\b[^}]*\})[^;]*from\s+['"]@playwright\/test['"]/m,
|
|
14
|
+
rule: `\`test\` importé de @playwright/test : l'importer de ${KIT_TEST}`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
// Un cas tu a la main echappe au statut amont, seul juge de ce qui se joue.
|
|
18
|
+
pattern: /\btest(?:\.describe)?(?:\.step)?\.(?:skip|fixme|only)\b/,
|
|
19
|
+
rule: 'test.skip, test.fixme ou test.only : le statut du cas amont décide seul de ce qui se joue',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** Les manquements aux regles, par fichier de parcours et par ligne. */
|
|
24
|
+
export function journeyViolations(conventions) {
|
|
25
|
+
const violations = [];
|
|
26
|
+
const files = readdirSync(conventions.journeysDir).filter((name) => name.endsWith(conventions.journeyExtension)).sort();
|
|
27
|
+
for (const name of files) {
|
|
28
|
+
const source = readFileSync(path.join(conventions.journeysDir, name), 'utf8');
|
|
29
|
+
for (const { pattern, rule } of RULES) {
|
|
30
|
+
const flags = pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`;
|
|
31
|
+
for (const match of source.matchAll(new RegExp(pattern.source, flags))) {
|
|
32
|
+
const line = source.slice(0, match.index + match[0].search(/\S/)).split('\n').length;
|
|
33
|
+
violations.push({ file: path.join(path.basename(conventions.journeysDir), name), line, rule });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return violations;
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const KIT_TEST = '@axelvilleret/e2e-spec-kit/playwright';
|
|
2
|
+
|
|
3
|
+
/** @param {string} text */
|
|
4
|
+
const quoted = (text) => `'${text.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
5
|
+
/** @param {string} text */
|
|
6
|
+
const oneLine = (text) => text.replace(/\s+/g, ' ').trim();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Le parcours d'un cas nouveau, a completer : importation, titre, et une ligne de commentaire par
|
|
10
|
+
* etape active. Les etapes restent en commentaire, donc non couvertes, tant qu'aucun `test.step`
|
|
11
|
+
* ne les joue.
|
|
12
|
+
*/
|
|
13
|
+
/** @param {Pick<import('../index.d.mts').TestCase, 'id' | 'title' | 'steps'>} testCase */
|
|
14
|
+
export function renderJourneySkeleton(testCase) {
|
|
15
|
+
const steps = testCase.steps
|
|
16
|
+
.filter((step) => !step.obsolete)
|
|
17
|
+
.map((step) => ` // ${step.id} - ${oneLine(step.action)} => ${oneLine(step.expected)}`);
|
|
18
|
+
return [
|
|
19
|
+
`import { test, expect } from '${KIT_TEST}';`,
|
|
20
|
+
'',
|
|
21
|
+
`test(${quoted(`${testCase.id} - ${testCase.title}`)}, async ({ page }) => {`,
|
|
22
|
+
...steps,
|
|
23
|
+
'});',
|
|
24
|
+
'',
|
|
25
|
+
].join('\n');
|
|
26
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
/** En-tete YAML entre deux lignes "---". */
|
|
4
|
+
const HEADER = /^---\n([\s\S]*?)\n---\n/;
|
|
5
|
+
|
|
6
|
+
/** Valeurs scalaires seulement. */
|
|
7
|
+
const SCALAR = /^([a-zA-Z]+):\s*(.*)$/;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} content
|
|
11
|
+
* @param {string} subject
|
|
12
|
+
*/
|
|
13
|
+
function matchHeader(content, subject) {
|
|
14
|
+
const match = content.match(HEADER);
|
|
15
|
+
if (!match) {
|
|
16
|
+
throw new Error(`${subject} : en-tête introuvable`);
|
|
17
|
+
}
|
|
18
|
+
return match;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} content
|
|
23
|
+
* @param {string} [subject]
|
|
24
|
+
* @returns {Record<string, string>}
|
|
25
|
+
*/
|
|
26
|
+
export function headerOf(content, subject = 'ce fichier') {
|
|
27
|
+
/** @type {Record<string, string>} */
|
|
28
|
+
const fields = {};
|
|
29
|
+
for (const line of matchHeader(content, subject)[1].split('\n')) {
|
|
30
|
+
const pair = line.match(SCALAR);
|
|
31
|
+
if (pair) {
|
|
32
|
+
fields[pair[1]] = pair[2].trim().replace(/^(["'])(.*)\1$/, '$2');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return fields;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Le miroir sans son en-tete : c'est lui que l'empreinte couvre. */
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} content
|
|
41
|
+
* @param {string} [subject]
|
|
42
|
+
*/
|
|
43
|
+
export function bodyOf(content, subject = 'ce fichier') {
|
|
44
|
+
return content.slice(matchHeader(content, subject)[0].length);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {string} body */
|
|
48
|
+
/**
|
|
49
|
+
* Une valeur d'en-tête telle qu'elle se relit : entourée de guillemets seulement si elle
|
|
50
|
+
* commence et finit par le même guillemet, qui serait sinon pris pour une délimitation.
|
|
51
|
+
* @param {string} value
|
|
52
|
+
*/
|
|
53
|
+
export function headerValue(value) {
|
|
54
|
+
return /^(["']).*\1$/.test(value) ? `"${value}"` : value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param {string} body */
|
|
58
|
+
export function fingerprint(body) {
|
|
59
|
+
return createHash('sha256').update(body, 'utf8').digest('hex').slice(0, 16);
|
|
60
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { bodyOf, fingerprint, headerOf, headerValue } from './header.mjs';
|
|
2
|
+
|
|
3
|
+
/** @typedef {Pick<import('../index.d.mts').ResolvedConventions, 'partialCoverageHeading' | 'stepTableLinePrefix'>} Conventions */
|
|
4
|
+
/** @typedef {import('../index.d.mts').TestCase} TestCase */
|
|
5
|
+
/** @typedef {import('../index.d.mts').Step} Step */
|
|
6
|
+
|
|
7
|
+
export const OBSOLETE_MARK = ' (obsolète)';
|
|
8
|
+
const NO_PARTIAL_COVERAGE = 'Aucune à ce jour.';
|
|
9
|
+
|
|
10
|
+
/** Le contenu de la section écrite par le dépôt, sans son titre. Vide si absente. */
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} body
|
|
13
|
+
* @param {Conventions} conventions
|
|
14
|
+
*/
|
|
15
|
+
export function partialCoverageOf(body, conventions) {
|
|
16
|
+
const section = body.split(`${conventions.partialCoverageHeading}\n`)[1];
|
|
17
|
+
return section ? section.split(/^## /m)[0].trim() : '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Le corps tel que l'empreinte le couvre : la section de couverture incomplète, seule partie
|
|
22
|
+
* écrite par le dépôt, y est vidée. La retoucher ne casse donc pas l'empreinte.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} body
|
|
26
|
+
* @param {Conventions} conventions
|
|
27
|
+
*/
|
|
28
|
+
function sealedPart(body, conventions) {
|
|
29
|
+
const heading = `${conventions.partialCoverageHeading}\n`;
|
|
30
|
+
const at = body.indexOf(heading);
|
|
31
|
+
if (at === -1) return body;
|
|
32
|
+
const after = body.slice(at + heading.length);
|
|
33
|
+
const next = after.search(/^## /m);
|
|
34
|
+
return body.slice(0, at + heading.length) + (next === -1 ? '' : after.slice(next));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** La retouche à la main d'un miroir, hors couverture incomplète, ou `undefined` s'il est intact. */
|
|
38
|
+
/**
|
|
39
|
+
* @param {Record<string, string>} header
|
|
40
|
+
* @param {string} body
|
|
41
|
+
* @param {Conventions} conventions
|
|
42
|
+
*/
|
|
43
|
+
function driftOf(header, body, conventions) {
|
|
44
|
+
const computed = fingerprint(sealedPart(body, conventions));
|
|
45
|
+
return header.hash === computed ? undefined : { sealed: header.hash, computed };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @param {Step} step */
|
|
49
|
+
function stepRow(step) {
|
|
50
|
+
return `| ${step.id}${step.obsolete ? OBSOLETE_MARK : ''} | ${step.action} | ${step.expected} |`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Le corps du miroir : tout vient du cas amont, sauf la couverture incomplète. */
|
|
54
|
+
/**
|
|
55
|
+
* @param {TestCase} testCase
|
|
56
|
+
* @param {string} partialCoverage
|
|
57
|
+
* @param {Conventions} conventions
|
|
58
|
+
*/
|
|
59
|
+
export function renderBody(testCase, partialCoverage, conventions) {
|
|
60
|
+
return [
|
|
61
|
+
`# ${testCase.id} — ${testCase.title}`,
|
|
62
|
+
testCase.description,
|
|
63
|
+
'## Prérequis',
|
|
64
|
+
testCase.prerequisites || 'Aucun.',
|
|
65
|
+
'## Étapes',
|
|
66
|
+
['| Étape | Action | Résultat attendu |', '| --- | --- | --- |', ...testCase.steps.map(stepRow)].join('\n'),
|
|
67
|
+
conventions.partialCoverageHeading,
|
|
68
|
+
partialCoverage || NO_PARTIAL_COVERAGE,
|
|
69
|
+
'## Post-conditions',
|
|
70
|
+
testCase.postconditions || 'Aucune.',
|
|
71
|
+
].filter((part) => part !== '').join('\n\n') + '\n';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Le miroir complet, empreinte comprise. L'ordre des champs est fixe. */
|
|
75
|
+
/**
|
|
76
|
+
* @param {TestCase} testCase
|
|
77
|
+
* @param {string} partialCoverage
|
|
78
|
+
* @param {Conventions} conventions
|
|
79
|
+
*/
|
|
80
|
+
export function renderMirror(testCase, partialCoverage, conventions) {
|
|
81
|
+
// L'empreinte couvre tout ce qui suit l'en-tête, ligne vide de tête comprise (voir bodyOf).
|
|
82
|
+
const body = `\n${renderBody(testCase, partialCoverage, conventions)}`;
|
|
83
|
+
const header = [
|
|
84
|
+
`id: ${testCase.id}`,
|
|
85
|
+
`title: ${headerValue(testCase.title)}`,
|
|
86
|
+
`sourceId: "${testCase.source.id}"`,
|
|
87
|
+
`sourceVersion: "${testCase.source.version}"`,
|
|
88
|
+
`lastUpdated: "${testCase.source.lastUpdated}"`,
|
|
89
|
+
`url: ${headerValue(testCase.source.url)}`,
|
|
90
|
+
`hash: ${fingerprint(sealedPart(body, conventions))}`,
|
|
91
|
+
`status: ${headerValue(testCase.status)}`,
|
|
92
|
+
`criticite: ${testCase.criticite}`,
|
|
93
|
+
`automatisation: ${headerValue(testCase.automatisation)}`,
|
|
94
|
+
];
|
|
95
|
+
return `---\n${header.join('\n')}\n---\n${body}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** La version amont d'un miroir ; `pageVersion` est son nom d'avant les sources. */
|
|
99
|
+
/** @param {Record<string, string>} header */
|
|
100
|
+
export const sourceVersionOf = (header) => header.sourceVersion ?? header.pageVersion;
|
|
101
|
+
|
|
102
|
+
/** @param {string} line */
|
|
103
|
+
function cells(line) {
|
|
104
|
+
return line.slice(1, -1).split(/(?<!\\)\|/).map((text) => text.trim());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Les étapes du tableau d'un miroir, pour le diff : id => { action, expected, obsolete }. */
|
|
108
|
+
/**
|
|
109
|
+
* @param {string} body
|
|
110
|
+
* @param {Conventions} conventions
|
|
111
|
+
*/
|
|
112
|
+
function stepsOfBody(body, conventions) {
|
|
113
|
+
/** @type {Map<string, Omit<Step, 'id'>>} */
|
|
114
|
+
const steps = new Map();
|
|
115
|
+
for (const line of body.split('\n')) {
|
|
116
|
+
if (!line.startsWith(conventions.stepTableLinePrefix)) continue;
|
|
117
|
+
const [idCell, action, expected] = cells(line);
|
|
118
|
+
const obsolete = idCell.endsWith(OBSOLETE_MARK);
|
|
119
|
+
steps.set(obsolete ? idCell.slice(0, -OBSOLETE_MARK.length) : idCell, { action, expected, obsolete });
|
|
120
|
+
}
|
|
121
|
+
return steps;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Un miroir lu une fois pour toutes : en-tête, corps, étapes, couverture incomplète, et la
|
|
126
|
+
* retouche à la main éventuelle (`drift`, `undefined` si le miroir est intact).
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} content
|
|
130
|
+
* @param {string} name
|
|
131
|
+
* @param {Conventions} conventions
|
|
132
|
+
* @returns {import('../index.d.mts').Mirror}
|
|
133
|
+
*/
|
|
134
|
+
export function parseMirror(content, name, conventions) {
|
|
135
|
+
const header = headerOf(content, name);
|
|
136
|
+
const body = bodyOf(content, name);
|
|
137
|
+
return {
|
|
138
|
+
name,
|
|
139
|
+
content,
|
|
140
|
+
header,
|
|
141
|
+
body,
|
|
142
|
+
steps: stepsOfBody(body, conventions),
|
|
143
|
+
partialCoverage: partialCoverageOf(body, conventions),
|
|
144
|
+
drift: driftOf(header, body, conventions),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { headerOf } from './header.mjs';
|
|
4
|
+
import { parseMirror } from './mirror.mjs';
|
|
5
|
+
import { readStatus, readStatusVocabulary, unknownStatusMessage } from './statuses.mjs';
|
|
6
|
+
|
|
7
|
+
export function specFiles(conventions) {
|
|
8
|
+
return readdirSync(conventions.specsDir).filter((name) => name.endsWith('.md')).sort();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Tous les miroirs du dossier des specs, chacun lu et analysé une fois (voir `parseMirror`). */
|
|
12
|
+
export function readMirrors(conventions) {
|
|
13
|
+
return specFiles(conventions).map((name) => {
|
|
14
|
+
const file = path.join(conventions.specsDir, name);
|
|
15
|
+
return { file, ...parseMirror(readFileSync(file, 'utf8'), name, conventions) };
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** L'en-tête du miroir qui porte cet identifiant de cas. Lit les fichiers jusqu'au bon, pas au-delà. */
|
|
20
|
+
export function specHeader(caseId, conventions) {
|
|
21
|
+
for (const name of specFiles(conventions)) {
|
|
22
|
+
const content = readFileSync(path.join(conventions.specsDir, name), 'utf8');
|
|
23
|
+
const fields = headerOf(content, name);
|
|
24
|
+
if (fields.id === caseId) {
|
|
25
|
+
return fields;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
throw new Error(`Aucun miroir de spec ne porte l'identifiant ${caseId} dans ${conventions.specsDir}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Arguments pour test.skip(...) : ignore le cas si son miroir n'est pas `valide`, sauf avec
|
|
34
|
+
* `E2E_PLAY_DRAFTS=1`. Lève sur un statut inconnu, pour ne pas l'ignorer en silence.
|
|
35
|
+
*/
|
|
36
|
+
export function skipUnlessValidated(caseId, conventions) {
|
|
37
|
+
const vocabulary = readStatusVocabulary(conventions);
|
|
38
|
+
const { declared, known, playable } = readStatus(vocabulary, specHeader(caseId, conventions).status);
|
|
39
|
+
|
|
40
|
+
if (!known) {
|
|
41
|
+
throw new Error(unknownStatusMessage(caseId, declared, vocabulary));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const forced = process.env[conventions.forceDraftsEnv] === '1';
|
|
45
|
+
|
|
46
|
+
return [
|
|
47
|
+
!playable && !forced,
|
|
48
|
+
`${caseId} est en statut "${declared}" : seuls les cas validés se jouent `
|
|
49
|
+
+ `(${conventions.forceDraftsEnv}=1 pour forcer)`,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { normalized } from '../text.mjs';
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('../index.d.mts').ResolvedConventions} Conventions */
|
|
4
|
+
/** @typedef {Record<string, boolean>} Vocabulary */
|
|
5
|
+
|
|
6
|
+
/** Le statut tel que le vocabulaire le connaît : `VALIDE`, ` Validé ` => `valide`. */
|
|
7
|
+
/** @param {string | undefined} raw */
|
|
8
|
+
export function canonicalStatus(raw) {
|
|
9
|
+
return normalized(raw);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** { valide: true, brouillon: false, ... } */
|
|
13
|
+
/**
|
|
14
|
+
* @param {Pick<Conventions, 'statuses'>} conventions
|
|
15
|
+
* @returns {Vocabulary}
|
|
16
|
+
*/
|
|
17
|
+
export function readStatusVocabulary(conventions) {
|
|
18
|
+
return conventions.statuses;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `known` : dans le vocabulaire. `playable` : se joue. */
|
|
22
|
+
/**
|
|
23
|
+
* @param {Vocabulary} vocabulary
|
|
24
|
+
* @param {string} declared
|
|
25
|
+
* @returns {import('../index.d.mts').SpecStatus}
|
|
26
|
+
*/
|
|
27
|
+
export function readStatus(vocabulary, declared) {
|
|
28
|
+
const status = canonicalStatus(declared);
|
|
29
|
+
return { declared, status, known: status in vocabulary, playable: vocabulary[status] === true };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} subject
|
|
34
|
+
* @param {string} declared
|
|
35
|
+
* @param {Vocabulary} vocabulary
|
|
36
|
+
*/
|
|
37
|
+
export function unknownStatusMessage(subject, declared, vocabulary) {
|
|
38
|
+
return `${subject} porte le statut "${declared}", hors vocabulaire (${Object.keys(vocabulary).join(', ')}). `
|
|
39
|
+
+ 'Un statut inconnu ne se traite pas comme un brouillon : le cas serait ignoré en silence, '
|
|
40
|
+
+ 'et une exécution où tout est ignoré ressort verte.';
|
|
41
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { OBSOLETE_MARK, partialCoverageOf } from './mirror.mjs';
|
|
4
|
+
|
|
5
|
+
/** Neuve a chaque appel : une regex globale partagee garde son lastIndex. */
|
|
6
|
+
function stepIds(conventions) {
|
|
7
|
+
return new RegExp(conventions.stepIdPattern, 'g');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Les etapes du tableau du miroir a couvrir, dans l'ordre : les obsoletes en sont exclues. */
|
|
11
|
+
export function declaredSteps(body, conventions) {
|
|
12
|
+
return [...new Set(
|
|
13
|
+
body
|
|
14
|
+
.split('\n')
|
|
15
|
+
.filter((line) => line.startsWith(conventions.stepTableLinePrefix))
|
|
16
|
+
.filter((line) => !line.split('|')[1].trimEnd().endsWith(OBSOLETE_MARK))
|
|
17
|
+
.flatMap((line) => line.match(stepIds(conventions)) ?? [])
|
|
18
|
+
)];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Les étapes de la section « Couverture incomplète » (son contenu, sans le titre), chacune avec
|
|
23
|
+
* ce qui n'est pas vérifié : le texte de sa ligne, puce et identifiants retirés. Une étape citée
|
|
24
|
+
* sur plusieurs lignes réunit leurs textes.
|
|
25
|
+
*/
|
|
26
|
+
export function partialNotes(partialCoverage, conventions) {
|
|
27
|
+
const notes = new Map();
|
|
28
|
+
for (const line of partialCoverage.split('\n')) {
|
|
29
|
+
const ids = line.match(stepIds(conventions)) ?? [];
|
|
30
|
+
const note = line.replace(stepIds(conventions), '').replace(/^[\s*,:–—-]+/, '').trim();
|
|
31
|
+
for (const id of ids) {
|
|
32
|
+
notes.set(id, [notes.get(id), note].filter(Boolean).join(' ; '));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return notes;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Les étapes citées dans la section « Couverture incomplète » du miroir. */
|
|
39
|
+
export function partialSteps(body, conventions) {
|
|
40
|
+
return [...partialNotes(partialCoverageOf(body, conventions), conventions).keys()];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Les etapes citees en tete d'un libelle `test.step` dans les parcours. */
|
|
44
|
+
export function coveredSteps(conventions) {
|
|
45
|
+
const labelled = new RegExp(`test\\.step\\(\\s*['"\`](${conventions.stepIdPattern})`, 'g');
|
|
46
|
+
const covered = new Set();
|
|
47
|
+
|
|
48
|
+
for (const name of readdirSync(conventions.journeysDir).filter((file) => file.endsWith(conventions.journeyExtension))) {
|
|
49
|
+
const source = readFileSync(path.join(conventions.journeysDir, name), 'utf8');
|
|
50
|
+
for (const [, id] of source.matchAll(labelled)) {
|
|
51
|
+
covered.add(id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return covered;
|
|
55
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { test as base, expect } from '@playwright/test';
|
|
2
|
+
import { resolveConventions } from './conventions/conventions.mjs';
|
|
3
|
+
import { skipUnlessValidated } from './mirrors/specs.mjs';
|
|
4
|
+
|
|
5
|
+
/** Coupe animations et defilement doux. Execute dans le navigateur : rester autonome. */
|
|
6
|
+
function freezeMotion() {
|
|
7
|
+
const inject = () => {
|
|
8
|
+
const style = document.createElement('style');
|
|
9
|
+
style.textContent = `
|
|
10
|
+
html, body, * {
|
|
11
|
+
scroll-behavior: auto !important;
|
|
12
|
+
animation-duration: 0s !important;
|
|
13
|
+
transition-duration: 0s !important;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
document.head.appendChild(style);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (document.head) {
|
|
20
|
+
inject();
|
|
21
|
+
} else {
|
|
22
|
+
document.addEventListener('DOMContentLoaded', inject);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Le premier identifiant de cas trouve dans le chemin de titres du test. */
|
|
27
|
+
function caseIdOf(titlePath, conventions) {
|
|
28
|
+
return titlePath.join(' ').match(new RegExp(conventions.caseIdPattern))?.[0] ?? null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Le `test` de Playwright, avec pages sans animation (clics et captures stables) et garde
|
|
33
|
+
* d'execution : un cas non valide est ignore avant le lancement du navigateur, un titre sans
|
|
34
|
+
* identifiant de cas fait echouer le test.
|
|
35
|
+
*/
|
|
36
|
+
export const test = base.extend({
|
|
37
|
+
page: async ({ page }, use) => {
|
|
38
|
+
await page.addInitScript(freezeMotion);
|
|
39
|
+
await use(page);
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// biome-ignore lint/correctness/noEmptyPattern: Playwright exige un premier paramètre déstructuré pour une fixture.
|
|
43
|
+
validatedCase: [async ({}, use, testInfo) => {
|
|
44
|
+
const conventions = resolveConventions();
|
|
45
|
+
const caseId = caseIdOf(testInfo.titlePath, conventions);
|
|
46
|
+
|
|
47
|
+
if (!caseId) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Aucun identifiant de cas dans "${testInfo.titlePath.join(' > ')}". `
|
|
50
|
+
+ `Le titre doit porter un identifiant au format ${conventions.caseIdPattern}, `
|
|
51
|
+
+ "sans quoi la garde d'execution ne s'applique a rien et un cas non valide se joue."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
testInfo.skip(...skipUnlessValidated(caseId, conventions));
|
|
56
|
+
await use();
|
|
57
|
+
}, { auto: true }],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export { expect };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Le rapport d'une exécution, indépendamment de la source qui le publie : ce que chaque
|
|
3
|
+
* publication rend dans son format (voir `lib/sources/`).
|
|
4
|
+
*
|
|
5
|
+
* Report : { env, title, when, baseUrl, branch, commit, run, diagnostic }
|
|
6
|
+
* run voir `readRunResults`
|
|
7
|
+
* diagnostic voir `Diagnostic`, ou undefined
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @typedef {import('../index.d.mts').Report} Report */
|
|
11
|
+
|
|
12
|
+
export const REPORTS_TITLE = "Rapports d'exécution";
|
|
13
|
+
/** @param {string} env */
|
|
14
|
+
export const environmentTitle = (env) => `Rapports - ${env}`;
|
|
15
|
+
/** @param {string} env */
|
|
16
|
+
export const environmentIntro = (env) => `Exécutions jouées sur l'environnement ${env}. Un rapport par exécution, rangé sous cette page.`;
|
|
17
|
+
export const HISTORY_COLUMNS = Object.freeze(['Date', 'Verdict', 'Cas joués', 'Classement', 'Commit', 'Rapport']);
|
|
18
|
+
|
|
19
|
+
export const CLASSEMENTS = Object.freeze({
|
|
20
|
+
A: 'A. Dérive du test',
|
|
21
|
+
B: 'B. Régression du site',
|
|
22
|
+
C: 'C. Environnement',
|
|
23
|
+
D: 'D. Indéterminisme',
|
|
24
|
+
indetermine: 'Indéterminé',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/** Le libellé affiché d'un verdict ou d'un résultat d'étape. */
|
|
28
|
+
/** @type {Record<string, string>} */
|
|
29
|
+
const LABELS = { passee: 'passée', echouee: 'échouée', 'non atteinte': 'non atteinte' };
|
|
30
|
+
/** @param {string} key */
|
|
31
|
+
export const labelOf = (key) => LABELS[key] ?? key;
|
|
32
|
+
|
|
33
|
+
/** @param {number | undefined} ms */
|
|
34
|
+
export const seconds = (ms) => (ms === undefined ? '—' : `${(ms / 1000).toFixed(1)} s`);
|
|
35
|
+
|
|
36
|
+
/** Les lignes « Contexte » du rapport : libellé, valeur. */
|
|
37
|
+
/**
|
|
38
|
+
* @param {Report} report
|
|
39
|
+
* @returns {[string, string][]}
|
|
40
|
+
*/
|
|
41
|
+
export function contextRows({ env, baseUrl, branch, commit, when, run }) {
|
|
42
|
+
const played = run.cases.map((c) => `${c.id} v${c.version ?? '?'}`).join(', ') || 'aucun';
|
|
43
|
+
return [
|
|
44
|
+
['Environnement', baseUrl ? `${env}, ${baseUrl}` : env],
|
|
45
|
+
['Code', `branche ${branch}, commit ${commit}`],
|
|
46
|
+
['Exécution', `${when}, durée ${seconds(run.duration)}`],
|
|
47
|
+
['Cas joués', `${played} ; ${run.skipped} ignoré(s)`],
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Le titre d'un rapport : `AAAA-MM-JJ HHhMM - <env> - <verdict>`. */
|
|
52
|
+
/** @param {{ when: string, env: string, verdict: string }} parts */
|
|
53
|
+
export const reportTitle = ({ when, env, verdict }) => `${when} - ${env} - ${verdict}`;
|
|
54
|
+
|
|
55
|
+
/** La ligne d'historique d'un rapport, hors lien : date, verdict, cas joués, classement, commit. */
|
|
56
|
+
/** @param {Report} report */
|
|
57
|
+
export function historyCells({ when, run, diagnostic, commit }) {
|
|
58
|
+
return {
|
|
59
|
+
when,
|
|
60
|
+
verdict: run.verdict,
|
|
61
|
+
cases: run.cases.map((c) => c.id).join(', ') || '—',
|
|
62
|
+
classement: diagnostic ? CLASSEMENTS[diagnostic.classement] : '—',
|
|
63
|
+
commit,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parseEnv } from 'node:util';
|
|
5
|
+
import { CLASSEMENTS, reportTitle } from './report-model.mjs';
|
|
6
|
+
import { readRunResults } from './results.mjs';
|
|
7
|
+
|
|
8
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
9
|
+
|
|
10
|
+
function git(root, ...args) {
|
|
11
|
+
try {
|
|
12
|
+
return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
13
|
+
} catch {
|
|
14
|
+
return 'inconnu';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function envValues(root, env) {
|
|
19
|
+
const values = {};
|
|
20
|
+
for (const name of ['.env', `.env.${env}`]) {
|
|
21
|
+
const file = path.join(root, name);
|
|
22
|
+
if (existsSync(file)) Object.assign(values, parseEnv(readFileSync(file, 'utf8')));
|
|
23
|
+
}
|
|
24
|
+
return values;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Refuse un diagnostic incomplet, et tout diagnostic qui recopie une valeur des fichiers d'environnement. */
|
|
28
|
+
function checkDiagnostic(diagnostic, verdict, secrets) {
|
|
29
|
+
if (!diagnostic) {
|
|
30
|
+
if (verdict === 'rouge') throw new Error('exécution rouge : --diagnostic <fichier.json> est requis');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!(diagnostic.classement in CLASSEMENTS)) {
|
|
34
|
+
throw new Error(`diagnostic.classement : ${Object.keys(CLASSEMENTS).join(', ')} attendu`);
|
|
35
|
+
}
|
|
36
|
+
if (verdict === 'rouge' && (!diagnostic.preuve || !diagnostic.piste)) {
|
|
37
|
+
throw new Error('diagnostic : preuve et piste sont requises sur une exécution rouge');
|
|
38
|
+
}
|
|
39
|
+
const text = JSON.stringify(diagnostic);
|
|
40
|
+
const leaked = Object.entries(secrets).filter(([key, value]) => !key.endsWith('_URL') && value.length >= 8 && text.includes(value));
|
|
41
|
+
if (leaked.length > 0) {
|
|
42
|
+
throw new Error(`le diagnostic contient la valeur de ${leaked.map(([key]) => key).join(', ')} : la retirer`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** « AAAA-MM-JJ HHhMM », heure locale : la date de l'exécution dans les titres et l'historique. */
|
|
47
|
+
function runTimestamp(startTime) {
|
|
48
|
+
const start = new Date(startTime);
|
|
49
|
+
const date = `${start.getFullYear()}-${pad(start.getMonth() + 1)}-${pad(start.getDate())}`;
|
|
50
|
+
return `${date} ${pad(start.getHours())}h${pad(start.getMinutes())}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Publie le rapport du dernier run par la source des cas (`source.reports`, voir `lib/sources/`).
|
|
55
|
+
* Le diagnostic est le seul contenu non calculé ; il est contrôlé avant toute publication.
|
|
56
|
+
*/
|
|
57
|
+
export async function publishReport(env, diagnostic, conventions, source) {
|
|
58
|
+
const { root } = conventions;
|
|
59
|
+
const run = readRunResults(conventions);
|
|
60
|
+
const values = envValues(root, env);
|
|
61
|
+
checkDiagnostic(diagnostic, run.verdict, values);
|
|
62
|
+
|
|
63
|
+
const when = runTimestamp(run.startTime);
|
|
64
|
+
const report = {
|
|
65
|
+
env,
|
|
66
|
+
when,
|
|
67
|
+
title: reportTitle({ when, env, verdict: run.verdict }),
|
|
68
|
+
baseUrl: values.E2E_BASE_URL,
|
|
69
|
+
branch: git(root, 'rev-parse', '--abbrev-ref', 'HEAD'),
|
|
70
|
+
commit: git(root, 'rev-parse', '--short', 'HEAD'),
|
|
71
|
+
run,
|
|
72
|
+
diagnostic,
|
|
73
|
+
};
|
|
74
|
+
const { url } = await source.reports.publish(report);
|
|
75
|
+
return { title: report.title, verdict: run.verdict, url };
|
|
76
|
+
}
|