@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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { caseLabel, caseTitle, emptyRecord, isObsoleteMark, sectionAnomaly, sectionKeyOf, STEP_COLUMNS } from '../../upstream/test-case.js';
|
|
2
|
+
import { errorMessage } from '../../text.js';
|
|
3
|
+
import { attrsOf, blocks, cell, contentOf, plainText, statusesIn } from './adf-read.js';
|
|
4
|
+
const label = (node) => caseLabel(plainText(node));
|
|
5
|
+
/**
|
|
6
|
+
* Un relevé d'anomalies. La lecture ADF est la seule à lever (noeud non pris en charge) : `read`
|
|
7
|
+
* convertit cette erreur en anomalie et rend `undefined`.
|
|
8
|
+
*/
|
|
9
|
+
function anomalyLog() {
|
|
10
|
+
const messages = [];
|
|
11
|
+
const add = (message) => messages.push(message);
|
|
12
|
+
return {
|
|
13
|
+
messages,
|
|
14
|
+
add,
|
|
15
|
+
read(readAdf, context) {
|
|
16
|
+
try {
|
|
17
|
+
return readAdf();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
add(context ? `${context} : ${errorMessage(error)}` : errorMessage(error));
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Découpe le document par section de niveau 1 ; ce qui précède la première est la description. */
|
|
27
|
+
function sectionsOf(doc, anomalies) {
|
|
28
|
+
const sections = { description: [] };
|
|
29
|
+
/** Les noeuds de la section en cours ; `undefined` si elle est ignorée (inconnue ou en double). */
|
|
30
|
+
let current = sections.description;
|
|
31
|
+
for (const node of doc.content) {
|
|
32
|
+
const isSectionHeading = node.type === 'heading' && attrsOf(node).level === 1;
|
|
33
|
+
if (!isSectionHeading) {
|
|
34
|
+
if (current)
|
|
35
|
+
current.push(node);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const key = sectionKeyOf(label(node));
|
|
39
|
+
if (!key) {
|
|
40
|
+
anomalies.add(sectionAnomaly.unknown(plainText(node)));
|
|
41
|
+
current = undefined;
|
|
42
|
+
}
|
|
43
|
+
else if (Object.hasOwn(sections, key)) {
|
|
44
|
+
anomalies.add(sectionAnomaly.duplicate(plainText(node)));
|
|
45
|
+
current = undefined;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
current = [];
|
|
49
|
+
sections[key] = current;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return sections;
|
|
53
|
+
}
|
|
54
|
+
/** L'unique tableau d'une section, ou `undefined` (anomalie notée) si la section contient autre chose. */
|
|
55
|
+
function onlyTable(nodes, section, anomalies) {
|
|
56
|
+
const tables = nodes.filter((node) => node.type === 'table');
|
|
57
|
+
const strayTexts = nodes
|
|
58
|
+
.filter((node) => node.type !== 'table' && plainText(node).trim() !== '')
|
|
59
|
+
.map((node) => plainText(node).trim());
|
|
60
|
+
if (tables.length === 1 && strayTexts.length === 0)
|
|
61
|
+
return tables[0];
|
|
62
|
+
anomalies.add(sectionAnomaly.notOnlyTable(section, tables.length, strayTexts));
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
/** Fiche d'identité : libellé canonique du champ => valeur texte. `null` si elle est illisible. */
|
|
66
|
+
function identityOf(nodes, anomalies) {
|
|
67
|
+
const table = onlyTable(nodes, "Fiche d'identité", anomalies);
|
|
68
|
+
if (!table)
|
|
69
|
+
return null;
|
|
70
|
+
const fields = emptyRecord();
|
|
71
|
+
for (const row of contentOf(table)) {
|
|
72
|
+
const cells = contentOf(row);
|
|
73
|
+
if (cells.length !== 2) {
|
|
74
|
+
anomalies.add(sectionAnomaly.identityRow);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const [key, value] = cells;
|
|
78
|
+
fields[label(key)] = plainText(value).trim();
|
|
79
|
+
}
|
|
80
|
+
return fields;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Le noeud sans ses pastilles Obsolète : elles marquent la ligne, elles ne font pas partie du
|
|
84
|
+
* texte de l'action ou du résultat attendu.
|
|
85
|
+
*/
|
|
86
|
+
function withoutObsoleteMark(node) {
|
|
87
|
+
if (!node.content)
|
|
88
|
+
return node;
|
|
89
|
+
const content = node.content
|
|
90
|
+
.filter((child) => !(child.type === 'status' && isObsoleteMark(attrsOf(child).text ?? '')))
|
|
91
|
+
.map(withoutObsoleteMark);
|
|
92
|
+
return { ...node, content };
|
|
93
|
+
}
|
|
94
|
+
/** Le texte brut d'une cellule d'identifiant : ni mise en forme, ni noeud autre que du texte. */
|
|
95
|
+
function idText(cellNode) {
|
|
96
|
+
return contentOf(cellNode)
|
|
97
|
+
.flatMap((paragraph) => paragraph.content ?? [])
|
|
98
|
+
.filter((node) => node.type === 'text')
|
|
99
|
+
.map((node) => node.text)
|
|
100
|
+
.join('')
|
|
101
|
+
.trim();
|
|
102
|
+
}
|
|
103
|
+
/** Une ligne du tableau des étapes. Une étape supprimée porte une pastille Obsolète, dans n'importe quelle cellule. */
|
|
104
|
+
function stepOf(row, anomalies) {
|
|
105
|
+
const [idCell, actionCell, expectedCell] = contentOf(row);
|
|
106
|
+
const id = idText(idCell);
|
|
107
|
+
const readCell = (node) => anomalies.read(() => cell(withoutObsoleteMark(node)), `étape ${id}`);
|
|
108
|
+
return {
|
|
109
|
+
id,
|
|
110
|
+
expected: readCell(expectedCell),
|
|
111
|
+
action: readCell(actionCell),
|
|
112
|
+
obsolete: statusesIn(row).some(isObsoleteMark),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function stepsOf(nodes, anomalies) {
|
|
116
|
+
const table = onlyTable(nodes, 'Étapes', anomalies);
|
|
117
|
+
if (!table)
|
|
118
|
+
return [];
|
|
119
|
+
const [header, ...rows] = contentOf(table);
|
|
120
|
+
const columns = contentOf(header).map(label);
|
|
121
|
+
if (columns.join('|') !== STEP_COLUMNS.join('|')) {
|
|
122
|
+
anomalies.add(sectionAnomaly.stepColumns(columns));
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
return rows.map((row) => stepOf(row, anomalies));
|
|
126
|
+
}
|
|
127
|
+
/** Une page de cas Confluence (corps ADF) => son brouillon de cas (voir `buildTestCase`). */
|
|
128
|
+
export function readConfluenceCase(page) {
|
|
129
|
+
const anomalies = anomalyLog();
|
|
130
|
+
const sections = sectionsOf(page.doc, anomalies);
|
|
131
|
+
const markdownOf = (key) => {
|
|
132
|
+
const nodes = sections[key];
|
|
133
|
+
return nodes ? anomalies.read(() => blocks(nodes)) ?? '' : '';
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
title: page.title,
|
|
137
|
+
origin: { id: page.id, version: page.version, lastUpdated: page.lastUpdated, url: page.url },
|
|
138
|
+
identity: sections.identity && identityOf(sections.identity, anomalies),
|
|
139
|
+
description: markdownOf('description'),
|
|
140
|
+
prerequisites: markdownOf('prerequisites'),
|
|
141
|
+
postconditions: markdownOf('postconditions'),
|
|
142
|
+
steps: sections.steps && stepsOf(sections.steps, anomalies),
|
|
143
|
+
anomalies: anomalies.messages,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* La source des cas : les pages enfants du dossier, au statut `current`, dont le titre suit la
|
|
148
|
+
* convention. Les autres (conventions, modèle, rapports) sont ignorées.
|
|
149
|
+
*/
|
|
150
|
+
export function confluenceCases(container, client) {
|
|
151
|
+
return {
|
|
152
|
+
async drafts(conventions) {
|
|
153
|
+
const candidates = (await client().children(container))
|
|
154
|
+
.filter((child) => child.type === 'page' && child.status === 'current' && caseTitle(child.title, conventions));
|
|
155
|
+
const drafts = [];
|
|
156
|
+
for (const candidate of candidates) {
|
|
157
|
+
drafts.push(readConfluenceCase(await client().page(candidate.id)));
|
|
158
|
+
}
|
|
159
|
+
return drafts;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { AdfDoc } from './adf-read.js';
|
|
2
|
+
/** Une page ou un dossier, tel que l'API v2 le designe dans ses chemins. */
|
|
3
|
+
export interface ContainerRef {
|
|
4
|
+
kind: 'folders' | 'pages';
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
/** Un enfant direct d'une page ou d'un dossier, tel que l'API le rend. */
|
|
8
|
+
export interface ConfluenceChild {
|
|
9
|
+
id: string;
|
|
10
|
+
type: string;
|
|
11
|
+
status: string;
|
|
12
|
+
title: string;
|
|
13
|
+
}
|
|
14
|
+
/** Une page lue : titre, version, corps ADF, URL stable. */
|
|
15
|
+
export interface ConfluencePage {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
version: number;
|
|
19
|
+
lastUpdated: string;
|
|
20
|
+
url: string;
|
|
21
|
+
doc: AdfDoc;
|
|
22
|
+
}
|
|
23
|
+
/** `.../wiki/spaces/KEY/folder/123` ou `.../wiki/spaces/KEY/pages/123/...` => conteneur. */
|
|
24
|
+
export declare function containerOf(url: string): ContainerRef & {
|
|
25
|
+
origin: string;
|
|
26
|
+
};
|
|
27
|
+
/** Client REST v2 minimal : pages et dossiers, corps en ADF. */
|
|
28
|
+
export declare function confluenceClient(origin: string, envFile?: string): {
|
|
29
|
+
/** Les enfants directs du conteneur, toutes pages de resultats. */
|
|
30
|
+
children: ({ kind, id }: ContainerRef) => Promise<ConfluenceChild[]>;
|
|
31
|
+
/** L'enfant direct qui porte exactement ce titre, ou `undefined`. */
|
|
32
|
+
childTitled(container: ContainerRef, title: string): Promise<ConfluenceChild | undefined>;
|
|
33
|
+
/** L'espace du conteneur. */
|
|
34
|
+
spaceOf({ kind, id }: ContainerRef): Promise<string>;
|
|
35
|
+
/** L'URL stable d'une page ou d'un dossier. */
|
|
36
|
+
link({ kind, id }: ContainerRef): Promise<string>;
|
|
37
|
+
/** Une page : titre, version, corps ADF, URL stable. */
|
|
38
|
+
page(id: string): Promise<ConfluencePage>;
|
|
39
|
+
/** Cree une page ; `doc` est un document ADF. */
|
|
40
|
+
create({ spaceId, parentId, title, doc }: {
|
|
41
|
+
spaceId: string;
|
|
42
|
+
parentId: string;
|
|
43
|
+
title: string;
|
|
44
|
+
doc: AdfDoc;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
id: string;
|
|
47
|
+
url: string;
|
|
48
|
+
}>;
|
|
49
|
+
/** Reecrit le corps ; `version` est la version lue, la suivante est publiee. */
|
|
50
|
+
update({ id, title, version, doc }: {
|
|
51
|
+
id: string;
|
|
52
|
+
title: string;
|
|
53
|
+
version: number;
|
|
54
|
+
doc: AdfDoc;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
export type ConfluenceClient = ReturnType<typeof confluenceClient>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
/** Identifiants Confluence : variables d'environnement, ou fichier `.env` passe au client. */
|
|
3
|
+
const CREDENTIALS = { email: 'CONFLUENCE_EMAIL', token: 'CONFLUENCE_API_TOKEN' };
|
|
4
|
+
/** `.../wiki/spaces/KEY/folder/123` ou `.../wiki/spaces/KEY/pages/123/...` => conteneur. */
|
|
5
|
+
export function containerOf(url) {
|
|
6
|
+
const { origin, pathname } = new URL(url);
|
|
7
|
+
const match = pathname.match(/\/wiki\/spaces\/[^/]+\/(folder|pages)\/(\d+)/);
|
|
8
|
+
if (!match) {
|
|
9
|
+
throw new Error(`ni un dossier ni une page Confluence : ${url}`);
|
|
10
|
+
}
|
|
11
|
+
return { origin, kind: match[1] === 'folder' ? 'folders' : 'pages', id: match[2] };
|
|
12
|
+
}
|
|
13
|
+
function authorization(envFile) {
|
|
14
|
+
if (envFile && existsSync(envFile)) {
|
|
15
|
+
process.loadEnvFile(envFile);
|
|
16
|
+
}
|
|
17
|
+
const email = process.env[CREDENTIALS.email];
|
|
18
|
+
const token = process.env[CREDENTIALS.token];
|
|
19
|
+
if (!email || !token) {
|
|
20
|
+
throw new Error(`${CREDENTIALS.email} et ${CREDENTIALS.token} sont requis (environnement${envFile ? ` ou ${envFile}` : ''}). `
|
|
21
|
+
+ 'Jeton : https://id.atlassian.com/manage-profile/security/api-tokens');
|
|
22
|
+
}
|
|
23
|
+
return `Basic ${Buffer.from(`${email}:${token}`).toString('base64')}`;
|
|
24
|
+
}
|
|
25
|
+
/** Client REST v2 minimal : pages et dossiers, corps en ADF. */
|
|
26
|
+
export function confluenceClient(origin, envFile) {
|
|
27
|
+
const auth = authorization(envFile);
|
|
28
|
+
/** `T` : la forme attendue de la reponse JSON, non verifiee. */
|
|
29
|
+
async function request(method, pathAndQuery, payload) {
|
|
30
|
+
const response = await fetch(new URL(pathAndQuery, origin), {
|
|
31
|
+
method,
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: auth,
|
|
34
|
+
Accept: 'application/json',
|
|
35
|
+
...(payload ? { 'Content-Type': 'application/json' } : {}),
|
|
36
|
+
},
|
|
37
|
+
body: payload ? JSON.stringify(payload) : undefined,
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const hint = response.status === 401 || response.status === 403
|
|
41
|
+
? ` : vérifier ${CREDENTIALS.email}, ${CREDENTIALS.token} et l'accès à l'espace`
|
|
42
|
+
: ` : ${(await response.text()).slice(0, 300)}`;
|
|
43
|
+
throw new Error(`Confluence ${response.status} sur ${method} ${pathAndQuery}${hint}`);
|
|
44
|
+
}
|
|
45
|
+
return response.json();
|
|
46
|
+
}
|
|
47
|
+
/** URL stable d'une page, sans le titre que Confluence ajoute en fin de chemin. */
|
|
48
|
+
function urlOf(page) {
|
|
49
|
+
const { webui } = page._links;
|
|
50
|
+
return `${origin}/wiki${webui.match(/^\/spaces\/[^/]+\/(?:pages|folder)\/\d+/)?.[0] ?? webui}`;
|
|
51
|
+
}
|
|
52
|
+
async function children({ kind, id }) {
|
|
53
|
+
const found = [];
|
|
54
|
+
let next = `/wiki/api/v2/${kind}/${id}/direct-children?limit=250`;
|
|
55
|
+
while (next) {
|
|
56
|
+
const page = await request('GET', next);
|
|
57
|
+
found.push(...page.results);
|
|
58
|
+
next = page._links?.next;
|
|
59
|
+
}
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
/** Les enfants directs du conteneur, toutes pages de resultats. */
|
|
64
|
+
children,
|
|
65
|
+
/** L'enfant direct qui porte exactement ce titre, ou `undefined`. */
|
|
66
|
+
async childTitled(container, title) {
|
|
67
|
+
return (await children(container)).find((child) => child.status === 'current' && child.title === title);
|
|
68
|
+
},
|
|
69
|
+
/** L'espace du conteneur. */
|
|
70
|
+
async spaceOf({ kind, id }) {
|
|
71
|
+
return (await request('GET', `/wiki/api/v2/${kind}/${id}`)).spaceId;
|
|
72
|
+
},
|
|
73
|
+
/** L'URL stable d'une page ou d'un dossier. */
|
|
74
|
+
async link({ kind, id }) {
|
|
75
|
+
return urlOf(await request('GET', `/wiki/api/v2/${kind}/${id}`));
|
|
76
|
+
},
|
|
77
|
+
/** Une page : titre, version, corps ADF, URL stable. */
|
|
78
|
+
async page(id) {
|
|
79
|
+
const page = await request('GET', `/wiki/api/v2/pages/${id}?body-format=atlas_doc_format`);
|
|
80
|
+
return {
|
|
81
|
+
id: page.id,
|
|
82
|
+
title: page.title,
|
|
83
|
+
version: page.version.number,
|
|
84
|
+
lastUpdated: page.version.createdAt.slice(0, 10),
|
|
85
|
+
url: urlOf(page),
|
|
86
|
+
/** Corps ADF suppose conforme : non verifie. */
|
|
87
|
+
doc: JSON.parse(page.body.atlas_doc_format.value),
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
/** Cree une page ; `doc` est un document ADF. */
|
|
91
|
+
async create({ spaceId, parentId, title, doc }) {
|
|
92
|
+
const page = await request('POST', '/wiki/api/v2/pages', {
|
|
93
|
+
spaceId, parentId, title, status: 'current', body: { representation: 'atlas_doc_format', value: JSON.stringify(doc) },
|
|
94
|
+
});
|
|
95
|
+
return { id: page.id, url: urlOf(page) };
|
|
96
|
+
},
|
|
97
|
+
/** Reecrit le corps ; `version` est la version lue, la suivante est publiee. */
|
|
98
|
+
async update({ id, title, version, doc }) {
|
|
99
|
+
await request('PUT', `/wiki/api/v2/pages/${id}`, {
|
|
100
|
+
id, title, status: 'current', version: { number: version + 1 }, body: { representation: 'atlas_doc_format', value: JSON.stringify(doc) },
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Source } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Source Confluence : une page par cas sous un dossier, corps en ADF, version de page.
|
|
4
|
+
* Configuration : `{ kind: 'confluence', url }`, l'URL du dossier « Tests fonctionnels ».
|
|
5
|
+
*/
|
|
6
|
+
export declare const confluence: Source;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { confluenceCases } from './cases.js';
|
|
3
|
+
import { confluenceClient, containerOf } from './client.js';
|
|
4
|
+
import { confluenceReports } from './reports.js';
|
|
5
|
+
import { provisionConfluence } from './workspace.js';
|
|
6
|
+
/**
|
|
7
|
+
* Source Confluence : une page par cas sous un dossier, corps en ADF, version de page.
|
|
8
|
+
* Configuration : `{ kind: 'confluence', url }`, l'URL du dossier « Tests fonctionnels ».
|
|
9
|
+
*/
|
|
10
|
+
export const confluence = Object.freeze({
|
|
11
|
+
kind: 'confluence',
|
|
12
|
+
/** Un emplacement passé à `init` : une URL. */
|
|
13
|
+
accepts: (location) => /^https?:\/\//.test(location),
|
|
14
|
+
/**
|
|
15
|
+
* Les cas et les rapports. Le client, qui exige les identifiants, n'est créé qu'au premier
|
|
16
|
+
* appel réseau ; `client` le remplace (tests).
|
|
17
|
+
*/
|
|
18
|
+
open(config, root, { client } = {}) {
|
|
19
|
+
if (!config.url)
|
|
20
|
+
throw new Error('source confluence sans url');
|
|
21
|
+
const container = containerOf(config.url);
|
|
22
|
+
const lazyClient = () => {
|
|
23
|
+
client ??= confluenceClient(container.origin, path.join(root, '.env'));
|
|
24
|
+
return client;
|
|
25
|
+
};
|
|
26
|
+
return { cases: confluenceCases(container, lazyClient), reports: confluenceReports(container, lazyClient) };
|
|
27
|
+
},
|
|
28
|
+
provision: provisionConfluence,
|
|
29
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OpenedSource, Report } from '../../types.js';
|
|
2
|
+
import type { AdfDoc, AdfNode } from './adf-read.js';
|
|
3
|
+
import type { ConfluenceClient, ContainerRef } from './client.js';
|
|
4
|
+
/** Page d'environnement : son historique, vide. */
|
|
5
|
+
export declare function environmentPage(env: string): AdfDoc;
|
|
6
|
+
/** La page du rapport. Exportée pour la valider contre le schéma ADF. */
|
|
7
|
+
export declare function renderReport(report: Report): AdfDoc;
|
|
8
|
+
/** La ligne d'historique qui pointe vers le rapport. */
|
|
9
|
+
export declare function historyRow(report: Report, url: string): AdfNode;
|
|
10
|
+
/** Insère la ligne sous l'en-tête du premier tableau de la page. */
|
|
11
|
+
export declare function withHistoryRow(page: AdfDoc, newRow: AdfNode): AdfDoc;
|
|
12
|
+
/**
|
|
13
|
+
* La publication des rapports : sous « Rapports - <env> » (créée si absente), une page par
|
|
14
|
+
* rapport, et sa ligne en tête de l'historique.
|
|
15
|
+
*/
|
|
16
|
+
export declare function confluenceReports(container: ContainerRef, client: () => ConfluenceClient): OpenedSource['reports'];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { markdownToAdf } from 'marklassian';
|
|
2
|
+
import { CLASSEMENTS, contextRows, environmentIntro, environmentTitle, HISTORY_COLUMNS, historyCells, labelOf, REPORTS_TITLE, seconds, } from '../../reports/report-model.js';
|
|
3
|
+
import { cell, codeBlock, doc, headerCell, heading, link, paragraph, row, status as pill, strong, table, text } from './adf-build.js';
|
|
4
|
+
import { contentOf } from './adf-read.js';
|
|
5
|
+
const COLORS = { vert: 'green', rouge: 'red', vide: 'neutral', passee: 'green', echouee: 'red', 'non atteinte': 'neutral' };
|
|
6
|
+
/** Page d'environnement : son historique, vide. */
|
|
7
|
+
export function environmentPage(env) {
|
|
8
|
+
return markdownToAdf([
|
|
9
|
+
environmentIntro(env),
|
|
10
|
+
'# Historique',
|
|
11
|
+
`| ${HISTORY_COLUMNS.join(' | ')} |\n|${' --- |'.repeat(HISTORY_COLUMNS.length)}`,
|
|
12
|
+
].join('\n\n'));
|
|
13
|
+
}
|
|
14
|
+
const status = (key) => pill(labelOf(key), COLORS[key]);
|
|
15
|
+
/** Le résultat d'une étape ; une étape partielle ajoute sa pastille et ce qui n'est pas vérifié. */
|
|
16
|
+
const stepResult = (step) => (step.partial === undefined
|
|
17
|
+
? [status(step.result)]
|
|
18
|
+
: [status(step.result), text(' '), pill('partielle', 'yellow'), text(step.partial ? ` ${step.partial}` : '')]);
|
|
19
|
+
/** La page du rapport. Exportée pour la valider contre le schéma ADF. */
|
|
20
|
+
export function renderReport(report) {
|
|
21
|
+
const { run, diagnostic } = report;
|
|
22
|
+
const content = [
|
|
23
|
+
heading('Verdict'),
|
|
24
|
+
paragraph(status(run.verdict)),
|
|
25
|
+
heading('Contexte'),
|
|
26
|
+
table(...contextRows(report).map(([label, value]) => row(headerCell(label), cell(text(value))))),
|
|
27
|
+
heading('Étapes'),
|
|
28
|
+
table(row(...['Étape', 'Action', 'Résultat', 'Durée'].map(headerCell)), ...run.cases.flatMap((c) => c.steps.map((step) => row(cell(text(step.id)), cell(text(step.action)), cell(...stepResult(step)), cell(text(seconds(step.duration))))))),
|
|
29
|
+
];
|
|
30
|
+
if (diagnostic) {
|
|
31
|
+
content.push(heading('Diagnostic'), paragraph(strong('Classement : '), text(CLASSEMENTS[diagnostic.classement])), ...(diagnostic.etape ? [paragraph(strong('Étape en cause : '), text(diagnostic.etape))] : []), ...(diagnostic.preuve ? [paragraph(strong('Preuve :')), codeBlock(diagnostic.preuve)] : []), ...(diagnostic.piste ? [paragraph(strong('Piste : '), text(diagnostic.piste))] : []), paragraph(strong('Demande de fusion : '), diagnostic.demandeDeFusion ? link(diagnostic.demandeDeFusion, diagnostic.demandeDeFusion) : text('aucune')));
|
|
32
|
+
}
|
|
33
|
+
return doc(content);
|
|
34
|
+
}
|
|
35
|
+
/** La ligne d'historique qui pointe vers le rapport. */
|
|
36
|
+
export function historyRow(report, url) {
|
|
37
|
+
const cells = historyCells(report);
|
|
38
|
+
return row(cell(text(cells.when)), cell(status(cells.verdict)), cell(text(cells.cases)), cell(text(cells.classement)), cell(text(cells.commit)), cell(link('Détail', url)));
|
|
39
|
+
}
|
|
40
|
+
/** Insère la ligne sous l'en-tête du premier tableau de la page. */
|
|
41
|
+
export function withHistoryRow(page, newRow) {
|
|
42
|
+
const history = page.content.find((node) => node.type === 'table');
|
|
43
|
+
if (!history) {
|
|
44
|
+
throw new Error("page d'environnement sans tableau d'historique");
|
|
45
|
+
}
|
|
46
|
+
const [header, ...rows] = contentOf(history);
|
|
47
|
+
history.content = [header, newRow, ...rows];
|
|
48
|
+
return page;
|
|
49
|
+
}
|
|
50
|
+
/** La page « Rapports - <env> », créée sous « Rapports d'exécution » si elle manque. */
|
|
51
|
+
async function environmentPageOf(client, container, env) {
|
|
52
|
+
const reports = await client.childTitled(container, REPORTS_TITLE);
|
|
53
|
+
if (!reports) {
|
|
54
|
+
throw new Error(`« ${REPORTS_TITLE} » absente sous le dossier des cas : lancer \`e2e-specs init\``);
|
|
55
|
+
}
|
|
56
|
+
const spaceId = await client.spaceOf(container);
|
|
57
|
+
const reportsContainer = { kind: reports.type === 'folder' ? 'folders' : 'pages', id: reports.id };
|
|
58
|
+
const existing = await client.childTitled(reportsContainer, environmentTitle(env));
|
|
59
|
+
const page = existing ?? await client.create({ spaceId, parentId: reports.id, title: environmentTitle(env), doc: environmentPage(env) });
|
|
60
|
+
return { id: page.id, spaceId };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* La publication des rapports : sous « Rapports - <env> » (créée si absente), une page par
|
|
64
|
+
* rapport, et sa ligne en tête de l'historique.
|
|
65
|
+
*/
|
|
66
|
+
export function confluenceReports(container, client) {
|
|
67
|
+
return {
|
|
68
|
+
async publish(report) {
|
|
69
|
+
const environment = await environmentPageOf(client(), container, report.env);
|
|
70
|
+
const page = await client().create({
|
|
71
|
+
spaceId: environment.spaceId, parentId: environment.id, title: report.title, doc: renderReport(report),
|
|
72
|
+
});
|
|
73
|
+
const history = await client().page(environment.id);
|
|
74
|
+
await client().update({ ...history, doc: withHistoryRow(history.doc, historyRow(report, page.url)) });
|
|
75
|
+
return { url: page.url };
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Source } from '../../types.js';
|
|
2
|
+
import type { AdfDoc } from './adf-read.js';
|
|
3
|
+
import type { ConfluenceClient } from './client.js';
|
|
4
|
+
type ProvisionSettings = Parameters<Source['provision']>[0];
|
|
5
|
+
type ProvisionResult = Awaited<ReturnType<Source['provision']>>;
|
|
6
|
+
/** La page des conventions. Exportée pour la valider contre le schéma ADF. */
|
|
7
|
+
export declare const conventionsPage: (project: string) => AdfDoc;
|
|
8
|
+
export declare const templatePage: (project: string) => AdfDoc;
|
|
9
|
+
/**
|
|
10
|
+
* Crée l'arborescence sous la page ou le dossier `location`. Une page déjà présente sous son
|
|
11
|
+
* titre est réutilisée. Rend la configuration de la source : l'URL de « Tests fonctionnels ».
|
|
12
|
+
* `client` remplace le client Confluence (tests).
|
|
13
|
+
*/
|
|
14
|
+
export declare function provisionConfluence({ root, location, envs, project, client: given }: ProvisionSettings & {
|
|
15
|
+
client?: ConfluenceClient;
|
|
16
|
+
}): Promise<ProvisionResult>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { markdownToAdf } from 'marklassian';
|
|
3
|
+
import { environmentTitle, REPORTS_TITLE } from '../../reports/report-model.js';
|
|
4
|
+
import { CASES_TITLE, casesIntro, CONVENTIONS_TITLE, conventionsMarkdown, reportsIntro, TEMPLATE_TITLE, templateMarkdown, } from '../../upstream/workspace.js';
|
|
5
|
+
import { confluenceClient, containerOf } from './client.js';
|
|
6
|
+
import { environmentPage } from './reports.js';
|
|
7
|
+
/** La page des conventions. Exportée pour la valider contre le schéma ADF. */
|
|
8
|
+
export const conventionsPage = (project) => markdownToAdf(conventionsMarkdown(project));
|
|
9
|
+
export const templatePage = (project) => markdownToAdf(templateMarkdown(project));
|
|
10
|
+
/**
|
|
11
|
+
* Crée l'arborescence sous la page ou le dossier `location`. Une page déjà présente sous son
|
|
12
|
+
* titre est réutilisée. Rend la configuration de la source : l'URL de « Tests fonctionnels ».
|
|
13
|
+
* `client` remplace le client Confluence (tests).
|
|
14
|
+
*/
|
|
15
|
+
export async function provisionConfluence({ root, location, envs, project, client: given }) {
|
|
16
|
+
const container = containerOf(location);
|
|
17
|
+
const client = given ?? confluenceClient(container.origin, path.join(root, '.env'));
|
|
18
|
+
const spaceId = await client.spaceOf(container);
|
|
19
|
+
const pages = [];
|
|
20
|
+
async function ensure(parent, title, doc) {
|
|
21
|
+
const existing = await client.childTitled(parent, title);
|
|
22
|
+
if (existing) {
|
|
23
|
+
const ref = { kind: existing.type === 'folder' ? 'folders' : 'pages', id: existing.id };
|
|
24
|
+
const node = { ...ref, url: await client.link(ref) };
|
|
25
|
+
pages.push({ title, url: node.url, created: false });
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
const page = await client.create({ spaceId, parentId: parent.id, title, doc });
|
|
29
|
+
pages.push({ title, url: page.url, created: true });
|
|
30
|
+
return { kind: 'pages', id: page.id, url: page.url };
|
|
31
|
+
}
|
|
32
|
+
const cases = await ensure(container, CASES_TITLE, markdownToAdf(casesIntro(project)));
|
|
33
|
+
await ensure(cases, CONVENTIONS_TITLE, conventionsPage(project));
|
|
34
|
+
await ensure(cases, TEMPLATE_TITLE, templatePage(project));
|
|
35
|
+
const reports = await ensure(cases, REPORTS_TITLE, markdownToAdf(reportsIntro));
|
|
36
|
+
for (const env of envs) {
|
|
37
|
+
await ensure(reports, environmentTitle(env), environmentPage(env));
|
|
38
|
+
}
|
|
39
|
+
return { config: { kind: 'confluence', url: cases.url }, pages };
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CaseDraft, OpenedSource } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Un fichier de cas Markdown => son brouillon de cas (voir `buildTestCase`). Les titres internes
|
|
4
|
+
* à une section descendent d'un cran, pour sortir au même niveau qu'un cas Confluence.
|
|
5
|
+
* La version est l'empreinte du fichier : tout changement du fichier est une nouvelle version.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readMarkdownCase(content: string, { id, url }: {
|
|
8
|
+
id: string;
|
|
9
|
+
url: string;
|
|
10
|
+
}): CaseDraft;
|
|
11
|
+
/**
|
|
12
|
+
* La source des cas : les fichiers `.md` du dossier, sans descendre dans les sous-dossiers, dont
|
|
13
|
+
* le titre suit la convention. Les autres (conventions, modèle, README) sont ignorés.
|
|
14
|
+
*/
|
|
15
|
+
export declare function markdownCases(dir: string, root: string): OpenedSource['cases'];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fingerprint } from '../../mirrors/header.js';
|
|
4
|
+
import { caseLabel, caseTitle, emptyRecord, isObsoleteMark, sectionAnomaly, sectionKeyOf, STEP_COLUMNS } from '../../upstream/test-case.js';
|
|
5
|
+
import { demoteHeadings, joinBlock, linesOf, tablesAndText } from './markdown.js';
|
|
6
|
+
/** Le titre du cas : le premier titre de niveau 1. */
|
|
7
|
+
const titleOf = (lines) => lines.find((line) => line.level === 1)?.title ?? '';
|
|
8
|
+
/**
|
|
9
|
+
* Découpe le fichier : le titre de niveau 1, puis les sections de niveau 2. Ce qui sépare le
|
|
10
|
+
* titre de la première section est la description.
|
|
11
|
+
*/
|
|
12
|
+
function sectionsOf(lines, anomalies) {
|
|
13
|
+
const sections = { description: [] };
|
|
14
|
+
let current;
|
|
15
|
+
let titled = false;
|
|
16
|
+
for (const line of lines) {
|
|
17
|
+
if (line.level === 1 && !titled) {
|
|
18
|
+
titled = true;
|
|
19
|
+
current = 'description';
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (line.level !== 2) {
|
|
23
|
+
if (current)
|
|
24
|
+
sections[current]?.push(line.text);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const title = line.title ?? '';
|
|
28
|
+
current = sectionKeyOf(caseLabel(title));
|
|
29
|
+
if (!current) {
|
|
30
|
+
anomalies.push(sectionAnomaly.unknown(title));
|
|
31
|
+
}
|
|
32
|
+
else if (Object.hasOwn(sections, current)) {
|
|
33
|
+
anomalies.push(sectionAnomaly.duplicate(title));
|
|
34
|
+
current = undefined;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
sections[current] = [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return sections;
|
|
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)
|
|
46
|
+
return tables[0];
|
|
47
|
+
anomalies.push(sectionAnomaly.notOnlyTable(section, tables.length, strayTexts));
|
|
48
|
+
return undefined;
|
|
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)
|
|
54
|
+
return null;
|
|
55
|
+
const fields = emptyRecord();
|
|
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
|
+
/** `TC-001/S02 (obsolète)` => l'identifiant, et la marque d'étape supprimée. */
|
|
66
|
+
function stepId(text) {
|
|
67
|
+
const mark = text.match(/^(.*?)\s*\(([^)]*)\)$/);
|
|
68
|
+
return mark && isObsoleteMark(mark[2]) ? { id: mark[1], obsolete: true } : { id: text, obsolete: false };
|
|
69
|
+
}
|
|
70
|
+
function stepsOf(texts, anomalies) {
|
|
71
|
+
const table = onlyTable(texts, 'Étapes', anomalies);
|
|
72
|
+
if (!table)
|
|
73
|
+
return [];
|
|
74
|
+
const [header = [], ...rows] = table;
|
|
75
|
+
const columns = header.map(caseLabel);
|
|
76
|
+
if (columns.join('|') !== STEP_COLUMNS.join('|')) {
|
|
77
|
+
anomalies.push(sectionAnomaly.stepColumns(columns));
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return rows.map((row) => {
|
|
81
|
+
const { id, obsolete } = stepId(row[0] ?? '');
|
|
82
|
+
if (row.length !== STEP_COLUMNS.length) {
|
|
83
|
+
anomalies.push(`étape ${id} : ${row.length} cellule(s), ${STEP_COLUMNS.length} attendues`);
|
|
84
|
+
return { id, obsolete, action: undefined, expected: undefined };
|
|
85
|
+
}
|
|
86
|
+
return { id, obsolete, action: row[1], expected: row[2] };
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Un fichier de cas Markdown => son brouillon de cas (voir `buildTestCase`). Les titres internes
|
|
91
|
+
* à une section descendent d'un cran, pour sortir au même niveau qu'un cas Confluence.
|
|
92
|
+
* La version est l'empreinte du fichier : tout changement du fichier est une nouvelle version.
|
|
93
|
+
*/
|
|
94
|
+
export function readMarkdownCase(content, { id, url }) {
|
|
95
|
+
const anomalies = [];
|
|
96
|
+
const lines = linesOf(content);
|
|
97
|
+
const sections = sectionsOf(lines, anomalies);
|
|
98
|
+
const markdownOf = (key) => {
|
|
99
|
+
const texts = sections[key];
|
|
100
|
+
return texts ? demoteHeadings(joinBlock(texts)) : '';
|
|
101
|
+
};
|
|
102
|
+
const identity = sections.identity && identityOf(sections.identity, anomalies);
|
|
103
|
+
return {
|
|
104
|
+
title: titleOf(lines),
|
|
105
|
+
origin: { id, version: fingerprint(content), lastUpdated: identity?.['derniere revision'] ?? '', url },
|
|
106
|
+
identity,
|
|
107
|
+
description: markdownOf('description'),
|
|
108
|
+
prerequisites: markdownOf('prerequisites'),
|
|
109
|
+
postconditions: markdownOf('postconditions'),
|
|
110
|
+
steps: sections.steps && stepsOf(sections.steps, anomalies),
|
|
111
|
+
anomalies,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const posix = (file) => file.split(path.sep).join('/');
|
|
115
|
+
/**
|
|
116
|
+
* La source des cas : les fichiers `.md` du dossier, sans descendre dans les sous-dossiers, dont
|
|
117
|
+
* le titre suit la convention. Les autres (conventions, modèle, README) sont ignorés.
|
|
118
|
+
*/
|
|
119
|
+
export function markdownCases(dir, root) {
|
|
120
|
+
return {
|
|
121
|
+
async drafts(conventions) {
|
|
122
|
+
if (!existsSync(dir)) {
|
|
123
|
+
throw new Error(`dossier des cas introuvable : ${dir} (lancer npm run specs -- init <dossier des cas> --dir .)`);
|
|
124
|
+
}
|
|
125
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
126
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.md'))
|
|
127
|
+
.map((entry) => entry.name)
|
|
128
|
+
.sort()
|
|
129
|
+
.map((name) => ({ name, content: readFileSync(path.join(dir, name), 'utf8') }))
|
|
130
|
+
.filter(({ content }) => caseTitle(titleOf(linesOf(content)), conventions))
|
|
131
|
+
.map(({ name, content }) => readMarkdownCase(content, { id: name, url: posix(path.relative(root, path.join(dir, name))) }));
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|