@axelvilleret/e2e-spec-kit 0.20.0 → 0.21.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/e2e-specs/README.md +3 -3
- package/e2e-specs/bin/e2e-specs.mjs +1 -1
- package/e2e-specs/dist/control/check.d.ts +20 -0
- package/e2e-specs/dist/control/check.js +55 -0
- package/e2e-specs/dist/control/cli.d.ts +44 -0
- package/e2e-specs/dist/control/cli.js +206 -0
- package/e2e-specs/dist/conventions/conventions.d.ts +6 -0
- package/e2e-specs/dist/conventions/conventions.js +38 -0
- package/e2e-specs/dist/environments/doctor.d.ts +10 -0
- package/e2e-specs/dist/environments/doctor.js +84 -0
- package/e2e-specs/dist/fixes/fix-request.d.ts +49 -0
- package/e2e-specs/dist/fixes/fix-request.js +105 -0
- package/e2e-specs/dist/index.d.ts +14 -0
- package/e2e-specs/{lib/index.mjs → dist/index.js} +13 -13
- package/e2e-specs/dist/journeys/rules.d.ts +3 -0
- package/e2e-specs/dist/journeys/rules.js +35 -0
- package/e2e-specs/dist/journeys/skeleton.d.ts +7 -0
- package/e2e-specs/dist/journeys/skeleton.js +21 -0
- package/e2e-specs/dist/mirrors/header.d.ts +9 -0
- package/e2e-specs/dist/mirrors/header.js +36 -0
- package/e2e-specs/dist/mirrors/mirror.d.ts +15 -0
- package/e2e-specs/dist/mirrors/mirror.js +94 -0
- package/e2e-specs/dist/mirrors/specs.d.ts +15 -0
- package/e2e-specs/dist/mirrors/specs.js +43 -0
- package/e2e-specs/dist/mirrors/statuses.d.ts +10 -0
- package/e2e-specs/dist/mirrors/statuses.js +19 -0
- package/e2e-specs/dist/mirrors/steps.d.ts +13 -0
- package/e2e-specs/dist/mirrors/steps.js +47 -0
- package/e2e-specs/dist/playwright.d.ts +10 -0
- package/e2e-specs/dist/playwright.js +52 -0
- package/e2e-specs/dist/reports/report-model.d.ts +38 -0
- package/e2e-specs/{lib/reports/report-model.mjs → dist/reports/report-model.js} +19 -39
- package/e2e-specs/dist/reports/report.d.ts +10 -0
- package/e2e-specs/dist/reports/report.js +78 -0
- package/e2e-specs/dist/reports/results.d.ts +10 -0
- package/e2e-specs/dist/reports/results.js +80 -0
- package/e2e-specs/dist/setup/init.d.ts +17 -0
- package/e2e-specs/dist/setup/init.js +60 -0
- package/e2e-specs/dist/setup/prerequisites.d.ts +8 -0
- package/e2e-specs/dist/setup/prerequisites.js +17 -0
- package/e2e-specs/dist/setup/source-config.d.ts +5 -0
- package/e2e-specs/dist/setup/source-config.js +33 -0
- package/e2e-specs/dist/setup/tests-dir.d.ts +1 -0
- package/e2e-specs/dist/setup/tests-folder.d.ts +16 -0
- package/e2e-specs/dist/setup/tests-folder.js +68 -0
- package/e2e-specs/dist/sources/confluence/adf-build.d.ts +22 -0
- package/e2e-specs/{lib/sources/confluence/adf-build.mjs → dist/sources/confluence/adf-build.js} +2 -10
- package/e2e-specs/dist/sources/confluence/adf-read.d.ts +46 -0
- package/e2e-specs/dist/sources/confluence/adf-read.js +118 -0
- package/e2e-specs/dist/sources/confluence/cases.d.ts +9 -0
- package/e2e-specs/dist/sources/confluence/cases.js +162 -0
- package/e2e-specs/dist/sources/confluence/client.d.ts +57 -0
- package/e2e-specs/dist/sources/confluence/client.js +104 -0
- package/e2e-specs/dist/sources/confluence/index.d.ts +6 -0
- package/e2e-specs/dist/sources/confluence/index.js +29 -0
- package/e2e-specs/dist/sources/confluence/reports.d.ts +16 -0
- package/e2e-specs/dist/sources/confluence/reports.js +78 -0
- package/e2e-specs/dist/sources/confluence/workspace.d.ts +17 -0
- package/e2e-specs/dist/sources/confluence/workspace.js +40 -0
- package/e2e-specs/dist/sources/markdown/cases.d.ts +15 -0
- package/e2e-specs/dist/sources/markdown/cases.js +134 -0
- package/e2e-specs/dist/sources/markdown/index.d.ts +7 -0
- package/e2e-specs/dist/sources/markdown/index.js +21 -0
- package/e2e-specs/dist/sources/markdown/markdown.d.ts +21 -0
- package/e2e-specs/dist/sources/markdown/markdown.js +68 -0
- package/e2e-specs/dist/sources/markdown/reports.d.ts +14 -0
- package/e2e-specs/dist/sources/markdown/reports.js +79 -0
- package/e2e-specs/dist/sources/markdown/workspace.d.ts +11 -0
- package/e2e-specs/dist/sources/markdown/workspace.js +37 -0
- package/e2e-specs/dist/sources/registry.d.ts +17 -0
- package/e2e-specs/{lib/sources/registry.mjs → dist/sources/registry.js} +10 -14
- package/e2e-specs/dist/text.d.ts +6 -0
- package/e2e-specs/{lib/text.mjs → dist/text.js} +3 -8
- package/e2e-specs/dist/types.d.ts +226 -0
- package/e2e-specs/dist/types.js +2 -0
- package/e2e-specs/dist/upstream/pull.d.ts +47 -0
- package/e2e-specs/dist/upstream/pull.js +178 -0
- package/e2e-specs/dist/upstream/test-case.d.ts +57 -0
- package/e2e-specs/dist/upstream/test-case.js +140 -0
- package/e2e-specs/dist/upstream/workspace.d.ts +13 -0
- package/e2e-specs/{lib/upstream/workspace.mjs → dist/upstream/workspace.js} +1 -9
- package/e2e-specs/docs/commands/README.md +5 -4
- package/e2e-specs/docs/commands/init.md +1 -2
- package/e2e-specs/docs/commands/pull.md +2 -5
- package/e2e-specs/docs/sources.md +3 -6
- package/e2e-specs/template/package.json +1 -1
- package/package.json +18 -12
- package/e2e-specs/lib/control/check.mjs +0 -64
- package/e2e-specs/lib/control/cli.mjs +0 -192
- package/e2e-specs/lib/conventions/conventions.mjs +0 -47
- package/e2e-specs/lib/environments/doctor.mjs +0 -86
- package/e2e-specs/lib/fixes/fix-request.mjs +0 -107
- package/e2e-specs/lib/index.d.mts +0 -220
- package/e2e-specs/lib/journeys/rules.mjs +0 -38
- package/e2e-specs/lib/journeys/skeleton.mjs +0 -26
- package/e2e-specs/lib/mirrors/header.mjs +0 -60
- package/e2e-specs/lib/mirrors/mirror.mjs +0 -146
- package/e2e-specs/lib/mirrors/specs.mjs +0 -51
- package/e2e-specs/lib/mirrors/statuses.mjs +0 -41
- package/e2e-specs/lib/mirrors/steps.mjs +0 -55
- package/e2e-specs/lib/playwright.d.mts +0 -4
- package/e2e-specs/lib/playwright.mjs +0 -60
- package/e2e-specs/lib/reports/report.mjs +0 -76
- package/e2e-specs/lib/reports/results.mjs +0 -77
- package/e2e-specs/lib/setup/init.mjs +0 -65
- package/e2e-specs/lib/setup/prerequisites.mjs +0 -21
- package/e2e-specs/lib/setup/source-config.mjs +0 -26
- package/e2e-specs/lib/setup/tests-folder.mjs +0 -50
- package/e2e-specs/lib/sources/confluence/adf-read.mjs +0 -100
- package/e2e-specs/lib/sources/confluence/cases.mjs +0 -167
- package/e2e-specs/lib/sources/confluence/client.mjs +0 -118
- package/e2e-specs/lib/sources/confluence/index.mjs +0 -36
- package/e2e-specs/lib/sources/confluence/reports.mjs +0 -106
- package/e2e-specs/lib/sources/confluence/workspace.mjs +0 -47
- package/e2e-specs/lib/sources/markdown/cases.mjs +0 -137
- package/e2e-specs/lib/sources/markdown/index.mjs +0 -25
- package/e2e-specs/lib/sources/markdown/markdown.mjs +0 -76
- package/e2e-specs/lib/sources/markdown/reports.mjs +0 -97
- package/e2e-specs/lib/sources/markdown/workspace.mjs +0 -46
- package/e2e-specs/lib/upstream/pull.mjs +0 -199
- package/e2e-specs/lib/upstream/test-case.mjs +0 -201
- /package/e2e-specs/{lib/setup/tests-dir.mjs → dist/setup/tests-dir.js} +0 -0
- /package/e2e-specs/{lib → dist}/upstream/pages/conventions.md +0 -0
- /package/e2e-specs/{lib → dist}/upstream/pages/template.md +0 -0
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { markdownToAdf } from 'marklassian';
|
|
2
|
-
import {
|
|
3
|
-
CLASSEMENTS, contextRows, environmentIntro, environmentTitle, HISTORY_COLUMNS, historyCells, labelOf, REPORTS_TITLE, seconds,
|
|
4
|
-
} from '../../reports/report-model.mjs';
|
|
5
|
-
import { cell, codeBlock, doc, headerCell, heading, link, paragraph, row, status as pill, strong, table, text } from './adf-build.mjs';
|
|
6
|
-
|
|
7
|
-
const COLORS = { vert: 'green', rouge: 'red', vide: 'neutral', passee: 'green', echouee: 'red', 'non atteinte': 'neutral' };
|
|
8
|
-
|
|
9
|
-
/** Page d'environnement : son historique, vide. */
|
|
10
|
-
export function environmentPage(env) {
|
|
11
|
-
return markdownToAdf([
|
|
12
|
-
environmentIntro(env),
|
|
13
|
-
'# Historique',
|
|
14
|
-
`| ${HISTORY_COLUMNS.join(' | ')} |\n|${' --- |'.repeat(HISTORY_COLUMNS.length)}`,
|
|
15
|
-
].join('\n\n'));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const status = (key) => pill(labelOf(key), COLORS[key]);
|
|
19
|
-
/** Le résultat d'une étape ; une étape partielle ajoute sa pastille et ce qui n'est pas vérifié. */
|
|
20
|
-
const stepResult = (step) => (step.partial === undefined
|
|
21
|
-
? [status(step.result)]
|
|
22
|
-
: [status(step.result), text(' '), pill('partielle', 'yellow'), text(step.partial ? ` ${step.partial}` : '')]);
|
|
23
|
-
|
|
24
|
-
/** La page du rapport. Exportée pour la valider contre le schéma ADF. */
|
|
25
|
-
export function renderReport(report) {
|
|
26
|
-
const { run, diagnostic } = report;
|
|
27
|
-
const content = [
|
|
28
|
-
heading('Verdict'),
|
|
29
|
-
paragraph(status(run.verdict)),
|
|
30
|
-
heading('Contexte'),
|
|
31
|
-
table(...contextRows(report).map(([label, value]) => row(headerCell(label), cell(text(value))))),
|
|
32
|
-
heading('Étapes'),
|
|
33
|
-
table(
|
|
34
|
-
row(...['Étape', 'Action', 'Résultat', 'Durée'].map(headerCell)),
|
|
35
|
-
...run.cases.flatMap((c) => c.steps.map((step) => row(
|
|
36
|
-
cell(text(step.id)), cell(text(step.action)), cell(...stepResult(step)), cell(text(seconds(step.duration))),
|
|
37
|
-
))),
|
|
38
|
-
),
|
|
39
|
-
];
|
|
40
|
-
if (diagnostic) {
|
|
41
|
-
content.push(
|
|
42
|
-
heading('Diagnostic'),
|
|
43
|
-
paragraph(strong('Classement : '), text(CLASSEMENTS[diagnostic.classement])),
|
|
44
|
-
...(diagnostic.etape ? [paragraph(strong('Étape en cause : '), text(diagnostic.etape))] : []),
|
|
45
|
-
...(diagnostic.preuve ? [paragraph(strong('Preuve :')), codeBlock(diagnostic.preuve)] : []),
|
|
46
|
-
...(diagnostic.piste ? [paragraph(strong('Piste : '), text(diagnostic.piste))] : []),
|
|
47
|
-
paragraph(strong('Demande de fusion : '), diagnostic.demandeDeFusion ? link(diagnostic.demandeDeFusion, diagnostic.demandeDeFusion) : text('aucune')),
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return doc(content);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** La ligne d'historique qui pointe vers le rapport. */
|
|
54
|
-
export function historyRow(report, url) {
|
|
55
|
-
const cells = historyCells(report);
|
|
56
|
-
return row(
|
|
57
|
-
cell(text(cells.when)),
|
|
58
|
-
cell(status(cells.verdict)),
|
|
59
|
-
cell(text(cells.cases)),
|
|
60
|
-
cell(text(cells.classement)),
|
|
61
|
-
cell(text(cells.commit)),
|
|
62
|
-
cell(link('Détail', url)),
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Insère la ligne sous l'en-tête du premier tableau de la page. */
|
|
67
|
-
export function withHistoryRow(page, newRow) {
|
|
68
|
-
const history = page.content.find((node) => node.type === 'table');
|
|
69
|
-
if (!history) {
|
|
70
|
-
throw new Error("page d'environnement sans tableau d'historique");
|
|
71
|
-
}
|
|
72
|
-
const [header, ...rows] = history.content;
|
|
73
|
-
history.content = [header, newRow, ...rows];
|
|
74
|
-
return page;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** La page « Rapports - <env> », créée sous « Rapports d'exécution » si elle manque. */
|
|
78
|
-
async function environmentPageOf(client, container, env) {
|
|
79
|
-
const reports = await client.childTitled(container, REPORTS_TITLE);
|
|
80
|
-
if (!reports) {
|
|
81
|
-
throw new Error(`« ${REPORTS_TITLE} » absente sous le dossier des cas : lancer \`e2e-specs init\``);
|
|
82
|
-
}
|
|
83
|
-
const spaceId = await client.spaceOf(container);
|
|
84
|
-
const reportsContainer = { kind: reports.type === 'folder' ? 'folders' : 'pages', id: reports.id };
|
|
85
|
-
const existing = await client.childTitled(reportsContainer, environmentTitle(env));
|
|
86
|
-
const page = existing ?? await client.create({ spaceId, parentId: reports.id, title: environmentTitle(env), doc: environmentPage(env) });
|
|
87
|
-
return { id: page.id, spaceId };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* La publication des rapports : sous « Rapports - <env> » (créée si absente), une page par
|
|
92
|
-
* rapport, et sa ligne en tête de l'historique.
|
|
93
|
-
*/
|
|
94
|
-
export function confluenceReports(container, client) {
|
|
95
|
-
return {
|
|
96
|
-
async publish(report) {
|
|
97
|
-
const environment = await environmentPageOf(client(), container, report.env);
|
|
98
|
-
const page = await client().create({
|
|
99
|
-
spaceId: environment.spaceId, parentId: environment.id, title: report.title, doc: renderReport(report),
|
|
100
|
-
});
|
|
101
|
-
const history = await client().page(environment.id);
|
|
102
|
-
await client().update({ ...history, doc: withHistoryRow(history.doc, historyRow(report, page.url)) });
|
|
103
|
-
return { url: page.url };
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { markdownToAdf } from 'marklassian';
|
|
3
|
-
import { environmentTitle, REPORTS_TITLE } from '../../reports/report-model.mjs';
|
|
4
|
-
import {
|
|
5
|
-
CASES_TITLE, casesIntro, CONVENTIONS_TITLE, conventionsMarkdown, reportsIntro, TEMPLATE_TITLE, templateMarkdown,
|
|
6
|
-
} from '../../upstream/workspace.mjs';
|
|
7
|
-
import { confluenceClient, containerOf } from './client.mjs';
|
|
8
|
-
import { environmentPage } from './reports.mjs';
|
|
9
|
-
|
|
10
|
-
/** La page des conventions. Exportée pour la valider contre le schéma ADF. */
|
|
11
|
-
export const conventionsPage = (project) => markdownToAdf(conventionsMarkdown(project));
|
|
12
|
-
export const templatePage = (project) => markdownToAdf(templateMarkdown(project));
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Crée l'arborescence sous la page ou le dossier `location`. Une page déjà présente sous son
|
|
16
|
-
* titre est réutilisée. Rend la configuration de la source : l'URL de « Tests fonctionnels ».
|
|
17
|
-
* `client` remplace le client Confluence (tests).
|
|
18
|
-
*/
|
|
19
|
-
export async function provisionConfluence({ root, location, envs, project, client: given }) {
|
|
20
|
-
const container = containerOf(location);
|
|
21
|
-
const client = given ?? confluenceClient(container.origin, path.join(root, '.env'));
|
|
22
|
-
const spaceId = await client.spaceOf(container);
|
|
23
|
-
const pages = [];
|
|
24
|
-
|
|
25
|
-
async function ensure(parent, title, doc) {
|
|
26
|
-
const existing = await client.childTitled(parent, title);
|
|
27
|
-
if (existing) {
|
|
28
|
-
const node = { kind: existing.type === 'folder' ? 'folders' : 'pages', id: existing.id };
|
|
29
|
-
node.url = await client.link(node);
|
|
30
|
-
pages.push({ title, url: node.url, created: false });
|
|
31
|
-
return node;
|
|
32
|
-
}
|
|
33
|
-
const page = await client.create({ spaceId, parentId: parent.id, title, doc });
|
|
34
|
-
pages.push({ title, url: page.url, created: true });
|
|
35
|
-
return { kind: 'pages', id: page.id, url: page.url };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const cases = await ensure(container, CASES_TITLE, markdownToAdf(casesIntro(project)));
|
|
39
|
-
await ensure(cases, CONVENTIONS_TITLE, conventionsPage(project));
|
|
40
|
-
await ensure(cases, TEMPLATE_TITLE, templatePage(project));
|
|
41
|
-
const reports = await ensure(cases, REPORTS_TITLE, markdownToAdf(reportsIntro));
|
|
42
|
-
for (const env of envs) {
|
|
43
|
-
await ensure(reports, environmentTitle(env), environmentPage(env));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return { config: { kind: 'confluence', url: cases.url }, pages };
|
|
47
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fingerprint } from '../../mirrors/header.mjs';
|
|
4
|
-
import { CASE_SECTIONS, caseLabel, caseTitle, isObsoleteMark, sectionAnomaly, STEP_COLUMNS } from '../../upstream/test-case.mjs';
|
|
5
|
-
import { demoteHeadings, joinBlock, linesOf, tablesAndText } from './markdown.mjs';
|
|
6
|
-
|
|
7
|
-
/** Le titre du cas : le premier titre de niveau 1. */
|
|
8
|
-
const titleOf = (lines) => lines.find((line) => line.level === 1)?.title ?? '';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Découpe le fichier : le titre de niveau 1, puis les sections de niveau 2. Ce qui sépare le
|
|
12
|
-
* titre de la première section est la description.
|
|
13
|
-
*/
|
|
14
|
-
function sectionsOf(lines, anomalies) {
|
|
15
|
-
const sections = { description: [] };
|
|
16
|
-
let current;
|
|
17
|
-
let titled = false;
|
|
18
|
-
|
|
19
|
-
for (const line of lines) {
|
|
20
|
-
if (line.level === 1 && !titled) {
|
|
21
|
-
titled = true;
|
|
22
|
-
current = 'description';
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (line.level !== 2) {
|
|
26
|
-
if (current) sections[current].push(line.text);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
current = CASE_SECTIONS[caseLabel(line.title)];
|
|
30
|
-
if (!current) {
|
|
31
|
-
anomalies.push(sectionAnomaly.unknown(line.title));
|
|
32
|
-
} else if (sections[current]) {
|
|
33
|
-
anomalies.push(sectionAnomaly.duplicate(line.title));
|
|
34
|
-
current = undefined;
|
|
35
|
-
} else {
|
|
36
|
-
sections[current] = [];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return sections;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** L'unique tableau d'une section, ou `undefined` (anomalie notée) si la section contient autre chose. */
|
|
43
|
-
function onlyTable(texts, section, anomalies) {
|
|
44
|
-
const { tables, strayTexts } = tablesAndText(texts);
|
|
45
|
-
if (tables.length === 1 && strayTexts.length === 0) return tables[0];
|
|
46
|
-
anomalies.push(sectionAnomaly.notOnlyTable(section, tables.length, strayTexts));
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Fiche d'identité : la ligne d'en-tête du tableau (`Champ | Valeur`) est ignorée. */
|
|
51
|
-
function identityOf(texts, anomalies) {
|
|
52
|
-
const table = onlyTable(texts, "Fiche d'identité", anomalies);
|
|
53
|
-
if (!table) return null;
|
|
54
|
-
|
|
55
|
-
const fields = {};
|
|
56
|
-
for (const row of table.slice(1)) {
|
|
57
|
-
if (row.length !== 2) {
|
|
58
|
-
anomalies.push(sectionAnomaly.identityRow);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
fields[caseLabel(row[0])] = row[1];
|
|
62
|
-
}
|
|
63
|
-
return fields;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** `TC-001/S02 (obsolète)` => l'identifiant, et la marque d'étape supprimée. */
|
|
67
|
-
function stepId(text) {
|
|
68
|
-
const mark = text.match(/^(.*?)\s*\(([^)]*)\)$/);
|
|
69
|
-
return mark && isObsoleteMark(mark[2]) ? { id: mark[1], obsolete: true } : { id: text, obsolete: false };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function stepsOf(texts, anomalies) {
|
|
73
|
-
const table = onlyTable(texts, 'Étapes', anomalies);
|
|
74
|
-
if (!table) return [];
|
|
75
|
-
|
|
76
|
-
const [header, ...rows] = table;
|
|
77
|
-
const columns = header.map(caseLabel);
|
|
78
|
-
if (columns.join('|') !== STEP_COLUMNS.join('|')) {
|
|
79
|
-
anomalies.push(sectionAnomaly.stepColumns(columns));
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
return rows.map((row) => {
|
|
83
|
-
const { id, obsolete } = stepId(row[0] ?? '');
|
|
84
|
-
if (row.length !== STEP_COLUMNS.length) {
|
|
85
|
-
anomalies.push(`étape ${id} : ${row.length} cellule(s), ${STEP_COLUMNS.length} attendues`);
|
|
86
|
-
return { id, obsolete, action: undefined, expected: undefined };
|
|
87
|
-
}
|
|
88
|
-
return { id, obsolete, action: row[1], expected: row[2] };
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Un fichier de cas Markdown => son brouillon de cas (voir `buildTestCase`). Les titres internes
|
|
94
|
-
* à une section descendent d'un cran, pour sortir au même niveau qu'un cas Confluence.
|
|
95
|
-
* La version est l'empreinte du fichier : tout changement du fichier est une nouvelle version.
|
|
96
|
-
*/
|
|
97
|
-
export function readMarkdownCase(content, { id, url }) {
|
|
98
|
-
const anomalies = [];
|
|
99
|
-
const lines = linesOf(content);
|
|
100
|
-
const sections = sectionsOf(lines, anomalies);
|
|
101
|
-
const markdownOf = (key) => (sections[key] ? demoteHeadings(joinBlock(sections[key])) : '');
|
|
102
|
-
const identity = sections.identity && identityOf(sections.identity, anomalies);
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
title: titleOf(lines),
|
|
106
|
-
origin: { id, version: fingerprint(content), lastUpdated: identity?.['derniere revision'] ?? '', url },
|
|
107
|
-
identity,
|
|
108
|
-
description: markdownOf('description'),
|
|
109
|
-
prerequisites: markdownOf('prerequisites'),
|
|
110
|
-
postconditions: markdownOf('postconditions'),
|
|
111
|
-
steps: sections.steps && stepsOf(sections.steps, anomalies),
|
|
112
|
-
anomalies,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const posix = (file) => file.split(path.sep).join('/');
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* La source des cas : les fichiers `.md` du dossier, sans descendre dans les sous-dossiers, dont
|
|
120
|
-
* le titre suit la convention. Les autres (conventions, modèle, README) sont ignorés.
|
|
121
|
-
*/
|
|
122
|
-
export function markdownCases(dir, root) {
|
|
123
|
-
return {
|
|
124
|
-
async drafts(conventions) {
|
|
125
|
-
if (!existsSync(dir)) {
|
|
126
|
-
throw new Error(`dossier des cas introuvable : ${dir} (lancer npm run specs -- init <dossier des cas> --dir .)`);
|
|
127
|
-
}
|
|
128
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
129
|
-
.filter((entry) => entry.isFile() && entry.name.endsWith('.md'))
|
|
130
|
-
.map((entry) => entry.name)
|
|
131
|
-
.sort()
|
|
132
|
-
.map((name) => ({ name, content: readFileSync(path.join(dir, name), 'utf8') }))
|
|
133
|
-
.filter(({ content }) => caseTitle(titleOf(linesOf(content)), conventions))
|
|
134
|
-
.map(({ name, content }) => readMarkdownCase(content, { id: name, url: posix(path.relative(root, path.join(dir, name))) }));
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { markdownCases } from './cases.mjs';
|
|
3
|
-
import { markdownReports } from './reports.mjs';
|
|
4
|
-
import { provisionMarkdown } from './workspace.mjs';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Source Markdown : un fichier par cas dans un dossier, versionné par git. La version d'un cas
|
|
8
|
-
* est l'empreinte de son fichier. Configuration : `{ kind: 'markdown', dir }`, le dossier des
|
|
9
|
-
* cas relatif au dossier de tests.
|
|
10
|
-
*/
|
|
11
|
-
/** @type {import('../../index.d.mts').Source} */
|
|
12
|
-
export const markdown = Object.freeze({
|
|
13
|
-
kind: 'markdown',
|
|
14
|
-
|
|
15
|
-
/** Un emplacement passé à `init` : un chemin de dossier, pas une URL. */
|
|
16
|
-
accepts: (location) => !/^[a-z][a-z0-9+.-]*:\/\//i.test(location),
|
|
17
|
-
|
|
18
|
-
open(config, root) {
|
|
19
|
-
if (!config.dir) throw new Error('source markdown sans dir');
|
|
20
|
-
const dir = path.resolve(root, config.dir);
|
|
21
|
-
return { cases: markdownCases(dir, root), reports: markdownReports(dir, root) };
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
provision: provisionMarkdown,
|
|
25
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/** Lecture et écriture du Markdown des fichiers de cas : titres hors blocs de code, tableaux GFM. */
|
|
2
|
-
|
|
3
|
-
const FENCE = /^\s*(`{3,}|~{3,})/;
|
|
4
|
-
|
|
5
|
-
/** Les lignes, chacune avec son niveau de titre (0 si ce n'est pas un titre ou si elle est dans un bloc de code). */
|
|
6
|
-
export function linesOf(content) {
|
|
7
|
-
let fence;
|
|
8
|
-
return content.replace(/\r\n?/g, '\n').split('\n').map((text) => {
|
|
9
|
-
const opening = text.match(FENCE)?.[1];
|
|
10
|
-
if (opening && (!fence || opening.startsWith(fence))) {
|
|
11
|
-
fence = fence ? undefined : opening[0].repeat(3);
|
|
12
|
-
return { text, level: 0 };
|
|
13
|
-
}
|
|
14
|
-
// Une séquence de `#` finale ferme le titre seulement si une espace la précède (CommonMark) : `C#` reste `C#`.
|
|
15
|
-
const heading = fence ? undefined : text.match(/^(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/);
|
|
16
|
-
return heading ? { text, level: heading[1].length, title: heading[2] } : { text, level: 0 };
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Des lignes en un bloc de Markdown : bords vides retirés, lignes vides consécutives réduites à une. */
|
|
21
|
-
export function joinBlock(texts) {
|
|
22
|
-
return texts.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Décale d'un cran les titres hors blocs de code : `#` devient `##`, `######` reste. */
|
|
26
|
-
export function demoteHeadings(content, by = 1) {
|
|
27
|
-
return linesOf(content)
|
|
28
|
-
.map(({ text, level }) => (level > 0 ? `${'#'.repeat(Math.min(level + by, 6))}${text.slice(level)}` : text))
|
|
29
|
-
.join('\n');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const isTableLine = (text) => text.trimStart().startsWith('|');
|
|
33
|
-
const isSeparator = (cells) => cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
|
|
34
|
-
|
|
35
|
-
/** Les cellules d'une ligne de tableau, `\|` conservé tel quel. */
|
|
36
|
-
function cellsOf(line) {
|
|
37
|
-
const trimmed = line.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '');
|
|
38
|
-
return trimmed.split(/(?<!\\)\|/).map((cell) => cell.trim());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Le contenu d'une section : ses tableaux (lignes de cellules, séparateur retiré) et le texte hors tableau. */
|
|
42
|
-
export function tablesAndText(texts) {
|
|
43
|
-
const tables = [];
|
|
44
|
-
const strayTexts = [];
|
|
45
|
-
let current;
|
|
46
|
-
for (const text of texts) {
|
|
47
|
-
if (!isTableLine(text)) {
|
|
48
|
-
current = undefined;
|
|
49
|
-
if (text.trim() !== '') strayTexts.push(text.trim());
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (!current) {
|
|
53
|
-
current = [];
|
|
54
|
-
tables.push(current);
|
|
55
|
-
}
|
|
56
|
-
const cells = cellsOf(text);
|
|
57
|
-
if (!isSeparator(cells)) current.push(cells);
|
|
58
|
-
}
|
|
59
|
-
return { tables, strayTexts };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Une valeur dans une cellule : sur une ligne, `|` échappé. */
|
|
63
|
-
const cell = (value) => String(value ?? '').replace(/\s*\n\s*/g, ' ').replaceAll('|', '\\|');
|
|
64
|
-
|
|
65
|
-
export const tableOf = (header, rows) => [
|
|
66
|
-
`| ${header.join(' | ')} |`,
|
|
67
|
-
`|${' --- |'.repeat(header.length)}`,
|
|
68
|
-
...rows.map((row) => `| ${row.map(cell).join(' | ')} |`),
|
|
69
|
-
].join('\n');
|
|
70
|
-
|
|
71
|
-
/** Un bloc de code dont la barrière ne peut pas apparaître dans le texte. */
|
|
72
|
-
export function codeBlock(text) {
|
|
73
|
-
const longest = Math.max(2, ...[...text.matchAll(/`+/g)].map((match) => match[0].length));
|
|
74
|
-
const fence = '`'.repeat(longest + 1);
|
|
75
|
-
return `${fence}\n${text}\n${fence}`;
|
|
76
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
CLASSEMENTS, contextRows, environmentIntro, environmentTitle, HISTORY_COLUMNS, historyCells, labelOf, REPORTS_TITLE, seconds,
|
|
5
|
-
} from '../../reports/report-model.mjs';
|
|
6
|
-
import { slug } from '../../text.mjs';
|
|
7
|
-
import { codeBlock, tableOf } from './markdown.mjs';
|
|
8
|
-
|
|
9
|
-
/** Le dossier des rapports, sous le dossier des cas. */
|
|
10
|
-
export const REPORTS_DIR = 'rapports';
|
|
11
|
-
|
|
12
|
-
/** Page d'environnement : son historique, vide. */
|
|
13
|
-
export function environmentPage(env) {
|
|
14
|
-
return [
|
|
15
|
-
`# ${environmentTitle(env)}`,
|
|
16
|
-
environmentIntro(env),
|
|
17
|
-
'## Historique',
|
|
18
|
-
tableOf(HISTORY_COLUMNS, []),
|
|
19
|
-
].join('\n\n') + '\n';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const stepResult = (step) => (step.partial === undefined
|
|
23
|
-
? labelOf(step.result)
|
|
24
|
-
: `${labelOf(step.result)}, partielle${step.partial ? ` : ${step.partial}` : ''}`);
|
|
25
|
-
|
|
26
|
-
/** Le fichier du rapport. */
|
|
27
|
-
export function renderReport(report) {
|
|
28
|
-
const { run, diagnostic } = report;
|
|
29
|
-
const parts = [
|
|
30
|
-
`# ${report.title}`,
|
|
31
|
-
'## Verdict',
|
|
32
|
-
labelOf(run.verdict),
|
|
33
|
-
'## Contexte',
|
|
34
|
-
tableOf(['Champ', 'Valeur'], contextRows(report)),
|
|
35
|
-
'## Étapes',
|
|
36
|
-
tableOf(['Étape', 'Action', 'Résultat', 'Durée'],
|
|
37
|
-
run.cases.flatMap((c) => c.steps.map((step) => [step.id, step.action, stepResult(step), seconds(step.duration)]))),
|
|
38
|
-
];
|
|
39
|
-
if (diagnostic) {
|
|
40
|
-
parts.push(
|
|
41
|
-
'## Diagnostic',
|
|
42
|
-
`**Classement :** ${CLASSEMENTS[diagnostic.classement]}`,
|
|
43
|
-
...(diagnostic.etape ? [`**Étape en cause :** ${diagnostic.etape}`] : []),
|
|
44
|
-
...(diagnostic.preuve ? ['**Preuve :**', codeBlock(diagnostic.preuve)] : []),
|
|
45
|
-
...(diagnostic.piste ? [`**Piste :** ${diagnostic.piste.replace(/\s*\n\s*/g, ' ')}`] : []),
|
|
46
|
-
`**Demande de fusion :** ${diagnostic.demandeDeFusion ?? 'aucune'}`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return `${parts.join('\n\n')}\n`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** La page d'environnement, la ligne du rapport insérée sous l'en-tête de l'historique. */
|
|
53
|
-
export function withHistoryRow(page, report, link) {
|
|
54
|
-
const cells = historyCells(report);
|
|
55
|
-
const row = tableOf(HISTORY_COLUMNS, [[cells.when, labelOf(cells.verdict), cells.cases, cells.classement, cells.commit, `[Détail](${link})`]])
|
|
56
|
-
.split('\n')[2];
|
|
57
|
-
const lines = page.split('\n');
|
|
58
|
-
const separator = lines.findIndex((line, index) => index > 0 && /^\|( *:?-{3,}:? *\|)+$/.test(line.trim()) && lines[index - 1].trim().startsWith('|'));
|
|
59
|
-
if (separator === -1) {
|
|
60
|
-
throw new Error("page d'environnement sans tableau d'historique");
|
|
61
|
-
}
|
|
62
|
-
return [...lines.slice(0, separator + 1), row, ...lines.slice(separator + 1)].join('\n');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Un fichier libre dans `dir` : `<base>.md`, sinon `<base>-2.md`, etc. */
|
|
66
|
-
function freeFile(dir, base) {
|
|
67
|
-
for (let n = 1; ; n += 1) {
|
|
68
|
-
const file = path.join(dir, `${base}${n === 1 ? '' : `-${n}`}.md`);
|
|
69
|
-
if (!existsSync(file)) return file;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const posix = (file) => file.split(path.sep).join('/');
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* La publication des rapports, sous `rapports/` du dossier des cas : un fichier par rapport dans
|
|
77
|
-
* `rapports/<env>/`, et sa ligne en tête de l'historique `rapports/<env>.md` (créé s'il manque).
|
|
78
|
-
*/
|
|
79
|
-
export function markdownReports(dir, root) {
|
|
80
|
-
return {
|
|
81
|
-
async publish(report) {
|
|
82
|
-
const reportsDir = path.join(dir, REPORTS_DIR);
|
|
83
|
-
if (!existsSync(reportsDir)) {
|
|
84
|
-
throw new Error(`« ${REPORTS_TITLE} » absent : ${reportsDir} n'existe pas, lancer \`e2e-specs init\``);
|
|
85
|
-
}
|
|
86
|
-
const environmentFile = path.join(reportsDir, `${slug(report.env)}.md`);
|
|
87
|
-
const environment = existsSync(environmentFile) ? readFileSync(environmentFile, 'utf8') : environmentPage(report.env);
|
|
88
|
-
|
|
89
|
-
const runsDir = path.join(reportsDir, slug(report.env));
|
|
90
|
-
mkdirSync(runsDir, { recursive: true });
|
|
91
|
-
const file = freeFile(runsDir, slug(report.title));
|
|
92
|
-
writeFileSync(file, renderReport(report), 'utf8');
|
|
93
|
-
writeFileSync(environmentFile, withHistoryRow(environment, report, posix(path.relative(reportsDir, file))), 'utf8');
|
|
94
|
-
return { url: posix(path.relative(root, file)) };
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { environmentTitle, REPORTS_TITLE } from '../../reports/report-model.mjs';
|
|
4
|
-
import {
|
|
5
|
-
CASES_TITLE, casesIntro, CONVENTIONS_TITLE, conventionsMarkdown, reportsIntro, TEMPLATE_TITLE, templateMarkdown,
|
|
6
|
-
} from '../../upstream/workspace.mjs';
|
|
7
|
-
import { slug } from '../../text.mjs';
|
|
8
|
-
import { demoteHeadings } from './markdown.mjs';
|
|
9
|
-
import { environmentPage, REPORTS_DIR } from './reports.mjs';
|
|
10
|
-
|
|
11
|
-
const posix = (file) => file.split(path.sep).join('/');
|
|
12
|
-
|
|
13
|
-
/** Une page Markdown : son titre en niveau 1, ses sections un cran plus bas. */
|
|
14
|
-
const page = (title, body) => `# ${title}\n\n${demoteHeadings(body).trim()}\n`;
|
|
15
|
-
|
|
16
|
-
/** Le modèle d'un fichier de cas : le titre du cas en niveau 1, les sections en niveau 2. */
|
|
17
|
-
export const templateFile = (project) => page('TC-NNN - Intitulé', templateMarkdown(project));
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Crée le dossier des cas `location` (relatif au dossier courant) : accueil, conventions, modèle,
|
|
21
|
-
* dossier des rapports et une page d'historique par environnement. Un fichier déjà là est gardé.
|
|
22
|
-
* Rend la configuration de la source : le dossier, relatif au dossier de tests `root`.
|
|
23
|
-
*/
|
|
24
|
-
export async function provisionMarkdown({ root, location, envs, project }) {
|
|
25
|
-
const dir = path.resolve(location);
|
|
26
|
-
const pages = [];
|
|
27
|
-
|
|
28
|
-
function ensure(file, title, content) {
|
|
29
|
-
const created = !existsSync(file);
|
|
30
|
-
if (created) {
|
|
31
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
32
|
-
writeFileSync(file, content, 'utf8');
|
|
33
|
-
}
|
|
34
|
-
pages.push({ title, url: posix(path.relative(root, file)), created });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
ensure(path.join(dir, 'README.md'), CASES_TITLE, page(CASES_TITLE, casesIntro(project, 'fichier')));
|
|
38
|
-
ensure(path.join(dir, '00-conventions.md'), CONVENTIONS_TITLE, page(CONVENTIONS_TITLE, conventionsMarkdown(project)));
|
|
39
|
-
ensure(path.join(dir, '00-modele.md'), TEMPLATE_TITLE, templateFile(project));
|
|
40
|
-
ensure(path.join(dir, REPORTS_DIR, 'README.md'), REPORTS_TITLE, page(REPORTS_TITLE, reportsIntro));
|
|
41
|
-
for (const env of envs) {
|
|
42
|
-
ensure(path.join(dir, REPORTS_DIR, `${slug(env)}.md`), environmentTitle(env), environmentPage(env));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return { config: { kind: 'markdown', dir: posix(path.relative(root, dir)) || '.' }, pages };
|
|
46
|
-
}
|