Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Those comparisons, and the kit's own build, which carries the documentation onto

`npm test` runs every test past the others' failures: the nativeElement assertions check, the browser APIs check, the OnPush strategies check, the poll and test limits check, the part glyphs check, on Linux x64 only the Kit bundles, the Kit copies, the Kit manifest and Angular's newest, the kit's Node.js tests, `src/noldova.ui.components.angular/tests/node/*.test.ts`, with `node --test`, of the symbols entry, the stylesheets that load the symbol font, the browser APIs check and the stuck test reporter, which no browser loads, and the kit's Angular specs, which must each report a result, with no test identity, the spec file and the titles of its suites and test, repeated, then, on Linux only, builds the docs site and tests it, as `npm run docs:build` and `npm run docs:test` do, as the static site it serves is the same on every platform.
With `NOLDOVA_SEPARATE_TEST=docs`, as the CI targets' tests set it, `npm test` leaves the docs site out, and the CI run's "Separate test" job checks it once, with `npm run build` and `npm run test:docs`.
The kit's Angular specs run in two runs of Angular's test builder, each in a browser of its own: first every test but those in a `describe(LayoutTraceFixture.suite, ...)`, then, from the spec files that hold one, only those. A layout trace records every tab of its browser, so in the first browser, under the whole suite, one could take over 10 seconds to end and keep another spec's trace from starting ([#198](https://github.com/noldova-com/ui-components/issues/198)); in the second only the tracing tests run. The spec files that run alone, as [Tests that run alone](#tests-that-run-alone) lists, take a third run of their own, with the builder's `isolate` option on, and the first two leave them out. Every run uses the Angular `part` configuration, and the script adds up their coverage as `npm run test:merge` does below, gating it on a whole run. The suite's title is in `src/noldova.ui.components.angular/tests/fixtures/layout-trace-suite.ts`, which the fixture and the script both read. After the runs, the script fails unless each test in any run's report passed or failed in exactly one of them, and each run after the first ran at least one test, so a traced test that both filters skip, or that both run, fails the run. Each run sets `DEBUG` to `vitest:browser:playwright,vitest:browser:api`, added to any `DEBUG` already set, so its log holds the Playwright provider's few lines on each browser session, the last of which means the page's loading began, and the browser API's on each session's orchestrator socket: its connects, its disconnects, a reconnect refused because its session closed, and pings it stopped answering; the script leaves the browser API's line on each command a test runs out of the log. When a session fails to connect within Vitest's connect timeout, on either output, the script names the browser's last stage, and each session's last provider stage and what its orchestrator did, from those lines ([#143](https://github.com/noldova-com/ui-components/issues/143)).
The kit's Angular specs run in two runs of Angular's test builder, each in a browser of its own: first every test but those in a `describe(LayoutTraceFixture.suite, ...)`, then, from the spec files that hold one, only those. A layout trace records every tab of its browser, so in the first browser, under the whole suite, one could take over 10 seconds to end and keep another spec's trace from starting ([#198](https://github.com/noldova-com/ui-components/issues/198)); in the second only the tracing tests run. The spec files that run alone, as [Tests that run alone](#tests-that-run-alone) lists, take a third run of their own, with the builder's `isolate` option on, and the first two leave them out. Every run uses the Angular `part` configuration, and the script adds up their coverage as `npm run test:merge` does below, gating it on a whole run. The suite's title is in `src/noldova.ui.components.angular/tests/fixtures/layout-trace-suite.ts`, which the fixture and the script both read. After the runs, the script fails unless each test in any run's report passed or failed in exactly one of them, and each run after the first ran at least one test, so a traced test that both filters skip, or that both run, fails the run. Each run, and the docs site's run too through the same `BrowserSessionStages.runAsync`, sets `DEBUG` to `vitest:browser:playwright,vitest:browser:api`, added to any `DEBUG` already set, so its log holds the Playwright provider's few lines on each browser session, the last of which means the page's loading began, and the browser API's on each session's orchestrator socket: its connects, its disconnects, a reconnect refused because its session closed, and pings it stopped answering; the script leaves the browser API's line on each command a test runs out of the log. When a session fails to connect within Vitest's connect timeout, on either output, the script names the browser's last stage, and each session's last provider stage and what its orchestrator did, from those lines ([#143](https://github.com/noldova-com/ui-components/issues/143)).
Vitest's own test and hook limits are timers in the browser page, which can't fire while the page doesn't answer, and the page sends its tests' progress from a timer too, so a stopped page held the docs site's run silent until the job's limit ([#270](https://github.com/noldova-com/ui-components/issues/270)). So each of the kit's runs and the docs site's run also report to `src/noldova.ui.components.angular/scripts/angular/stuck-test-reporter.ts`, in Vitest's main process, whose shape and limits come from Noldova's Git repository's, which the kit's `vitest.config.mts` adds through `scripts/angular/stuck-test-plugin.ts`: Angular's builder drops the configuration's own reporters when the command line names any, and a reporter Vitest loads by its path runs in Vite's module runner, whose stack mapping fails on its frames in each Playwright call's stack, so the plugin adds the reporter it imports to Vitest's resolved reporters. The reporter: every 5 seconds it checks how long each test file has been silent. Once a file's tests have started, when that passes the longer of the hook limit and the file's first unfinished test's limit by 30 seconds, it names the file and that test, `<file> > <test>`, or the file alone when Vitest's main process hasn't heard of its tests yet, as when its first test stops the page, as the browser sends a file's tests as they run; a file still loading after 100 seconds is named alone, and when no file is loading or running and the whole run has been silent for 100 seconds with files unfinished, it names each of them. The 100 seconds are over three times the longest start before a part's first file, 30.6 seconds on macOS x64 in main's last three Build and test runs of 2026-11-30. With the names, it gives each browser session's commands still running, such as a click or a viewport's resize, with the file that sent each and how long it has run, and what the session's page's main thread does, through the Chrome DevTools Protocol: busy, with the JavaScript stack the debugger's pause stops, idle when no JavaScript runs within 5 seconds of the pause, or silent when the page doesn't answer the pause. A page's debugger slows a run while it is on, so the reporter turns each page's on, with breakpoints and `debugger` statements off, only once the run stops: an idle page answers then, while a busy page, whose main thread no longer answers, is named unread. Over 91 of the kit's browser spec files, keeping each page's on from its first command took 4 to 35% longer than a run without the reporter on macOS and Windows, and turning it on only at the stop took within 3% of it; on Linux the test machine's run-to-run spread, 27 to 51 seconds, hid both, though arming at the stop was never slower than the run without the reporter in a round. Early arming, an option of `StuckTestPlugin` and the reporter, turns each page's on while the page still answers, before the session's first browser command runs, which reads a busy page's stack too, and waits for it at most 5 seconds; turning it on goes on past that, as a slow browser can still answer. A page whose debugger isn't on by the time the run stops is named unread, with the error that stopped it turning on, if any. The kit's runs arm early only when `NOLDOVA_STUCK_ARM_EARLY=1` is set, so in CI, flake-proof runs included, a busy page reads unread rather than its stack; setting it gets the stack in a run on a developer's computer or a test machine. It then stops the run with exit code 1. It reads Vitest's objects through interfaces of its own, in `scripts/angular/interfaces/`, as Vitest's types bring in the browser's, which the scripts' compile leaves out. Its Node.js test, `src/noldova.ui.components.angular/tests/node/stuck-test-reporter.test.ts`, reads busy, idle, silent and unread pages through stand-in DevTools sessions, runs the reporter on a stand-in project to show that by default it turns a page's debugger on only at the stop and reads a page that answers then, a page whose debugger turns on late, and a session's second arm, which waits for its first, and runs Vitest's browser mode with the reporter, from its plugin with short limits, on `tests/fixtures/stuck-test/`, where `NOLDOVA_STUCK_LOAD` and `NOLDOVA_STUCK_ARM_EARLY` set each run's load limit and early arming: on a test that loops forever, with early arming and without, a file whose import never settles, with a short load limit, and a test that passes a `debugger` statement, with early arming.
`npm test -- --shard=<part>/<parts>`, with 2 to 8 parts, runs only every `<parts>`-th spec file of the kit's sorted list, from the `<part>`-th, with the Angular `part` configuration, which keeps the coverage report in `_build/angular-coverage` without gating it, and runs the checks and the Node.js tests before the specs only in part 1.
`npm run test:merge -- <folder> <parts>`, with Node.js alone, first checks itself on small reports in a temporary folder, then adds up the coverage of the parts, each in a subfolder of `<folder>`, by where each function, statement and branch sits in its file, from only the parts that loaded the file, since a part that never loaded it maps it from its source and can map it otherwise, and fails as `npm test` does below the requirement in [Coverage](#coverage), naming what no part reached; it also fails when fewer subfolders than `<parts>` came, or when one holds no report or one that isn't JSON.
Expand Down
18 changes: 8 additions & 10 deletions src/noldova.ui.components.angular.docs/scripts/test-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import fs from "node:fs/promises";
import path from "node:path";

import CommandFailedException from "../../noldova.ui.components.angular/scripts/command-failed.exception.ts";
import Config from "../../noldova.ui.components.angular/scripts/config.ts";
import Script from "../../noldova.ui.components.angular/scripts/script.ts";
import { AngularCoverageReport } from "../../noldova.ui.components.angular/scripts/angular/angular-coverage-report.ts";
import { AngularTestReport } from "../../noldova.ui.components.angular/scripts/angular/angular-test-report.ts";
import { BrowserSessionStages } from "../../noldova.ui.components.angular/scripts/angular/browser-session-stages.ts";
import { ProcessRunner } from "../../noldova.ui.components.angular/scripts/processes/process-runner.ts";
import { DocsSiteCheck } from "./docs-site-check.ts";
import { DocsPreparation } from "./docs/docs-preparation.ts";
import { DocsSymbols } from "./docs/docs-symbols.ts";
Expand All @@ -30,6 +31,7 @@ export class TestDocs extends Script {
private static readonly BLANK_LINE: string = "";
private static readonly SYMBOLS_TITLE: string = "The docs site's subset of the symbol font";
private static readonly WORKSPACE_FOLDER: string = ".";
private static readonly TEST_RUNNER: ProcessRunner = new ProcessRunner();
private static readonly PLATFORM: NodeJS.Platform = "linux";
private static readonly SUITE_OPTION: string = "--suite";
private static readonly ACCEPTED_OPTIONS: readonly string[] = [TestDocs.SUITE_OPTION, "--skip-test-details", "--skip-coverage-details"];
Expand Down Expand Up @@ -65,15 +67,11 @@ export class TestDocs extends Script {
await fs.rm(file, { force: true });
await fs.rm(coverage.path, { force: true });
await fs.rm(TestDocs.DEPENDENCY_CACHE, { recursive: true, force: true });
let failed = false;
try {
await this.executeProcessAsync(process.execPath, [TestDocs.ANGULAR_CLI_PATH, ...TestDocs.ANGULAR_TEST_ARGUMENTS, file], TestDocs.WORKSPACE_FOLDER);
}
catch (error) {
if (!(error instanceof CommandFailedException))
throw error;
failed = true;
}
// The kit's browser debug lines, so a stalled run's log shows how far each browser session got, its provider's and its socket's last events (#270).
const stages = new BrowserSessionStages();
const failed = await stages.runAsync(TestDocs.TEST_RUNNER, process.execPath, [TestDocs.ANGULAR_CLI_PATH, ...TestDocs.ANGULAR_TEST_ARGUMENTS, file], TestDocs.WORKSPACE_FOLDER) !== 0;
for (const line of stages.report())
await this.writeLogAsync(line);
const findings = [...await report.checkAsync(file, specs), ...await coverage.listUnhitAsync()];
for (const finding of findings)
await this.writeLogAsync(finding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@

import "@noldova/context.core";

import { OrchestratorLine } from "./orchestrator-line.ts";

import type { ProcessRunner } from "../processes/process-runner.ts";

// How far each browser session of a part got, from the debug lines Vitest writes with DEBUG naming its namespaces: the Playwright provider's
// last stage, whose last, "browser page is created, opening", means the page's loading began, and what the session's orchestrator socket did,
// which Vitest's browser API logs by the session's id. Vitest's own error, when the sessions don't connect, names one session and no stage.
export class BrowserSessionStages {
public static readonly namespaces: readonly string[] = ["vitest:browser:playwright", "vitest:browser:api"];
private static readonly DEBUG_VARIABLE: string = "DEBUG";
Comment thread
rostislavrotaru marked this conversation as resolved.
Resolved
private static readonly CONNECT_FAILURE: string = "Failed to connect to the browser session";
private static readonly COLOR: RegExp = /\u001b\[[0-9;]*m/gu;
private static readonly SESSION_LINE: RegExp = /vitest:browser:playwright \[([0-9a-f-]{36})\]\[[^\]]+\] (.+)$/u;
private static readonly BROWSER_LINE: RegExp = /vitest:browser:playwright \[[^\]]+\] (.+)$/u;
// The browser API's lines on a session's orchestrator socket, whose id is the session's, and what each means.
private static readonly ORCHESTRATOR_LINES: readonly (readonly [RegExp, string])[] = [
[/vitest:browser:api \[([0-9a-f-]{36})\] Browser API connected to orchestrator$/u, "connected"],
[/vitest:browser:api \[([0-9a-f-]{36})\] Browser API disconnected from orchestrator$/u, "disconnected"],
[/vitest:browser:api \[([0-9a-f-]{36})\] ignoring the orchestrator connection of a closed session$/u, "refused, its session closed"],
[/vitest:browser:api \[([0-9a-f-]{36})\] orchestrator did not respond to \d+ heartbeat pings/u, "stopped answering pings"]
];
// One per command a test runs, so the log leaves them out.
private static readonly COMMAND_LINE: RegExp = /vitest:browser:api \[[^\]]+\] Triggering command /u;
private static readonly NO_LINE: string = "no line from the Playwright provider";
Expand All @@ -38,6 +36,14 @@ export class BrowserSessionStages {
return [...Object.isUndefined(current) || current.length === 0 ? [] : [current], ...BrowserSessionStages.namespaces].join(",");
}

// Runs an Angular test run with DEBUG naming the namespaces too, reading each line of its output, and returns its exit code; the kit's parts and
// the docs site's run both start through it, so each one's log shows how far its browser sessions got.
public async runAsync(runner: ProcessRunner, command: string, commandArguments: readonly string[], directory: string,
environment: NodeJS.ProcessEnv = process.env): Promise<number | null> {
const debug = BrowserSessionStages.debugOf(environment[BrowserSessionStages.DEBUG_VARIABLE]);
return await runner.runReadingLinesAsync(command, commandArguments, directory, { ...environment, [BrowserSessionStages.DEBUG_VARIABLE]: debug }, t => this.read(t));
}

// Reads a line of the part's output, and says whether the log shows it.
public read(line: string): boolean {
const text = line.replace(BrowserSessionStages.COLOR, "").trimEnd();
Expand All @@ -55,12 +61,10 @@ export class BrowserSessionStages {
this.browser = String(browser[1]);
return true;
}
for (const [pattern, event] of BrowserSessionStages.ORCHESTRATOR_LINES) {
const orchestrator = pattern.exec(text);
if (!Object.isNull(orchestrator)) {
const id = String(orchestrator[1]);
this.orchestrators.set(id, [...this.orchestrators.get(id) ?? [], event]);
}
for (const orchestrator of OrchestratorLine.all) {
const id = orchestrator.sessionOf(text);
if (!Object.isNull(id))
this.orchestrators.set(id, [...this.orchestrators.get(id) ?? [], orchestrator.event]);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @license
* Copyright (c) Noldova.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

import "@noldova/context.core";

// A line the browser API writes on a session's orchestrator socket, whose id is the session's, and what it means.
export class OrchestratorLine {
public static readonly all: readonly OrchestratorLine[] = [
new OrchestratorLine(/vitest:browser:api \[([0-9a-f-]{36})\] Browser API connected to orchestrator$/u, "connected"),
new OrchestratorLine(/vitest:browser:api \[([0-9a-f-]{36})\] Browser API disconnected from orchestrator$/u, "disconnected"),
new OrchestratorLine(/vitest:browser:api \[([0-9a-f-]{36})\] ignoring the orchestrator connection of a closed session$/u, "refused, its session closed"),
new OrchestratorLine(/vitest:browser:api \[([0-9a-f-]{36})\] orchestrator did not respond to \d+ heartbeat pings/u, "stopped answering pings")
];

public readonly event: string;
private readonly pattern: RegExp;

private constructor(pattern: RegExp, event: string) {
this.pattern = pattern;
this.event = event;
}

// The session's id when the text is this line, or null.
public sessionOf(text: string): string | null {
const match = this.pattern.exec(text);
return Object.isNull(match) ? null : String(match[1]);
}
}
Loading
Loading