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
35 changes: 28 additions & 7 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export abstract class AngularTimingScript extends Script {
private static readonly ANGULAR_TEST_COMMAND: string = "test";
private static readonly ANGULAR_FILTER_OPTION: string = "--filter";
private static readonly ANGULAR_INCLUDE_OPTION: string = "--include";
private static readonly ANGULAR_EXCLUDE_OPTION: string = "--exclude";
private static readonly ANGULAR_ISOLATE_OPTION: string = "--isolate";
private static readonly TIMING_FOLDER: string = "../../_build/timing";
private static readonly DEPENDENCY_CACHE: string = "../../node_modules/.vite";
private static readonly WORKSPACE_FOLDER: string = ".";
Expand All @@ -48,18 +50,21 @@ export abstract class AngularTimingScript extends Script {
private static readonly SELF_CHECK_FAILED: string = "The timing check failed its own check, so it times nothing.";
private static readonly SELECTION_CASE: string =
"a workspace with a spec file that traces layout and one that doesn't runs every test outside the tracing suite first, then the suite from that file alone, "
+ "and spec files named by their file names run only those files, in the same parts";
+ "and spec files named by their file names run only those files, in the same parts; a listed spec file runs alone, in a part of its own with isolate on, "
+ "and the other parts leave it out";
private static readonly TRACED_SPEC: string = "tests/traced.spec.ts";
private static readonly UNTRACED_SPEC: string = "tests/untraced.spec.ts";
private static readonly SHARED_NAME_SPEC: string = "tests/other/untraced.spec.ts";

private readonly project: string;
private readonly owner: string;
private readonly isolated: readonly string[];

protected constructor(project: string, owner: string) {
protected constructor(project: string, owner: string, isolated: readonly string[] = []) {
super();
this.project = project;
this.owner = owner;
this.isolated = isolated;
}

// Spec files named by their file names, such as code-block-run.component.spec.ts, are the only ones timed; with none named, every spec file is.
Expand Down Expand Up @@ -87,7 +92,7 @@ export abstract class AngularTimingScript extends Script {
await fs.rm(AngularTimingScript.DEPENDENCY_CACHE, { recursive: true, force: true });
const timing = new AngularTestTiming(AngularTimingScript.WORKSPACE_FOLDER);
const tests = new AngularTestReport(AngularTimingScript.WORKSPACE_FOLDER, this.project);
const parts = await AngularTimingScript.partsAsync(AngularTimingScript.WORKSPACE_FOLDER, tests, specs);
const parts = await AngularTimingScript.partsAsync(AngularTimingScript.WORKSPACE_FOLDER, tests, specs, this.isolated);
for (let run = 1; run <= AngularTimingScript.RUNS; run++) {
await this.writeLogAsync(`Timing run ${run} of ${AngularTimingScript.RUNS} of ${this.owner} specs...`);
const reports: string[] = [];
Expand Down Expand Up @@ -129,7 +134,7 @@ export abstract class AngularTimingScript extends Script {

// The test builder's selections for one timing run: one for every spec, or, when spec files trace layout, first every test outside the tracing
// suite, then only the suite's tests from the files that hold it, each in a browser of its own.
private static async partsAsync(folder: string, tests: AngularTestReport, specs: readonly string[] = []): Promise<readonly (readonly string[])[]> {
private static async partsAsync(folder: string, tests: AngularTestReport, specs: readonly string[], isolatedFiles: readonly string[]): Promise<readonly (readonly string[])[]> {
const files = await tests.listSpecFilesAsync();
const matches = specs.map(t => [t, files.filter(u => u === t || path.posix.basename(u) === t)] as const);
const unknown = matches.filter(([, t]) => t.length === 0).map(([t]) => t);
Expand All @@ -141,17 +146,20 @@ export abstract class AngularTimingScript extends Script {
throw new CommandFailedException(`${shared.map(([t, u]) => `${t} names ${u.join(" and ")}`).join("; ")}; name such a spec file by its path from the workspace's folder.`);
const chosen = specs.length === 0 ? files : files.filter(t => matches.some(([, u]) => u.includes(t)));
const include = (selected: readonly string[]): readonly string[] => selected.flatMap(t => [AngularTimingScript.ANGULAR_INCLUDE_OPTION, t]);
const isolated = chosen.filter(t => isolatedFiles.includes(t));
const onPage = chosen.filter(t => !isolated.includes(t));
const traced: string[] = [];
for (const spec of chosen)
for (const spec of onPage)
if ((await fs.readFile(path.resolve(folder, spec), AngularTimingScript.ENCODING)).includes(LayoutTraceSuite.mark))
traced.push(spec);
const named = specs.length === 0 ? [] : include(chosen);
const named = specs.length === 0 ? isolatedFiles.flatMap(t => [AngularTimingScript.ANGULAR_EXCLUDE_OPTION, t]) : include(onPage);
const untraced = `${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.untracedFilter}`;
const alone = isolated.length === 0 ? [] : [[AngularTimingScript.ANGULAR_ISOLATE_OPTION, untraced, ...include(isolated)]];
if (onPage.length === 0)
return alone;
if (traced.length === 0)
return [named];
return [
[`${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.untracedFilter}`, ...named],
[`${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.title}`, ...include(traced)]
];
return [named, ...alone];
return [[untraced, ...named], [`${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.title}`, ...include(traced)], ...alone];
}

private static async checkRanOnceAsync(tests: AngularTestReport, reports: readonly string[]): Promise<readonly string[]> {
Expand Down Expand Up @@ -268,17 +276,23 @@ export abstract class AngularTimingScript extends Script {
await fs.writeFile(path.join(folder, AngularTimingScript.SHARED_NAME_SPEC), "describe(\"Shared name\", () => {});\n", AngularTimingScript.ENCODING);
const report = new AngularTestReport(folder, AngularTimingScript.SELF_CHECK_PROJECT);
const tracedPart = [`${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.title}`, AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.TRACED_SPEC];
const untraced = `${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.untracedFilter}`;
const isolated = [AngularTimingScript.SHARED_NAME_SPEC];
const alonePart = [AngularTimingScript.ANGULAR_ISOLATE_OPTION, untraced, AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.SHARED_NAME_SPEC];
const selections = [
[[], [[`${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.untracedFilter}`], tracedPart]],
[[AngularTimingScript.UNTRACED_SPEC], [[AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.UNTRACED_SPEC]]],
[[path.posix.basename(AngularTimingScript.TRACED_SPEC)],
[[`${AngularTimingScript.ANGULAR_FILTER_OPTION}=${LayoutTraceSuite.untracedFilter}`, AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.TRACED_SPEC], tracedPart]]
[[], [], [[untraced], tracedPart]],
[[AngularTimingScript.UNTRACED_SPEC], [], [[AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.UNTRACED_SPEC]]],
[[path.posix.basename(AngularTimingScript.TRACED_SPEC)], [], [[untraced, AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.TRACED_SPEC], tracedPart]],
[[], isolated, [[untraced, AngularTimingScript.ANGULAR_EXCLUDE_OPTION, AngularTimingScript.SHARED_NAME_SPEC], tracedPart, alonePart]],
[[AngularTimingScript.UNTRACED_SPEC, AngularTimingScript.SHARED_NAME_SPEC], isolated,
[[AngularTimingScript.ANGULAR_INCLUDE_OPTION, AngularTimingScript.UNTRACED_SPEC], alonePart]],
[[AngularTimingScript.SHARED_NAME_SPEC], isolated, [alonePart]]
] as const;
for (const [specs, expected] of selections)
if (JSON.stringify(await AngularTimingScript.partsAsync(folder, report, specs)) !== JSON.stringify(expected))
for (const [specs, isolatedFiles, expected] of selections)
if (JSON.stringify(await AngularTimingScript.partsAsync(folder, report, specs, isolatedFiles)) !== JSON.stringify(expected))
return false;
for (const specs of [["missing.spec.ts"], [path.posix.basename(AngularTimingScript.UNTRACED_SPEC)]])
if (await AngularTimingScript.partsAsync(folder, report, specs).then(() => true, (error: unknown) => !(error instanceof CommandFailedException)))
if (await AngularTimingScript.partsAsync(folder, report, specs, []).then(() => true, (error: unknown) => !(error instanceof CommandFailedException)))
return false;
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/noldova.ui.components.angular/scripts/test-timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* LICENSE file in the root directory of this source tree.
*/

import { IsolatedSpecs } from "../tests/fixtures/isolated-specs.ts";
import { AngularTimingScript } from "./angular/angular-timing-script.ts";

export class TestTiming extends AngularTimingScript {
private static readonly ANGULAR_PROJECT: string = "components";
private static readonly OWNER: string = "the kit's";

public constructor() {
super(TestTiming.ANGULAR_PROJECT, TestTiming.OWNER);
super(TestTiming.ANGULAR_PROJECT, TestTiming.OWNER, IsolatedSpecs.files);
}

public override async runAsync(): Promise<void> {
Expand Down
30 changes: 27 additions & 3 deletions src/noldova.ui.components.angular/scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PollBoundCheck } from "./checks/poll-bound-check.ts";
import { ProductNamesCheck } from "./checks/product-names-check.ts";
import CommandFailedException from "./command-failed.exception.ts";
import Config from "./config.ts";
import { IsolatedSpecs } from "../tests/fixtures/isolated-specs.ts";
import { LayoutTraceSuite } from "../tests/fixtures/layout-trace-suite.ts";
import { ProcessRunner } from "./processes/process-runner.ts";
import { TemporaryFolder } from "./processes/temporary-folder.ts";
Expand Down Expand Up @@ -74,11 +75,15 @@ export class Test extends Script {
private static readonly ANGULAR_PART_OPTIONS: readonly string[] = ["--configuration=part"];
private static readonly ANGULAR_INCLUDE_OPTION: string = "--include";
private static readonly ANGULAR_FILTER_OPTION: string = "--filter";
private static readonly ANGULAR_EXCLUDE_OPTION: string = "--exclude";
private static readonly ANGULAR_ISOLATE_OPTION: string = "--isolate";
private static readonly ISOLATED_SPECS: readonly string[] = IsolatedSpecs.files;
private static readonly TRACED_SUITE: string = LayoutTraceSuite.title;
private static readonly TRACED_MARK: string = LayoutTraceSuite.mark;
private static readonly UNTRACED_FILTER: string = LayoutTraceSuite.untracedFilter;
private static readonly TRACED_PART: string = "part-2";
private static readonly UNTRACED_PART: string = "part-1";
private static readonly ISOLATED_PART: string = "part-3";
private static readonly PARTS_PREFIX: string = "kit-coverage-parts-";
private static readonly COVERAGE_PART_FILE: string = "coverage-final.json";
private static readonly DEPENDENCY_CACHE: string = "../../node_modules/.vite";
Expand Down Expand Up @@ -175,8 +180,15 @@ export class Test extends Script {
if (selected.length === 0)
return 0;

const unlisted = Test.ISOLATED_SPECS.filter(t => !specs.includes(t));
if (unlisted.length > 0) {
await this.writeLogAsync(Test.isolatedSpecsMissing(unlisted));
this.failed = true;
}
const isolated = selected.filter(t => Test.ISOLATED_SPECS.includes(t));
const shared = selected.filter(t => !isolated.includes(t));
const traced: string[] = [];
for (const spec of selected)
for (const spec of shared)
if ((await this.readFileAsync(path.resolve(Test.WORKSPACE_FOLDER, spec))).includes(Test.TRACED_MARK))
traced.push(spec);
const isWhole = filters.length === 0 && Object.isNull(shard);
Expand All @@ -185,15 +197,23 @@ export class Test extends Script {
const parts = await new TemporaryFolder().createAsync(process.platform, Test.PARTS_PREFIX);
try {
await fs.rm(Test.DEPENDENCY_CACHE, { recursive: true, force: true });
const runs = [await this.runAngularPartAsync(selected, isWhole ? [] : selected, options, Test.UNTRACED_FILTER, keepsCoverage ? path.join(parts, Test.UNTRACED_PART) : null)];
const runs: ReadonlyMap<string, boolean>[] = [];
if (shared.length > 0) {
const excluded = isWhole ? Test.ISOLATED_SPECS.flatMap(t => [Test.ANGULAR_EXCLUDE_OPTION, t]) : [];
runs.push(await this.runAngularPartAsync(shared, isWhole ? [] : shared, [...options, ...excluded], Test.UNTRACED_FILTER,
keepsCoverage ? path.join(parts, Test.UNTRACED_PART) : null));
}
if (traced.length > 0)
runs.push(await this.runAngularPartAsync(traced, traced, options, Test.TRACED_SUITE, keepsCoverage ? path.join(parts, Test.TRACED_PART) : null));
if (isolated.length > 0)
runs.push(await this.runAngularPartAsync(isolated, isolated, [...options, Test.ANGULAR_ISOLATE_OPTION], Test.UNTRACED_FILTER,
keepsCoverage ? path.join(parts, Test.ISOLATED_PART) : null));
for (const finding of AngularTestReport.checkRanOnce(runs)) {
await this.writeLogAsync(finding);
this.failed = true;
}
if (keepsCoverage) {
await new CoverageMerge(Test.ROOT, Test.KIT_FOLDER).mergeAsync(parts, traced.length > 0 ? 2 : 1, this.coverage.path);
await new CoverageMerge(Test.ROOT, Test.KIT_FOLDER).mergeAsync(parts, runs.length, this.coverage.path);
if (Object.isNull(shard))
for (const line of await this.coverage.listUnhitAsync()) {
await this.writeLogAsync(line);
Expand Down Expand Up @@ -256,6 +276,10 @@ export class Test extends Script {
return `The kit's run of the tests named by ${filter} wrote no coverage at ${file}.`;
}

private static isolatedSpecsMissing(files: readonly string[]): string {
return `IsolatedSpecs names spec files the kit doesn't have, so they would run nowhere: ${files.join(", ")}.`;
}

private static partRun(part: number, parts: number, specs: number): string {
return `Part ${part} of ${parts} ran ${specs} of the kit's spec files and kept their coverage, which npm run test:merge gates with the other parts'; the checks before the specs run in part 1 alone.`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DestroyRef, Directive, ElementRef, type Signal, afterNextRender, comput

import "@noldova/context.core";

import { ClockTokens } from "../../models/clock-tokens.js";
import { ConfigurationTableFillWidths } from "../../models/configuration-table-fill-widths.js";
import { ConfigurationTableShares } from "../../models/configuration-table-shares.js";
import { ConfigurationTableTokens } from "../../models/configuration-table-tokens.js";
Expand Down Expand Up @@ -45,18 +46,18 @@ export class ConfigurationTableDirective {
});

public constructor() {
let fitAfterObservedFrame: number | null = null;
const sizes = new ResizeObserver(() => fitAfterObservedFrame ??= requestAnimationFrame(() => {
fitAfterObservedFrame = null;
const timeSource = inject(ClockTokens.timeSource);
let cancelFit: (() => void) | null = null;
const sizes = new ResizeObserver(() => cancelFit ??= timeSource.frame(() => {
cancelFit = null;
this.fit();
}));
afterNextRender(() => {
for (const part of [this.grid.closest<HTMLElement>(ConfigurationTableDirectiveResources.configurationTableSelector), this.grid].filter((t): t is HTMLElement => !Object.isNull(t)))
sizes.observe(part);
});
inject(DestroyRef).onDestroy(() => {
if (!Object.isNull(fitAfterObservedFrame))
cancelAnimationFrame(fitAfterObservedFrame);
cancelFit?.();
sizes.disconnect();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { MarkdownMentions } from "../../models/markdown-mentions.js";
import { MarkdownReveal } from "../../models/markdown-reveal.js";
import { MarkdownShellRunner } from "../../models/markdown-shell-runner.js";
import { MarkdownViewTokens } from "../../models/markdown-view-tokens.js";
import { MediaTokens } from "../../models/media-tokens.js";
import type { MentionCandidate } from "../../models/mention-candidate.js";
import type { ShellRun } from "../../models/shell-run.js";
import { ShellRunBlocks } from "../../models/shell-run-blocks.js";
Expand Down Expand Up @@ -66,7 +67,7 @@ export class MarkdownViewComponent {
private readonly markdown: IMarkdownParser | null = inject(MarkdownViewTokens.parser);
private readonly reader: MarkdownReader = new MarkdownReader();
private readonly host: HTMLElement = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
private readonly reveal: MarkdownReveal | null = isPlatformBrowser(inject(PLATFORM_ID)) ? new MarkdownReveal(this.host) : null;
private readonly reveal: MarkdownReveal | null = isPlatformBrowser(inject(PLATFORM_ID)) ? new MarkdownReveal(this.host, inject(MediaTokens.queries)) : null;
private readonly image: Signal<MessageImageDirective | undefined> = contentChild(MessageImageDirective, { descendants: false });
private readonly shellRunOutput: Signal<ShellRunOutputDirective | undefined> = contentChild(ShellRunOutputDirective, { descendants: false });
private readonly outerImages: MarkdownImages = inject(MarkdownViewTokens.images, { skipSelf: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @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.
*/

export interface IHighlightScope {
readonly Highlight?: unknown;
readonly CSS?: { readonly highlights?: unknown };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @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.
*/

export interface IIdleCallbacks {
readonly requestIdleCallback?: (callback: IdleRequestCallback) => number;
readonly cancelIdleCallback: (handle: number) => void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @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.
*/

export interface IMediaQueries {
match(query: string): MediaQueryList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @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.
*/

export class HighlightTokensResources {
public static readonly highlightAvailableToken: string = "nol-highlight-available";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @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 { InjectionToken } from "@angular/core";

import "@noldova/context.core";

import type { IHighlightScope } from "../interfaces/i-highlight-scope.js";
import { HighlightTokensResources } from "./highlight-tokens.resources.js";

export class HighlightTokens {
public static readonly available: InjectionToken<boolean> =
new InjectionToken<boolean>(HighlightTokensResources.highlightAvailableToken, { providedIn: "root", factory: () => HighlightTokens.isAvailableIn(globalThis) });

public static isAvailableIn(scope: IHighlightScope): boolean {
return Object.isFunction(scope.Highlight) && !Object.isNullOrUndefined(scope.CSS?.highlights);
}
}
Loading
Loading