@simpright/portal 0.0.0 → 0.2.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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -1
  3. package/dist/bugs.d.ts +3 -0
  4. package/dist/bugs.js +112 -0
  5. package/dist/build-pages.d.ts +3 -0
  6. package/dist/build-pages.js +28 -0
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.js +145 -0
  9. package/dist/preview.d.ts +13 -0
  10. package/dist/preview.js +85 -0
  11. package/dist/publish-run.d.ts +19 -0
  12. package/dist/publish-run.js +78 -0
  13. package/dist/run-summaries.d.ts +8 -0
  14. package/dist/run-summaries.js +91 -0
  15. package/dist/site.d.ts +34 -0
  16. package/dist/site.js +63 -0
  17. package/dist/test-cases.d.ts +3 -0
  18. package/dist/test-cases.js +155 -0
  19. package/package.json +41 -5
  20. package/pages/bugs.html +1240 -0
  21. package/pages/dashboard.html +1230 -0
  22. package/pages/test-cases.html +1287 -0
  23. package/sample/.nojekyll +0 -0
  24. package/sample/api-regression/run-1/index.html +10 -0
  25. package/sample/api-regression/run-1/run-summary.json +1 -0
  26. package/sample/api-regression/run-10/index.html +10 -0
  27. package/sample/api-regression/run-10/run-summary.json +1 -0
  28. package/sample/api-regression/run-2/index.html +10 -0
  29. package/sample/api-regression/run-2/run-summary.json +1 -0
  30. package/sample/api-regression/run-3/index.html +10 -0
  31. package/sample/api-regression/run-3/run-summary.json +1 -0
  32. package/sample/api-regression/run-4/index.html +10 -0
  33. package/sample/api-regression/run-4/run-summary.json +1 -0
  34. package/sample/api-regression/run-5/index.html +10 -0
  35. package/sample/api-regression/run-5/run-summary.json +1 -0
  36. package/sample/api-regression/run-6/index.html +10 -0
  37. package/sample/api-regression/run-6/run-summary.json +1 -0
  38. package/sample/api-regression/run-7/index.html +10 -0
  39. package/sample/api-regression/run-7/run-summary.json +1 -0
  40. package/sample/api-regression/run-8/index.html +10 -0
  41. package/sample/api-regression/run-8/run-summary.json +1 -0
  42. package/sample/api-regression/run-9/index.html +10 -0
  43. package/sample/api-regression/run-9/run-summary.json +1 -0
  44. package/sample/api-regression-history.json +1 -0
  45. package/sample/api-regression-manifest.json +12 -0
  46. package/sample/bugs/bugs-data.js +130 -0
  47. package/sample/custom-ui/run-1/index.html +10 -0
  48. package/sample/custom-ui/run-1/run-summary.json +1 -0
  49. package/sample/custom-ui/run-2/index.html +10 -0
  50. package/sample/custom-ui/run-2/run-summary.json +1 -0
  51. package/sample/custom-ui-history.json +1 -0
  52. package/sample/custom-ui-manifest.json +4 -0
  53. package/sample/latest/api-regression/index.html +10 -0
  54. package/sample/latest/api-regression/run-summary.json +1 -0
  55. package/sample/latest/custom-ui/index.html +10 -0
  56. package/sample/latest/custom-ui/run-summary.json +1 -0
  57. package/sample/latest/smoke/index.html +10 -0
  58. package/sample/latest/smoke/run-summary.json +1 -0
  59. package/sample/latest/ui-regression/index.html +10 -0
  60. package/sample/latest/ui-regression/run-summary.json +1 -0
  61. package/sample/portal.json +37 -0
  62. package/sample/site.json +3 -0
  63. package/sample/smoke/run-1/index.html +10 -0
  64. package/sample/smoke/run-1/run-summary.json +1 -0
  65. package/sample/smoke/run-2/index.html +10 -0
  66. package/sample/smoke/run-2/run-summary.json +1 -0
  67. package/sample/smoke/run-3/index.html +10 -0
  68. package/sample/smoke/run-3/run-summary.json +1 -0
  69. package/sample/smoke/run-4/index.html +10 -0
  70. package/sample/smoke/run-4/run-summary.json +1 -0
  71. package/sample/smoke-history.json +1 -0
  72. package/sample/smoke-manifest.json +6 -0
  73. package/sample/test-cases/api/scenarios-data.js +169 -0
  74. package/sample/test-cases/ui/scenarios-data.js +191 -0
  75. package/sample/ui-regression/run-1/index.html +10 -0
  76. package/sample/ui-regression/run-1/run-summary.json +1 -0
  77. package/sample/ui-regression/run-10/index.html +10 -0
  78. package/sample/ui-regression/run-10/run-summary.json +1 -0
  79. package/sample/ui-regression/run-2/index.html +10 -0
  80. package/sample/ui-regression/run-2/run-summary.json +1 -0
  81. package/sample/ui-regression/run-3/index.html +10 -0
  82. package/sample/ui-regression/run-3/run-summary.json +1 -0
  83. package/sample/ui-regression/run-4/index.html +10 -0
  84. package/sample/ui-regression/run-4/run-summary.json +1 -0
  85. package/sample/ui-regression/run-5/index.html +10 -0
  86. package/sample/ui-regression/run-5/run-summary.json +1 -0
  87. package/sample/ui-regression/run-6/index.html +10 -0
  88. package/sample/ui-regression/run-6/run-summary.json +1 -0
  89. package/sample/ui-regression/run-7/index.html +10 -0
  90. package/sample/ui-regression/run-7/run-summary.json +1 -0
  91. package/sample/ui-regression/run-8/index.html +10 -0
  92. package/sample/ui-regression/run-8/run-summary.json +1 -0
  93. package/sample/ui-regression/run-9/index.html +10 -0
  94. package/sample/ui-regression/run-9/run-summary.json +1 -0
  95. package/sample/ui-regression-history.json +1 -0
  96. package/sample/ui-regression-manifest.json +12 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrii Zaitsev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
