@simpright/portal 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -1
- package/dist/bugs.d.ts +3 -0
- package/dist/bugs.js +112 -0
- package/dist/build-pages.d.ts +3 -0
- package/dist/build-pages.js +28 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +145 -0
- package/dist/preview.d.ts +13 -0
- package/dist/preview.js +85 -0
- package/dist/publish-run.d.ts +19 -0
- package/dist/publish-run.js +78 -0
- package/dist/run-summaries.d.ts +8 -0
- package/dist/run-summaries.js +91 -0
- package/dist/site.d.ts +34 -0
- package/dist/site.js +63 -0
- package/dist/test-cases.d.ts +3 -0
- package/dist/test-cases.js +155 -0
- package/package.json +41 -5
- package/pages/bugs.html +1240 -0
- package/pages/dashboard.html +1230 -0
- package/pages/test-cases.html +1287 -0
- package/sample/.nojekyll +0 -0
- package/sample/api-regression/run-1/index.html +10 -0
- package/sample/api-regression/run-1/run-summary.json +1 -0
- package/sample/api-regression/run-10/index.html +10 -0
- package/sample/api-regression/run-10/run-summary.json +1 -0
- package/sample/api-regression/run-2/index.html +10 -0
- package/sample/api-regression/run-2/run-summary.json +1 -0
- package/sample/api-regression/run-3/index.html +10 -0
- package/sample/api-regression/run-3/run-summary.json +1 -0
- package/sample/api-regression/run-4/index.html +10 -0
- package/sample/api-regression/run-4/run-summary.json +1 -0
- package/sample/api-regression/run-5/index.html +10 -0
- package/sample/api-regression/run-5/run-summary.json +1 -0
- package/sample/api-regression/run-6/index.html +10 -0
- package/sample/api-regression/run-6/run-summary.json +1 -0
- package/sample/api-regression/run-7/index.html +10 -0
- package/sample/api-regression/run-7/run-summary.json +1 -0
- package/sample/api-regression/run-8/index.html +10 -0
- package/sample/api-regression/run-8/run-summary.json +1 -0
- package/sample/api-regression/run-9/index.html +10 -0
- package/sample/api-regression/run-9/run-summary.json +1 -0
- package/sample/api-regression-history.json +1 -0
- package/sample/api-regression-manifest.json +12 -0
- package/sample/bugs/bugs-data.js +130 -0
- package/sample/custom-ui/run-1/index.html +10 -0
- package/sample/custom-ui/run-1/run-summary.json +1 -0
- package/sample/custom-ui/run-2/index.html +10 -0
- package/sample/custom-ui/run-2/run-summary.json +1 -0
- package/sample/custom-ui-history.json +1 -0
- package/sample/custom-ui-manifest.json +4 -0
- package/sample/latest/api-regression/index.html +10 -0
- package/sample/latest/api-regression/run-summary.json +1 -0
- package/sample/latest/custom-ui/index.html +10 -0
- package/sample/latest/custom-ui/run-summary.json +1 -0
- package/sample/latest/smoke/index.html +10 -0
- package/sample/latest/smoke/run-summary.json +1 -0
- package/sample/latest/ui-regression/index.html +10 -0
- package/sample/latest/ui-regression/run-summary.json +1 -0
- package/sample/portal.json +37 -0
- package/sample/site.json +3 -0
- package/sample/smoke/run-1/index.html +10 -0
- package/sample/smoke/run-1/run-summary.json +1 -0
- package/sample/smoke/run-2/index.html +10 -0
- package/sample/smoke/run-2/run-summary.json +1 -0
- package/sample/smoke/run-3/index.html +10 -0
- package/sample/smoke/run-3/run-summary.json +1 -0
- package/sample/smoke/run-4/index.html +10 -0
- package/sample/smoke/run-4/run-summary.json +1 -0
- package/sample/smoke-history.json +1 -0
- package/sample/smoke-manifest.json +6 -0
- package/sample/test-cases/api/scenarios-data.js +169 -0
- package/sample/test-cases/ui/scenarios-data.js +191 -0
- package/sample/ui-regression/run-1/index.html +10 -0
- package/sample/ui-regression/run-1/run-summary.json +1 -0
- package/sample/ui-regression/run-10/index.html +10 -0
- package/sample/ui-regression/run-10/run-summary.json +1 -0
- package/sample/ui-regression/run-2/index.html +10 -0
- package/sample/ui-regression/run-2/run-summary.json +1 -0
- package/sample/ui-regression/run-3/index.html +10 -0
- package/sample/ui-regression/run-3/run-summary.json +1 -0
- package/sample/ui-regression/run-4/index.html +10 -0
- package/sample/ui-regression/run-4/run-summary.json +1 -0
- package/sample/ui-regression/run-5/index.html +10 -0
- package/sample/ui-regression/run-5/run-summary.json +1 -0
- package/sample/ui-regression/run-6/index.html +10 -0
- package/sample/ui-regression/run-6/run-summary.json +1 -0
- package/sample/ui-regression/run-7/index.html +10 -0
- package/sample/ui-regression/run-7/run-summary.json +1 -0
- package/sample/ui-regression/run-8/index.html +10 -0
- package/sample/ui-regression/run-8/run-summary.json +1 -0
- package/sample/ui-regression/run-9/index.html +10 -0
- package/sample/ui-regression/run-9/run-summary.json +1 -0
- package/sample/ui-regression-history.json +1 -0
- package/sample/ui-regression-manifest.json +12 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The small JSON files the portal reads, so the browser never downloads a run's full results.json (an API
|
|
2
|
+
// regression's is about 8 MB) or the coverage summary (about 400 KB). publish-run and build-pages
|
|
3
|
+
// (src/publish-run.ts, src/build-pages.ts) write them into a site folder (a gh-pages checkout, or any folder):
|
|
4
|
+
// <family>/run-<N>/run-summary.json one run: its stats, known issues and each scenario test's last status
|
|
5
|
+
// (read by the Bugs page); written once per run, from its results.json,
|
|
6
|
+
// which publish-run then removes
|
|
7
|
+
// latest/<family>/run-summary.json a copy of the newest run's
|
|
8
|
+
// <family>-history.json every kept run of the family, newest first, with its stats, plus the
|
|
9
|
+
// newest run's known issues (read by the dashboard)
|
|
10
|
+
// latest/api-coverage/totals.json the coverage summary's totals, without the per-endpoint detail
|
|
11
|
+
//
|
|
12
|
+
// The output depends only on the site's files, so two workflows writing the same file write the same bytes.
|
|
13
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
/** A run's folder in its family's folder: run-<the workflow's run number>. */
|
|
16
|
+
export const RUN_FOLDER = /^run-\d+$/;
|
|
17
|
+
const SUMMARY = 'run-summary.json';
|
|
18
|
+
const TITLE_ID = /^([A-Z]+-\d+):/;
|
|
19
|
+
const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'));
|
|
20
|
+
const writeJson = (file, data) => writeFileSync(file, `${JSON.stringify(data)}\n`);
|
|
21
|
+
// Playwright JSON report: suites (file -> describe blocks) -> specs (one per test title) -> tests (one per project).
|
|
22
|
+
// A known issue is an annotation containing "Known issue" (test.fail(true, 'Known issue BUG-003: ...')).
|
|
23
|
+
function summarize(run, report) {
|
|
24
|
+
const knownIssues = [];
|
|
25
|
+
const tests = {};
|
|
26
|
+
const walk = (suite, area) => {
|
|
27
|
+
for (const spec of suite.specs ?? []) {
|
|
28
|
+
for (const test of spec.tests ?? []) {
|
|
29
|
+
for (const { description = '' } of test.annotations ?? []) {
|
|
30
|
+
if (!description.includes('Known issue'))
|
|
31
|
+
continue;
|
|
32
|
+
if (!knownIssues.some((issue) => issue.testName === spec.title && issue.description === description)) {
|
|
33
|
+
knownIssues.push({ area, testName: spec.title, description });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const id = TITLE_ID.exec(spec.title)?.[1];
|
|
38
|
+
const test = spec.tests?.[0];
|
|
39
|
+
if (id && test)
|
|
40
|
+
tests[id] = { status: test.results?.at(-1)?.status ?? 'skipped', expectedStatus: test.expectedStatus };
|
|
41
|
+
}
|
|
42
|
+
for (const child of suite.suites ?? [])
|
|
43
|
+
walk(child, area);
|
|
44
|
+
};
|
|
45
|
+
for (const suite of report.suites ?? [])
|
|
46
|
+
walk(suite, suite.title);
|
|
47
|
+
return { run, stats: report.stats ?? {}, knownIssues, tests };
|
|
48
|
+
}
|
|
49
|
+
// The run's summary, built from its results.json the first time; undefined when the run has no results.
|
|
50
|
+
function runSummary(site, family, run) {
|
|
51
|
+
const dir = path.join(site, family, run);
|
|
52
|
+
const summaryFile = path.join(dir, SUMMARY);
|
|
53
|
+
if (existsSync(summaryFile))
|
|
54
|
+
return readJson(summaryFile);
|
|
55
|
+
const resultsFile = path.join(dir, 'results.json');
|
|
56
|
+
if (!existsSync(resultsFile))
|
|
57
|
+
return undefined;
|
|
58
|
+
const summary = summarize(run, readJson(resultsFile));
|
|
59
|
+
writeJson(summaryFile, summary);
|
|
60
|
+
return summary;
|
|
61
|
+
}
|
|
62
|
+
/** The family's run summaries, the newest one's copy in latest/<family>/ and <family>-history.json, for the runs in <family>-manifest.json. */
|
|
63
|
+
export function buildFamily(site, family) {
|
|
64
|
+
const runs = readJson(path.join(site, `${family}-manifest.json`)).filter((run) => RUN_FOLDER.test(run));
|
|
65
|
+
const summaries = runs.map((run) => ({ run, summary: runSummary(site, family, run) }));
|
|
66
|
+
const newest = summaries[0]?.summary;
|
|
67
|
+
const latestDir = path.join(site, 'latest', family);
|
|
68
|
+
if (newest && existsSync(latestDir))
|
|
69
|
+
writeJson(path.join(latestDir, SUMMARY), newest);
|
|
70
|
+
writeJson(path.join(site, `${family}-history.json`), {
|
|
71
|
+
runs: summaries.map(({ run, summary }) => ({ run, stats: summary?.stats ?? null })),
|
|
72
|
+
knownIssues: newest?.knownIssues ?? [],
|
|
73
|
+
});
|
|
74
|
+
console.log(`${family}: ${runs.length} runs in ${family}-history.json`);
|
|
75
|
+
}
|
|
76
|
+
/** The report families that have a manifest but no history yet. */
|
|
77
|
+
export function familiesWithoutHistory(site) {
|
|
78
|
+
return readdirSync(site)
|
|
79
|
+
.filter((name) => name.endsWith('-manifest.json'))
|
|
80
|
+
.map((name) => name.slice(0, -'-manifest.json'.length))
|
|
81
|
+
.filter((family) => !existsSync(path.join(site, `${family}-history.json`)));
|
|
82
|
+
}
|
|
83
|
+
/** latest/api-coverage/totals.json: only the scalar totals (overallCoveragePct, coveredEndpoints, ...); the per-endpoint detail stays in summary.json. */
|
|
84
|
+
export function buildCoverageTotals(site) {
|
|
85
|
+
const summaryFile = path.join(site, 'latest/api-coverage/summary.json');
|
|
86
|
+
if (!existsSync(summaryFile))
|
|
87
|
+
return;
|
|
88
|
+
const summary = readJson(summaryFile);
|
|
89
|
+
const totals = Object.fromEntries(Object.entries(summary).filter(([, value]) => typeof value !== 'object'));
|
|
90
|
+
writeJson(path.join(site, 'latest/api-coverage/totals.json'), totals);
|
|
91
|
+
}
|
package/dist/site.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Config, type Portal } from 'simpright/config';
|
|
2
|
+
/** The pages this package ships: dashboard.html (the site's index.html), test-cases.html and bugs.html. */
|
|
3
|
+
export declare const PAGES_DIR: string;
|
|
4
|
+
/** The brand the portal pages show (portal.json, and the Test Cases and Bugs data files). */
|
|
5
|
+
export declare function portalBrand(portal: Portal): Pick<Portal, 'title' | 'titleAccent' | 'tagline'>;
|
|
6
|
+
/** When the pages were built: SOURCE_DATE_EPOCH (seconds) when it's set, for builds that must be reproducible, else now. */
|
|
7
|
+
export declare function buildTime(): string;
|
|
8
|
+
/**
|
|
9
|
+
* portal.json, what the dashboard (index.html) shows: its brand and description and the health thresholds
|
|
10
|
+
* (simpright.yml portal), the test runs it lists (simpright.yml runs) and the repository it links to.
|
|
11
|
+
*/
|
|
12
|
+
export declare function portalConfig(root: string, config: Config): {
|
|
13
|
+
title: string;
|
|
14
|
+
titleAccent?: string;
|
|
15
|
+
tagline?: string;
|
|
16
|
+
formatVersion: number;
|
|
17
|
+
description: string | undefined;
|
|
18
|
+
repository: string;
|
|
19
|
+
wiki: boolean;
|
|
20
|
+
healthThreshold: Partial<Record<"api" | "ui", number>>;
|
|
21
|
+
runs: {
|
|
22
|
+
id: string;
|
|
23
|
+
label: string;
|
|
24
|
+
note: string | undefined;
|
|
25
|
+
trend: "api" | "ui" | undefined;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Writes the dashboard into the site: index.html, its portal.json, .nojekyll (serve the files as they are, without
|
|
30
|
+
* Jekyll) and, when the site has none yet, site.json with the layout version.
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeDashboard(root: string, config: Config, site: string): void;
|
|
33
|
+
/** Replaces the `target` folder with a copy of the `source` folder. */
|
|
34
|
+
export declare function replaceDir(source: string, target: string): void;
|
package/dist/site.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Writing a portal site folder (a gh-pages checkout, or any folder): the dashboard that every publish refreshes, the
|
|
2
|
+
// site's layout version, and the folder copy the commands share. Pushing the folder is the CI step's job.
|
|
3
|
+
import { copyFileSync, cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { repositoryUrl } from 'simpright/config';
|
|
7
|
+
/** The pages this package ships: dashboard.html (the site's index.html), test-cases.html and bugs.html. */
|
|
8
|
+
export const PAGES_DIR = fileURLToPath(new URL('../pages/', import.meta.url));
|
|
9
|
+
/** Changes when the format changes, so a page can tell an older portal.json apart. */
|
|
10
|
+
const PORTAL_FORMAT_VERSION = 1;
|
|
11
|
+
/** The site's layout (the folders and files described in publish-run.ts); a later version can migrate older sites. */
|
|
12
|
+
const SITE_LAYOUT_VERSION = 1;
|
|
13
|
+
/** The brand the portal pages show (portal.json, and the Test Cases and Bugs data files). */
|
|
14
|
+
export function portalBrand(portal) {
|
|
15
|
+
return { title: portal.title, titleAccent: portal.titleAccent, tagline: portal.tagline };
|
|
16
|
+
}
|
|
17
|
+
/** When the pages were built: SOURCE_DATE_EPOCH (seconds) when it's set, for builds that must be reproducible, else now. */
|
|
18
|
+
export function buildTime() {
|
|
19
|
+
const epoch = process.env.SOURCE_DATE_EPOCH;
|
|
20
|
+
return (epoch && /^\d+$/.test(epoch) ? new Date(Number(epoch) * 1000) : new Date()).toISOString();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* portal.json, what the dashboard (index.html) shows: its brand and description and the health thresholds
|
|
24
|
+
* (simpright.yml portal), the test runs it lists (simpright.yml runs) and the repository it links to.
|
|
25
|
+
*/
|
|
26
|
+
export function portalConfig(root, config) {
|
|
27
|
+
const { portal, runs } = config;
|
|
28
|
+
if (!portal || !runs)
|
|
29
|
+
throw new Error('simpright.yml needs a portal section and runs to build the portal.');
|
|
30
|
+
return {
|
|
31
|
+
formatVersion: PORTAL_FORMAT_VERSION,
|
|
32
|
+
...portalBrand(portal),
|
|
33
|
+
description: portal.description,
|
|
34
|
+
repository: repositoryUrl(root),
|
|
35
|
+
// The side panel links the repository's wiki only when the project publishes one (simpright.yml parts.wiki).
|
|
36
|
+
wiki: config.parts?.wiki === true,
|
|
37
|
+
healthThreshold: portal.healthThreshold ?? {},
|
|
38
|
+
// Only what the page shows: the Latest reports links, the Run history rows and the layers' regressions.
|
|
39
|
+
runs: runs.map(({ id, label, note, trend }) => ({ id, label, note, trend })),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Writes the dashboard into the site: index.html, its portal.json, .nojekyll (serve the files as they are, without
|
|
44
|
+
* Jekyll) and, when the site has none yet, site.json with the layout version.
|
|
45
|
+
*/
|
|
46
|
+
export function writeDashboard(root, config, site) {
|
|
47
|
+
const portal = portalConfig(root, config);
|
|
48
|
+
mkdirSync(site, { recursive: true });
|
|
49
|
+
copyFileSync(path.join(PAGES_DIR, 'dashboard.html'), path.join(site, 'index.html'));
|
|
50
|
+
writeFileSync(path.join(site, 'portal.json'), `${JSON.stringify(portal, null, 2)}\n`);
|
|
51
|
+
const noJekyll = path.join(site, '.nojekyll');
|
|
52
|
+
if (!existsSync(noJekyll))
|
|
53
|
+
writeFileSync(noJekyll, '');
|
|
54
|
+
const siteInfo = path.join(site, 'site.json');
|
|
55
|
+
if (!existsSync(siteInfo))
|
|
56
|
+
writeFileSync(siteInfo, `${JSON.stringify({ layoutVersion: SITE_LAYOUT_VERSION }, null, 2)}\n`);
|
|
57
|
+
console.log(`Dashboard: index.html and portal.json (${portal.runs.length} runs) -> ${path.relative(process.cwd(), site).split(path.sep).join('/') || '.'}/`);
|
|
58
|
+
}
|
|
59
|
+
/** Replaces the `target` folder with a copy of the `source` folder. */
|
|
60
|
+
export function replaceDir(source, target) {
|
|
61
|
+
rmSync(target, { recursive: true, force: true });
|
|
62
|
+
cpSync(source, target, { recursive: true });
|
|
63
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// The Test Cases pages: one page per scenario layer (UI, API) of the portal.
|
|
2
|
+
//
|
|
3
|
+
// For each layer in simpright.yml it writes <out dir>/<layer>/index.html (a copy of pages/test-cases.html) and
|
|
4
|
+
// <out dir>/<layer>/scenarios-data.js, which sets window.SCENARIO_CATALOG: the folder tree (area -> file -> scenario
|
|
5
|
+
// IDs), counts, and every scenario with its steps, raw YAML and the line of its test in the spec, plus the portal's
|
|
6
|
+
// brand (simpright.yml portal) and the workflow of the layer's area-picker run (Run on GitHub). The data is a script,
|
|
7
|
+
// not JSON, so the page also opens straight from disk. build-pages builds them into the site as test-cases/<layer>/.
|
|
8
|
+
//
|
|
9
|
+
// It reads the files as they are; run `simpright-scenarios validate` first.
|
|
10
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { branchName, commitSha, projectPath, repositoryUrl } from 'simpright/config';
|
|
13
|
+
import { runWorkflows } from 'simpright/workflows';
|
|
14
|
+
import { isMap, isSeq, parse, parseDocument } from 'yaml';
|
|
15
|
+
import { buildTime, PAGES_DIR, portalBrand } from './site.js';
|
|
16
|
+
const METHOD_ORDER = ['GET', 'QUERY', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
17
|
+
const ENDPOINT = /\b(GET|POST|PUT|PATCH|DELETE|QUERY) (\/[^\s,.;:)"']*)/g;
|
|
18
|
+
const toPosix = (file) => file.split(path.sep).join('/');
|
|
19
|
+
const titleCase = (name) => name.replace(/-/g, ' ').replace(/^\w/, (c) => c.toUpperCase());
|
|
20
|
+
/**
|
|
21
|
+
* An API file's endpoint, such as "GET /products/{productId}/related": the endpoint its steps name
|
|
22
|
+
* whose method and path give the file name (a path parameter {productId} becomes by-product-id).
|
|
23
|
+
* Falls back to the file name when no step names it.
|
|
24
|
+
*/
|
|
25
|
+
function endpointOf(fileName, steps) {
|
|
26
|
+
for (const step of steps) {
|
|
27
|
+
for (const [, method = '', urlPath = ''] of step.matchAll(ENDPOINT)) {
|
|
28
|
+
const kebab = urlPath
|
|
29
|
+
.split('/')
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((part) => {
|
|
32
|
+
const param = /^\{(\w+)\}$/.exec(part);
|
|
33
|
+
return param?.[1] ? `by-${param[1].replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()}` : part;
|
|
34
|
+
})
|
|
35
|
+
.join('-');
|
|
36
|
+
if (`${method.toLowerCase()}-${kebab}` === fileName)
|
|
37
|
+
return `${method} ${urlPath}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Files sort by label; endpoints by path, then method, so an endpoint's methods sit together. */
|
|
43
|
+
function sortKey(label, endpoint) {
|
|
44
|
+
if (!endpoint)
|
|
45
|
+
return label.toLowerCase();
|
|
46
|
+
const [method = '', urlPath = ''] = endpoint.split(' ');
|
|
47
|
+
return `${urlPath} ${METHOD_ORDER.indexOf(method)}`;
|
|
48
|
+
}
|
|
49
|
+
/** Each scenario's own YAML, as written in the file (the list item, dedented). */
|
|
50
|
+
function rawScenarios(source) {
|
|
51
|
+
const doc = parseDocument(source);
|
|
52
|
+
const list = doc.get('scenarios');
|
|
53
|
+
if (!isSeq(list))
|
|
54
|
+
return [];
|
|
55
|
+
return list.items.map((item) => {
|
|
56
|
+
if (!isMap(item) || !item.range)
|
|
57
|
+
return '';
|
|
58
|
+
const start = source.lastIndexOf('\n', item.range[0]) + 1;
|
|
59
|
+
const lines = source.slice(start, item.range[1]).replace(/\r/g, '').trimEnd().split('\n');
|
|
60
|
+
const indent = /^\s*/.exec((lines[0] ?? '').replace(/-\s/, ''))?.[0].length ?? 0;
|
|
61
|
+
return lines.map((line, i) => (i === 0 ? line.replace(/^\s*/, '') : line.slice(indent))).join('\n');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Builds the Test Cases pages of the project in `root` into `outDir`/<layer>/. */
|
|
65
|
+
export function buildTestCases(root, config, outDir) {
|
|
66
|
+
const read = (file) => readFileSync(path.join(root, file), 'utf8');
|
|
67
|
+
/** The 1-based line of the test titled '<id>: ...' in a spec, if the spec exists. */
|
|
68
|
+
const specLine = (spec, id) => {
|
|
69
|
+
if (!spec || !existsSync(path.join(root, spec)))
|
|
70
|
+
return undefined;
|
|
71
|
+
const lines = read(spec).split('\n');
|
|
72
|
+
const index = lines.findIndex((line) => new RegExp(`['"\`]${id}: `).test(line));
|
|
73
|
+
return index >= 0 ? index + 1 : undefined;
|
|
74
|
+
};
|
|
75
|
+
const scenariosDir = config.paths.scenarios;
|
|
76
|
+
const generatedAt = buildTime();
|
|
77
|
+
const sha = commitSha(root);
|
|
78
|
+
const repoUrl = repositoryUrl(root);
|
|
79
|
+
const branch = branchName(config);
|
|
80
|
+
const brand = config.portal ? portalBrand(config.portal) : undefined;
|
|
81
|
+
// Run on GitHub opens the workflow of the layer's manual run with an area picker.
|
|
82
|
+
const runFiles = runWorkflows(root);
|
|
83
|
+
const pickerWorkflows = Object.fromEntries((config.runs ?? []).filter((run) => run.areaPicker).map((run) => [run.project, runFiles.get(run.id)]));
|
|
84
|
+
for (const layer of Object.keys(config.ids.layers)) {
|
|
85
|
+
const layerDir = path.join(root, scenariosDir, layer);
|
|
86
|
+
const areas = existsSync(layerDir)
|
|
87
|
+
? readdirSync(layerDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort()
|
|
88
|
+
: [];
|
|
89
|
+
const tree = [];
|
|
90
|
+
const scenarios = [];
|
|
91
|
+
for (const area of areas) {
|
|
92
|
+
const files = readdirSync(path.join(layerDir, area))
|
|
93
|
+
.filter((f) => f.endsWith('.yml'))
|
|
94
|
+
.map((fileName) => {
|
|
95
|
+
const file = toPosix(path.join(scenariosDir, layer, area, fileName));
|
|
96
|
+
const source = read(file);
|
|
97
|
+
const data = parse(source);
|
|
98
|
+
const name = fileName.replace(/\.yml$/, '');
|
|
99
|
+
const endpoint = layer === 'api' ? endpointOf(name, data.scenarios.flatMap((s) => s.steps)) : undefined;
|
|
100
|
+
const label = layer === 'api' ? (endpoint ?? name) : titleCase(name);
|
|
101
|
+
return { file, source, data, name, label, sortKey: sortKey(label, endpoint) };
|
|
102
|
+
})
|
|
103
|
+
// The page walks the scenarios in this order (arrow keys), so it is also the tree's order.
|
|
104
|
+
.sort((a, b) => (a.sortKey < b.sortKey ? -1 : a.sortKey > b.sortKey ? 1 : 0));
|
|
105
|
+
const fileNodes = [];
|
|
106
|
+
for (const { file, source, data, name, label } of files) {
|
|
107
|
+
const raws = rawScenarios(source);
|
|
108
|
+
fileNodes.push({ file, name, label, suite: data.suite, tags: data.tags, ids: data.scenarios.map((s) => s.id) });
|
|
109
|
+
data.scenarios.forEach((scenario, i) => {
|
|
110
|
+
scenarios.push({
|
|
111
|
+
...scenario,
|
|
112
|
+
ref: scenario.ref === undefined ? [] : [scenario.ref].flat(),
|
|
113
|
+
specLine: specLine(scenario.automatedIn, scenario.id),
|
|
114
|
+
area,
|
|
115
|
+
areaLabel: titleCase(area),
|
|
116
|
+
file,
|
|
117
|
+
fileLabel: label,
|
|
118
|
+
suite: data.suite,
|
|
119
|
+
tags: data.tags,
|
|
120
|
+
yaml: raws[i] ?? '',
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
tree.push({ area, label: titleCase(area), files: fileNodes });
|
|
125
|
+
}
|
|
126
|
+
const automated = scenarios.filter((s) => s.status === 'automated').length;
|
|
127
|
+
const catalog = {
|
|
128
|
+
layer,
|
|
129
|
+
title: `${layer.toUpperCase()} Test Cases`,
|
|
130
|
+
prefix: config.ids.layers[layer]?.prefix,
|
|
131
|
+
generatedAt,
|
|
132
|
+
commit: sha,
|
|
133
|
+
repoUrl,
|
|
134
|
+
branch,
|
|
135
|
+
// The project's folder in the repository: the pages' links to its files start with it.
|
|
136
|
+
projectPath: projectPath(root),
|
|
137
|
+
portal: brand,
|
|
138
|
+
workflowUrl: pickerWorkflows[layer] ? `${repoUrl}/actions/workflows/${pickerWorkflows[layer]}` : undefined,
|
|
139
|
+
stats: {
|
|
140
|
+
total: scenarios.length,
|
|
141
|
+
automated,
|
|
142
|
+
manual: scenarios.length - automated,
|
|
143
|
+
knownIssues: scenarios.filter((s) => s.knownIssue).length,
|
|
144
|
+
automatedPct: scenarios.length ? Math.round((automated / scenarios.length) * 100) : 0,
|
|
145
|
+
},
|
|
146
|
+
tree,
|
|
147
|
+
scenarios,
|
|
148
|
+
};
|
|
149
|
+
const target = path.join(outDir, layer);
|
|
150
|
+
mkdirSync(target, { recursive: true });
|
|
151
|
+
copyFileSync(path.join(PAGES_DIR, 'test-cases.html'), path.join(target, 'index.html'));
|
|
152
|
+
writeFileSync(path.join(target, 'scenarios-data.js'), `// Generated by @simpright/portal (build-test-cases); do not edit.\nwindow.SCENARIO_CATALOG = ${JSON.stringify(catalog, null, 1)};\n`);
|
|
153
|
+
console.log(`${catalog.title}: ${scenarios.length} scenarios (${automated} automated) -> ${toPosix(path.relative(root, target))}/`);
|
|
154
|
+
}
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpright/portal",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A static dashboard for Playwright runs: run history, trends and known issues, plus Test Cases and Bugs pages, published into any folder (GitHub Pages, or anywhere else).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"simpright",
|
|
7
|
+
"playwright",
|
|
8
|
+
"dashboard",
|
|
9
|
+
"test-report",
|
|
10
|
+
"github-pages"
|
|
11
|
+
],
|
|
5
12
|
"license": "MIT",
|
|
6
13
|
"author": "Andrii Zaitsev",
|
|
7
|
-
"homepage": "https://github.com/Zaytsman/SimpRightKit",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
14
|
+
"homepage": "https://github.com/Zaytsman/SimpRightKit/tree/main/packages/portal#readme",
|
|
15
|
+
"bugs": "https://github.com/Zaytsman/SimpRightKit/issues",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Zaytsman/SimpRightKit.git",
|
|
19
|
+
"directory": "packages/portal"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"simpright-portal": "dist/cli.js"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"pages",
|
|
37
|
+
"sample"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"simpright": "0.1.0",
|
|
44
|
+
"yaml": "^2.9.1"
|
|
45
|
+
}
|
|
10
46
|
}
|