1
  # @simpright/portal
2
2
 
3
- A placeholder: the first release of this package is 0.1.0. See the [SimpRight Kit](https://github.com/Zaytsman/SimpRightKit).
3
+ A static dashboard for Playwright runs, part of the [SimpRight Kit](https://github.com/Zaytsman/SimpRightKit). It shows each run family's latest report and history, a health card and trend per layer, the known issues, and Test Cases and Bugs pages built from the project's scenarios and bugs. It writes a plain folder, so you can publish it anywhere. On GitHub, publish it as the `gh-pages` branch.
4
+
5
+ ```bash
6
+ npx @simpright/portal preview --sample # the portal with a made-up project's data, on http://127.0.0.1:4173/
7
+
8
+ npm install --save-dev @simpright/portal
9
+ npx simpright-portal publish-run --site .gh-pages --run <id> --number <N>
10
+ npx simpright-portal build-pages --site .gh-pages
11
+ npx simpright-portal preview --site .gh-pages
12
+ ```
13
+
14
+ See the [demo portal](https://zaytsman.github.io/SimpRightKit/) (the sample's data) and SimpRight's [Automation Portal](https://zaytsman.github.io/SimpRight/) (a real project's).
15
+
16
+ ## Commands
17
+
18
+ - `publish-run --site <dir> --run <id> --number <N> [--keep <N>] [--latest-coverage] [--report <dir>] [--results <file>] [--coverage <dir>]`: copies a run's HTML report into `<id>/run-<N>/` and writes its small summary from the JSON report. It keeps the newest runs (default: the run's `keep`, else 10) and refreshes the dashboard. The run's outputs default to `playwright-report/`, `test-results/results.json` and `test-results/api-coverage/`. `--latest-coverage` (default: the run's `publishCoverage`) also publishes the run's API coverage report as the latest.
19
+ - `build-pages --site <dir>`: the Test Cases pages (one per layer), the Bugs page and the dashboard.
20
+ - `build-test-cases [<out dir>]`, `build-bugs [<out dir>]`, `build-config [<out file>]`: one page, or the dashboard's `portal.json`, on its own.
21
+ - `preview [--site <dir> | --sample] [--port <N>]`: serves a site on `http://127.0.0.1:<port>/` (default 4173), only to this machine. `--sample` serves the sample site this package ships, with its own pages, and needs no project.
22
+
23
+ The commands but `preview` take `--root <dir>`, the project's folder (default: the nearest folder up with `simpright.yml`). Set `SOURCE_DATE_EPOCH` for a reproducible build time.
24
+
25
+ ## What it reads
26
+
27
+ - `simpright.yml`: `portal` (title, accent, tagline, description, health thresholds) and `runs` (one report family each: `id`, `label`, `note`, `trend`, `keep`, `publishCoverage`); `parts.wiki` (a link to the repository's wiki); for the pages, `paths.scenarios`, `paths.bugs`, `ids`, and the workflow of each layer's `areaPicker` run (a "Run on GitHub" button). The dashboard shows a status card and trends for each layer with a `trend` run, and names only those layers.
28
+ - The repository the pages link to: `GITHUB_REPOSITORY` on GitHub Actions, else the `origin` remote. Links to the project's files start with its folder in the repository (git's, or `SIMPRIGHT_PROJECT_PATH`), so a project in a subfolder of a monorepo links right too.
29
+ - The JSON reporter's output for the stats and known issues: a test annotation that contains `Known issue` (`test.fail(true, 'Known issue BUG-001: ...')`) lists the test under Known Issues, and the bug ID links to the Bugs page.
30
+
31
+ ## The site
32
+
33
+ ```text
34
+ index.html, portal.json the dashboard and what it shows (rewritten on every publish)
35
+ site.json the site's layout version
36
+ <id>-manifest.json the kept runs of a family, newest first
37
+ <id>-history.json their stats and the newest run's known issues
38
+ <id>/run-<N>/ a run's HTML report, run-summary.json and API coverage
39
+ latest/<id>/ a copy of the family's newest run
40
+ latest/api-coverage/ the newest coverage report of the family that publishes it
41
+ test-cases/<layer>/ the Test Cases pages
42
+ bugs/ the Bugs page
43
+ ```
44
+
45
+ A run's full `results.json` isn't published (an API regression's is about 8 MB): the pages read the small summaries.
46
+
47
+ ## License
48
+
49
+ [MIT](LICENSE)
package/dist/bugs.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { type Config } from 'simpright/config';
2
+ /** Builds the Bugs page of the project in `root` into `outDir`; does nothing when simpright.yml has no paths.bugs. */
3
+ export declare function buildBugs(root: string, config: Config, outDir: string): void;
package/dist/bugs.js ADDED
@@ -0,0 +1,112 @@
1
+ // The Bugs page of the portal, from the bug files and the scenarios that name them.
2
+ //
3
+ // It writes <out dir>/index.html (a copy of pages/bugs.html) and <out dir>/bugs-data.js, which sets
4
+ // window.BUG_CATALOG: every bug with its fields, raw YAML and the scenarios whose `bug` names it (with the line of
5
+ // their test in the spec), the portal's brand (simpright.yml portal), and where the latest results of each layer's
6
+ // regression (the run with that trend in simpright.yml runs) are published. The page reads those results itself (the
7
+ // small run-summary.json of each published run, src/run-summaries.ts), so a known-issue test that passes there is
8
+ // flagged for a re-check. The data is a script, not JSON, so the page also opens straight from disk. build-pages
9
+ // builds it into the site as bugs/.
10
+ //
11
+ // It reads the files as they are; run `simpright-scenarios validate` first.
12
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
13
+ import path from 'node:path';
14
+ import { branchName, commitSha, projectPath, repositoryUrl } from 'simpright/config';
15
+ import { parse } from 'yaml';
16
+ import { buildTime, PAGES_DIR, portalBrand } from './site.js';
17
+ const SEVERITY_ORDER = ['critical', 'major', 'minor', 'trivial'];
18
+ const toPosix = (file) => file.split(path.sep).join('/');
19
+ /** Builds the Bugs page of the project in `root` into `outDir`; does nothing when simpright.yml has no paths.bugs. */
20
+ export function buildBugs(root, config, outDir) {
21
+ const read = (file) => readFileSync(path.join(root, file), 'utf8');
22
+ /** Files under `dir` (relative to the project root, with forward slashes) that end with .yml. */
23
+ const ymlFiles = (dir) => {
24
+ if (!existsSync(path.join(root, dir)))
25
+ return [];
26
+ return readdirSync(path.join(root, dir), { recursive: true, encoding: 'utf8' })
27
+ .map((file) => `${dir}/${toPosix(file)}`)
28
+ .filter((file) => file.endsWith('.yml'))
29
+ .sort();
30
+ };
31
+ /** The 1-based line of the test titled '<id>: ...' in a spec, if the spec exists. */
32
+ const specLine = (spec, id) => {
33
+ if (!spec || !existsSync(path.join(root, spec)))
34
+ return undefined;
35
+ const lines = read(spec).split('\n');
36
+ const index = lines.findIndex((line) => new RegExp(`['"\`]${id}: `).test(line));
37
+ return index >= 0 ? index + 1 : undefined;
38
+ };
39
+ const bugsDir = config.paths.bugs;
40
+ const bugIds = config.ids.bugs;
41
+ if (!bugsDir || !bugIds) {
42
+ console.log('No paths.bugs in simpright.yml: no Bugs page to build.');
43
+ return;
44
+ }
45
+ // Scenario files are <scenarios>/<layer>/<area>/<name>.yml.
46
+ const linked = new Map();
47
+ for (const file of ymlFiles(config.paths.scenarios)) {
48
+ const [layer = '', area = ''] = file.slice(config.paths.scenarios.length + 1).split('/');
49
+ const scenarios = parse(read(file)).scenarios ?? [];
50
+ for (const scenario of scenarios) {
51
+ if (!scenario.bug)
52
+ continue;
53
+ linked.set(scenario.bug, [
54
+ ...(linked.get(scenario.bug) ?? []),
55
+ {
56
+ id: scenario.id,
57
+ name: scenario.name,
58
+ layer,
59
+ area,
60
+ file,
61
+ status: scenario.status,
62
+ automatedIn: scenario.automatedIn,
63
+ specLine: specLine(scenario.automatedIn, scenario.id),
64
+ knownIssue: scenario.knownIssue,
65
+ },
66
+ ]);
67
+ }
68
+ }
69
+ const bugs = ymlFiles(bugsDir)
70
+ .filter((file) => !file.slice(bugsDir.length + 1).includes('/'))
71
+ .map((file) => {
72
+ const source = read(file).replace(/\r/g, '');
73
+ const bug = parse(source);
74
+ return {
75
+ ...bug,
76
+ ref: bug.ref === undefined ? [] : [bug.ref].flat(),
77
+ file,
78
+ // The file without its schema comment line.
79
+ yaml: source.replace(/^#.*\n/, '').trimEnd(),
80
+ scenarios: linked.get(bug.id) ?? [],
81
+ };
82
+ })
83
+ // Open bugs first, then by severity, then by ID.
84
+ .sort((a, b) => Number(a.status !== 'open') - Number(b.status !== 'open') ||
85
+ SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) ||
86
+ a.id.localeCompare(b.id));
87
+ const count = (status) => bugs.filter((bug) => bug.status === status).length;
88
+ const catalog = {
89
+ title: 'Bugs',
90
+ prefix: bugIds.prefix,
91
+ generatedAt: buildTime(),
92
+ commit: commitSha(root),
93
+ repoUrl: repositoryUrl(root),
94
+ branch: branchName(config),
95
+ // The project's folder in the repository: the page's links to its files start with it.
96
+ projectPath: projectPath(root),
97
+ portal: config.portal ? portalBrand(config.portal) : undefined,
98
+ bugsDir,
99
+ layers: Object.fromEntries(Object.keys(config.ids.layers).map((layer) => [layer, layer.toUpperCase()])),
100
+ // Each layer's regression: the run whose trend it is, published by publish-run as latest/<id>/.
101
+ // Relative to the published page (bugs/index.html); missing ones (a local build) are skipped by the page.
102
+ regressions: (config.runs ?? [])
103
+ .filter((run) => run.trend && run.trend in config.ids.layers)
104
+ .map((run) => ({ layer: run.trend, label: run.label, results: `../latest/${run.id}/run-summary.json`, report: `../latest/${run.id}/` })),
105
+ stats: { total: bugs.length, open: count('open'), fixed: count('fixed'), wontFix: count('wont-fix') },
106
+ bugs,
107
+ };
108
+ mkdirSync(outDir, { recursive: true });
109
+ copyFileSync(path.join(PAGES_DIR, 'bugs.html'), path.join(outDir, 'index.html'));
110
+ writeFileSync(path.join(outDir, 'bugs-data.js'), `// Generated by @simpright/portal (build-bugs); do not edit.\nwindow.BUG_CATALOG = ${JSON.stringify(catalog, null, 1)};\n`);
111
+ console.log(`Bugs: ${bugs.length} bugs (${catalog.stats.open} open) -> ${toPosix(path.relative(root, outDir))}/`);
112
+ }
@@ -0,0 +1,3 @@
1
+ import type { Config } from 'simpright/config';
2
+ /** Builds the pages of the project in `root` into `site`; see the top of this file. */
3
+ export declare function buildPages(root: string, config: Config, siteDir: string): void;
@@ -0,0 +1,28 @@
1
+ // build-pages: builds the portal's pages into a site folder: the Test Cases pages (test-cases/<layer>/), the Bugs page
2
+ // (bugs/, when simpright.yml has paths.bugs) and the dashboard (index.html, portal.json). The rest of the site is the
3
+ // test runs' (publish-run). On CI a step runs it between the gh-pages checkout and the push, and a pull request's
4
+ // checks can run it to see that the pages still build; it runs wherever Node does.
5
+ //
6
+ // It replaces the whole test-cases/ and bugs/ folders, so a layer that no longer exists disappears too. It also
7
+ // builds the run summaries of report families that have none yet (src/run-summaries.ts), so a dashboard change
8
+ // published here finds its data before the next run.
9
+ import { rmSync } from 'node:fs';
10
+ import path from 'node:path';
11
+ import { buildBugs } from './bugs.js';
12
+ import { buildCoverageTotals, buildFamily, familiesWithoutHistory } from './run-summaries.js';
13
+ import { writeDashboard } from './site.js';
14
+ import { buildTestCases } from './test-cases.js';
15
+ /** Builds the pages of the project in `root` into `site`; see the top of this file. */
16
+ export function buildPages(root, config, siteDir) {
17
+ const site = path.resolve(siteDir);
18
+ for (const [folder, build] of [
19
+ ['test-cases', buildTestCases],
20
+ ['bugs', buildBugs],
21
+ ]) {
22
+ rmSync(path.join(site, folder), { recursive: true, force: true });
23
+ build(root, config, path.join(site, folder));
24
+ }
25
+ familiesWithoutHistory(site).forEach((family) => buildFamily(site, family));
26
+ buildCoverageTotals(site);
27
+ writeDashboard(root, config, site);
28
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ // The simpright-portal command: publishes test runs and builds the portal's pages into a site folder (publish-run,
3
+ // build-pages), or builds one page on its own. Exits with 0 when it's done, 1 on an error in the project, and 2 on a
4
+ // usage error.
5
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
6
+ import path from 'node:path';
7
+ import { parseArgs } from 'node:util';
8
+ import { ConfigError, projectRoot, readConfig, UsageError } from 'simpright/config';
9
+ import { buildBugs } from './bugs.js';
10
+ import { buildPages } from './build-pages.js';
11
+ import { DEFAULT_PORT, preview } from './preview.js';
12
+ import { publishRun } from './publish-run.js';
13
+ import { portalConfig } from './site.js';
14
+ import { buildTestCases } from './test-cases.js';
15
+ const USAGE = `usage: simpright-portal <command> [options] [--root <dir>]
16
+ publish-run --site <dir> --run <id> --number <N> [--keep <N>] [--latest-coverage]
17
+ [--report <dir>] [--results <file>] [--coverage <dir>]
18
+ publish a run's report (default playwright-report/, test-results/results.json and
19
+ test-results/api-coverage/) into the site as <id>/run-<N>/, keep the newest runs (default: the
20
+ run's keep, else 10) and refresh the dashboard
21
+ build-pages --site <dir>
22
+ build the Test Cases and Bugs pages and the dashboard into the site
23
+ build-test-cases [<out dir>] the Test Cases pages alone (default test-results/test-cases)
24
+ build-bugs [<out dir>] the Bugs page alone (default test-results/bugs)
25
+ build-config [<out file>] the dashboard's portal.json alone (default test-results/portal/portal.json)
26
+ preview [--site <dir> | --sample] [--port <N>]
27
+ serve a site on http://127.0.0.1:<port>/ (default 4173), or the sample site with this
28
+ package's pages (no project needed)
29
+ --root the project's folder (default: the nearest folder up with simpright.yml)`;
30
+ const ROOT_OPTION = { root: { type: 'string' } };
31
+ const version = () => JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
32
+ /** The command's options and positionals, parsed with its own option list (an unknown option is a usage error). */
33
+ function parse(args, options, maxPositionals) {
34
+ const parsed = parseArgs({ args, options: { ...options, ...ROOT_OPTION }, allowPositionals: true });
35
+ if (parsed.positionals.length > maxPositionals)
36
+ throw new UsageError(`Unexpected argument '${parsed.positionals[maxPositionals]}'.`);
37
+ const root = projectRoot(parsed.values.root);
38
+ return { values: parsed.values, positionals: parsed.positionals, root, config: readConfig(root) };
39
+ }
40
+ /** `preview`: no project needed, and it keeps running until it's stopped. */
41
+ async function startPreview(args) {
42
+ const { values } = parseArgs({ args, options: { site: { type: 'string' }, sample: { type: 'boolean' }, port: { type: 'string' } } });
43
+ if (Boolean(values.site) === Boolean(values.sample))
44
+ throw new UsageError('preview needs --site <dir> or --sample.');
45
+ const port = values.port === undefined ? DEFAULT_PORT : Number(values.port);
46
+ if (!Number.isInteger(port) || port < 0 || port > 65535)
47
+ throw new UsageError(`--port must be a port number, got '${values.port}'.`);
48
+ const server = await preview({ site: values.site, sample: values.sample, port });
49
+ const address = server.address();
50
+ const url = `http://127.0.0.1:${typeof address === 'object' && address ? address.port : port}/`;
51
+ console.log(`Serving ${values.sample ? 'the sample site' : path.resolve(values.site)} at ${url} (Ctrl+C to stop)`);
52
+ }
53
+ function main(argv) {
54
+ const [command, ...args] = argv;
55
+ if (command === 'preview')
56
+ return startPreview(args);
57
+ if (command === '--version' || command === '-v') {
58
+ console.log(version());
59
+ return 0;
60
+ }
61
+ if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
62
+ console.log(USAGE);
63
+ return command === undefined ? 2 : 0;
64
+ }
65
+ switch (command) {
66
+ case 'publish-run': {
67
+ const { values, root, config } = parse(args, {
68
+ site: { type: 'string' },
69
+ run: { type: 'string' },
70
+ number: { type: 'string' },
71
+ keep: { type: 'string' },
72
+ 'latest-coverage': { type: 'boolean' },
73
+ report: { type: 'string' },
74
+ results: { type: 'string' },
75
+ coverage: { type: 'string' },
76
+ }, 0);
77
+ const { site, run, number } = values;
78
+ if (!site || !run || !number)
79
+ throw new UsageError('--site, --run and --number are required.');
80
+ publishRun(root, config, {
81
+ site,
82
+ run,
83
+ number,
84
+ keep: values.keep,
85
+ latestCoverage: values['latest-coverage'],
86
+ report: values.report,
87
+ results: values.results,
88
+ coverage: values.coverage,
89
+ });
90
+ return 0;
91
+ }
92
+ case 'build-pages': {
93
+ const { values, root, config } = parse(args, { site: { type: 'string' } }, 0);
94
+ if (!values.site)
95
+ throw new UsageError('--site is required.');
96
+ buildPages(root, config, values.site);
97
+ return 0;
98
+ }
99
+ case 'build-test-cases': {
100
+ const { positionals, root, config } = parse(args, {}, 1);
101
+ buildTestCases(root, config, path.resolve(root, positionals[0] ?? 'test-results/test-cases'));
102
+ return 0;
103
+ }
104
+ case 'build-bugs': {
105
+ const { positionals, root, config } = parse(args, {}, 1);
106
+ buildBugs(root, config, path.resolve(root, positionals[0] ?? 'test-results/bugs'));
107
+ return 0;
108
+ }
109
+ case 'build-config': {
110
+ const { positionals, root, config } = parse(args, {}, 1);
111
+ const outFile = path.resolve(root, positionals[0] ?? 'test-results/portal/portal.json');
112
+ const portal = portalConfig(root, config);
113
+ mkdirSync(path.dirname(outFile), { recursive: true });
114
+ writeFileSync(outFile, `${JSON.stringify(portal, null, 2)}\n`);
115
+ console.log(`Portal: ${portal.runs.length} runs -> ${path.relative(root, outFile).split(path.sep).join('/')}`);
116
+ return 0;
117
+ }
118
+ default:
119
+ throw new UsageError(`Unknown command '${command}'.`);
120
+ }
121
+ }
122
+ try {
123
+ const result = await main(process.argv.slice(2));
124
+ if (typeof result === 'number')
125
+ process.exitCode = result;
126
+ }
127
+ catch (error) {
128
+ if (error.code === 'EADDRINUSE') {
129
+ console.error(`${error.message}: another program uses the port; pick another with --port.`);
130
+ process.exitCode = 1;
131
+ }
132
+ else if (error instanceof ConfigError) {
133
+ console.error(`simpright.yml isn't valid (simpright doctor checks it):`);
134
+ for (const problem of error.problems)
135
+ console.error(` - ${problem}`);
136
+ process.exitCode = 1;
137
+ }
138
+ else if (error instanceof UsageError || error.code?.startsWith('ERR_PARSE_ARGS')) {
139
+ console.error(`${error.message}\n${USAGE}`);
140
+ process.exitCode = 2;
141
+ }
142
+ else {
143
+ throw error;
144
+ }
145
+ }
@@ -0,0 +1,13 @@
1
+ import { type Server } from 'node:http';
2
+ /** The sample site's data (no pages): built from the kit's sample project by its scripts/sample-site.ts. */
3
+ export declare const SAMPLE_DIR: string;
4
+ export declare const DEFAULT_PORT = 4173;
5
+ export interface PreviewOptions {
6
+ /** The site folder to serve; left out with `sample`. */
7
+ site?: string;
8
+ /** Serve the sample site with this package's pages. */
9
+ sample?: boolean;
10
+ port?: number;
11
+ }
12
+ /** Starts the preview server; resolves once it listens. */
13
+ export declare function preview(options: PreviewOptions): Promise<Server>;
@@ -0,0 +1,85 @@
1
+ // preview: serves a portal site on this machine (127.0.0.1 only), to look at a locally published site before it goes
2
+ // out, or (--sample) the sample site this package ships, before there's a site of your own. The sample has the data of
3
+ // a made-up project; its pages are this package's, so the preview shows the current pages with the sample's data.
4
+ import { createReadStream, existsSync, statSync } from 'node:fs';
5
+ import { createServer } from 'node:http';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { PAGES_DIR } from './site.js';
9
+ /** The sample site's data (no pages): built from the kit's sample project by its scripts/sample-site.ts. */
10
+ export const SAMPLE_DIR = fileURLToPath(new URL('../sample/', import.meta.url));
11
+ export const DEFAULT_PORT = 4173;
12
+ const CONTENT_TYPES = {
13
+ '.html': 'text/html; charset=utf-8',
14
+ '.js': 'text/javascript; charset=utf-8',
15
+ '.json': 'application/json; charset=utf-8',
16
+ '.css': 'text/css; charset=utf-8',
17
+ '.svg': 'image/svg+xml',
18
+ '.png': 'image/png',
19
+ '.jpg': 'image/jpeg',
20
+ '.webp': 'image/webp',
21
+ '.txt': 'text/plain; charset=utf-8',
22
+ '.md': 'text/plain; charset=utf-8',
23
+ '.zip': 'application/zip',
24
+ };
25
+ /** The sample's pages: the URL of each one in a site, and the file of this package that is that page. */
26
+ function samplePage(urlPath) {
27
+ if (urlPath === '/index.html')
28
+ return path.join(PAGES_DIR, 'dashboard.html');
29
+ if (/^\/test-cases\/[^/]+\/index\.html$/.test(urlPath))
30
+ return path.join(PAGES_DIR, 'test-cases.html');
31
+ if (urlPath === '/bugs/index.html')
32
+ return path.join(PAGES_DIR, 'bugs.html');
33
+ return undefined;
34
+ }
35
+ /** Starts the preview server; resolves once it listens. */
36
+ export function preview(options) {
37
+ const root = path.resolve(options.sample ? SAMPLE_DIR : (options.site ?? '.'));
38
+ if (!existsSync(root) || !statSync(root).isDirectory())
39
+ throw new Error(`No site folder at ${root}.`);
40
+ const server = createServer((request, response) => {
41
+ if (request.method !== 'GET' && request.method !== 'HEAD') {
42
+ response.writeHead(405, { allow: 'GET, HEAD' }).end();
43
+ return;
44
+ }
45
+ let urlPath;
46
+ try {
47
+ urlPath = decodeURIComponent(new URL(request.url ?? '/', 'http://localhost').pathname);
48
+ }
49
+ catch {
50
+ response.writeHead(400).end();
51
+ return;
52
+ }
53
+ const file = path.join(root, urlPath);
54
+ // Nothing outside the site folder.
55
+ if (file !== root && !file.startsWith(root + path.sep)) {
56
+ response.writeHead(403).end();
57
+ return;
58
+ }
59
+ // A folder: its index.html, with a trailing slash so the page's relative links resolve inside it.
60
+ const isFolder = existsSync(file) && statSync(file).isDirectory();
61
+ if (isFolder && !urlPath.endsWith('/')) {
62
+ response.writeHead(301, { location: `${urlPath}/` }).end();
63
+ return;
64
+ }
65
+ const pagePath = isFolder || urlPath.endsWith('/') ? `${urlPath.replace(/\/$/, '')}/index.html` : urlPath;
66
+ const target = (options.sample ? samplePage(pagePath) : undefined) ?? path.join(root, pagePath);
67
+ if (!existsSync(target) || !statSync(target).isFile()) {
68
+ response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' }).end(`Not found: ${urlPath}\n`);
69
+ return;
70
+ }
71
+ response.writeHead(200, {
72
+ 'content-type': CONTENT_TYPES[path.extname(target).toLowerCase()] ?? 'application/octet-stream',
73
+ 'content-length': statSync(target).size,
74
+ 'cache-control': 'no-store',
75
+ });
76
+ if (request.method === 'HEAD')
77
+ response.end();
78
+ else
79
+ createReadStream(target).pipe(response);
80
+ });
81
+ return new Promise((resolve, reject) => {
82
+ server.once('error', reject);
83
+ server.listen(options.port ?? DEFAULT_PORT, '127.0.0.1', () => resolve(server));
84
+ });
85
+ }
@@ -0,0 +1,19 @@
1
+ import { type Config } from 'simpright/config';
2
+ export interface PublishRunOptions {
3
+ /** The site folder. */
4
+ site: string;
5
+ /** The run's id in simpright.yml runs: its report family. */
6
+ run: string;
7
+ /** The run's number (GITHUB_RUN_NUMBER on CI): the report goes in <id>/run-<N>/. */
8
+ number: string;
9
+ /** How many runs of the family stay on the site (default: the run's keep, else 10). */
10
+ keep?: string;
11
+ /** Also publish the newest run's API coverage as latest/api-coverage/ (default: the run's publishCoverage). */
12
+ latestCoverage?: boolean;
13
+ /** The run's outputs, relative to the project root. */
14
+ report?: string;
15
+ results?: string;
16
+ coverage?: string;
17
+ }
18
+ /** Publishes the run's outputs from the project in `root` into the site; see the top of this file. */
19
+ export declare function publishRun(root: string, config: Config, options: PublishRunOptions): void;
@@ -0,0 +1,78 @@
1
+ // publish-run: publishes a test run's report into a portal site folder: the HTML report, its API coverage, the small
2
+ // files the portal reads and the dashboard. On CI a step runs it between the gh-pages checkout and the push; it runs
3
+ // wherever Node does, so a site can also be built locally, in any folder.
4
+ //
5
+ // It reads the run's Playwright HTML report (default playwright-report/), its JSON report (test-results/results.json)
6
+ // and its API coverage (test-results/api-coverage/), relative to the project root.
7
+ // Site layout:
8
+ // index.html, portal.json the dashboard and what it shows (src/site.ts, on every publish)
9
+ // site.json the layout version (written once)
10
+ // <id>-manifest.json the kept runs of the family, newest first; older runs are deleted
11
+ // <id>-history.json every kept run's stats + the newest run's known issues (read by the dashboard)
12
+ // <id>/run-<N>/ HTML report + run-summary.json (+ api-coverage/) of run N; publishing the same
13
+ // number again (a re-run of the workflow) replaces it
14
+ // latest/<id>/ a copy of the newest kept run
15
+ // latest/api-coverage/ the newest coverage report of the family that publishes it (+ totals.json)
16
+ // The run summaries, the history and totals.json come from src/run-summaries.ts. The run's full results.json is
17
+ // only their source: an API regression's is about 8 MB, so it isn't published (it stays in the run's artifact).
18
+ import { copyFileSync, cpSync, existsSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
19
+ import path from 'node:path';
20
+ import { UsageError } from 'simpright/config';
21
+ import { buildCoverageTotals, buildFamily, RUN_FOLDER } from './run-summaries.js';
22
+ import { replaceDir, writeDashboard } from './site.js';
23
+ const DEFAULT_KEEP = 10;
24
+ const WHOLE_NUMBER = /^[1-9]\d*$/;
25
+ /** Publishes the run's outputs from the project in `root` into the site; see the top of this file. */
26
+ export function publishRun(root, config, options) {
27
+ const run = config.runs?.find(({ id }) => id === options.run);
28
+ if (!run)
29
+ throw new UsageError(`Unknown run '${options.run}': simpright.yml's runs have no such id.`);
30
+ if (!WHOLE_NUMBER.test(options.number))
31
+ throw new UsageError(`--number must be a positive whole number, got '${options.number}'.`);
32
+ const keep = options.keep ?? String(run.keep ?? DEFAULT_KEEP);
33
+ if (!WHOLE_NUMBER.test(keep))
34
+ throw new UsageError(`--keep must be a positive whole number, got '${keep}'.`);
35
+ const latestCoverage = options.latestCoverage ?? run.publishCoverage ?? false;
36
+ const report = path.resolve(root, options.report ?? 'playwright-report');
37
+ const results = path.resolve(root, options.results ?? 'test-results/results.json');
38
+ const coverage = path.resolve(root, options.coverage ?? 'test-results/api-coverage');
39
+ if (!existsSync(report)) {
40
+ console.log(`No ${path.relative(root, report).split(path.sep).join('/')}/ found; nothing to publish.`);
41
+ return;
42
+ }
43
+ const site = path.resolve(options.site);
44
+ const familyDir = path.join(site, run.id);
45
+ const thisRun = `run-${options.number}`;
46
+ const runNumber = (folder) => Number(folder.slice('run-'.length));
47
+ // This run's report, coverage and results (the source of its run-summary.json, removed below).
48
+ replaceDir(report, path.join(familyDir, thisRun));
49
+ if (existsSync(results))
50
+ copyFileSync(results, path.join(familyDir, thisRun, 'results.json'));
51
+ if (existsSync(coverage))
52
+ cpSync(coverage, path.join(familyDir, thisRun, 'api-coverage'), { recursive: true });
53
+ // Keep only the newest runs and list them in the manifest.
54
+ const runs = readdirSync(familyDir, { withFileTypes: true })
55
+ .filter((entry) => entry.isDirectory() && RUN_FOLDER.test(entry.name))
56
+ .map((entry) => entry.name)
57
+ .sort((a, b) => runNumber(b) - runNumber(a));
58
+ const kept = runs.slice(0, Number(keep));
59
+ for (const old of runs.slice(kept.length))
60
+ rmSync(path.join(familyDir, old), { recursive: true, force: true });
61
+ writeFileSync(path.join(site, `${run.id}-manifest.json`), `${JSON.stringify(kept, null, 2)}\n`);
62
+ console.log(`Runs kept for ${run.id}: ${kept.length}`);
63
+ if (!kept.includes(thisRun))
64
+ console.log(`${thisRun} is older than the ${keep} newest runs, so it isn't kept.`);
65
+ buildFamily(site, run.id);
66
+ // Every run with results now has its run-summary.json, so drop the full results.json (also from runs published
67
+ // before the summaries existed).
68
+ for (const folder of kept)
69
+ rmSync(path.join(familyDir, folder, 'results.json'), { force: true });
70
+ // The latest copies come from the newest kept run, which is this one unless an older run was published again.
71
+ const newest = path.join(familyDir, kept[0]);
72
+ replaceDir(newest, path.join(site, 'latest', run.id));
73
+ if (latestCoverage && existsSync(path.join(newest, 'api-coverage'))) {
74
+ replaceDir(path.join(newest, 'api-coverage'), path.join(site, 'latest', 'api-coverage'));
75
+ }
76
+ buildCoverageTotals(site);
77
+ writeDashboard(root, config, site);
78
+ }
@@ -0,0 +1,8 @@
1
+ /** A run's folder in its family's folder: run-<the workflow's run number>. */
2
+ export declare const RUN_FOLDER: RegExp;
3
+ /** The family's run summaries, the newest one's copy in latest/<family>/ and <family>-history.json, for the runs in <family>-manifest.json. */
4
+ export declare function buildFamily(site: string, family: string): void;
5
+ /** The report families that have a manifest but no history yet. */
6
+ export declare function familiesWithoutHistory(site: string): string[];
7
+ /** latest/api-coverage/totals.json: only the scalar totals (overallCoveragePct, coveredEndpoints, ...); the per-endpoint detail stays in summary.json. */
8
+ export declare function buildCoverageTotals(site: string): void;