From 16affd300466cc307e46000b539e90df9663a1f7 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Wed, 15 Jan 2025 15:21:56 +0100 Subject: [PATCH] Do not compute individual durations --- .changeset/gold-schools-live.md | 7 +++ docs/review/api/alfa-test-utils.api.md | 41 ++---------- packages/alfa-test-utils/src/audit/audit.ts | 3 +- .../alfa-test-utils/src/audit/performance.ts | 62 ++----------------- packages/alfa-test-utils/src/report/sip.ts | 8 +-- .../alfa-test-utils/test/audit/audit.spec.tsx | 14 +---- .../alfa-test-utils/test/report/sip.spec.tsx | 15 +---- 7 files changed, 24 insertions(+), 126 deletions(-) create mode 100644 .changeset/gold-schools-live.md diff --git a/.changeset/gold-schools-live.md b/.changeset/gold-schools-live.md new file mode 100644 index 00000000..30675574 --- /dev/null +++ b/.changeset/gold-schools-live.md @@ -0,0 +1,7 @@ +--- +"@siteimprove/alfa-test-utils": minor +--- + +**Breaking:** Individual rules durations are not recorded anymore during audits. + +This means that `Audit#durations` directly contains the common keys. diff --git a/docs/review/api/alfa-test-utils.api.md b/docs/review/api/alfa-test-utils.api.md index 395a6ec1..94c3d040 100644 --- a/docs/review/api/alfa-test-utils.api.md +++ b/docs/review/api/alfa-test-utils.api.md @@ -19,7 +19,6 @@ import { Page } from '@siteimprove/alfa-web'; import { Performance as Performance_2 } from '@siteimprove/alfa-performance'; import type { Predicate } from '@siteimprove/alfa-predicate'; import { Result } from '@siteimprove/alfa-result'; -import type { Rule } from '@siteimprove/alfa-act'; import { Sequence } from '@siteimprove/alfa-sequence'; // @public @@ -167,42 +166,17 @@ export namespace Outcomes { // @public export namespace Performance { const // (undocumented) - durationKeys: readonly ["applicability", "expectation", "total"]; - // Warning: (ae-incompatible-release-tags) The symbol "CommonDurations" is marked as @public, but its signature references "Performance" which is marked as @internal - // - // (undocumented) - export type CommonDurations = { - [K in CommonKeys]: number; - }; + commonKeys: readonly ["cascade", "aria-tree", "total"]; // @internal (undocumented) export type CommonKeys = (typeof commonKeys)[number]; - // @internal (undocumented) - export type DurationKey = (typeof durationKeys)[number]; + // Warning: (ae-incompatible-release-tags) The symbol "Durations" is marked as @public, but its signature references "Performance" which is marked as @internal export type Durations = { - common: CommonDurations; - rules: RulesDurations; + [K in CommonKeys]: number; }; - const // (undocumented) - commonKeys: readonly ["cascade", "aria-tree", "total"]; // @internal (undocumented) export function empty(): Durations; // @internal (undocumented) - export function emptyRuleDurations(): RuleDurations; - // @internal (undocumented) export function recordCommon(durations: Durations): Performance_2; - // @internal (undocumented) - export function recordRule(durations: Durations): Performance_2; - // Warning: (ae-incompatible-release-tags) The symbol "RuleDurations" is marked as @public, but its signature references "Performance" which is marked as @internal - // - // (undocumented) - export type RuleDurations = { - [K in DurationKey]: number; - }; - // @internal (undocumented) - export type RuleEvent = Rule.Event; - export type RulesDurations = { - [key: string]: RuleDurations; - }; {}; } @@ -238,6 +212,8 @@ export namespace SIP { timestamp?: string; httpsAgent?: Agent; }): Promise; + // Warning: (ae-forgotten-export) The symbol "CamelCase" needs to be exported by the entry point index.d.ts + // // (undocumented) export type CommonDurations = { [K in CamelCase]: number; @@ -255,19 +231,12 @@ export namespace SIP { Failed: number; Passed: number; CantTell: number; - Durations: RuleDurations; }>; SiteId?: number; TestName?: string; Version: `${number}.${number}.${number}`; } export function payload(audit: Audit | Audit.JSON, options: Partial, timestamp: string): Promise; - // Warning: (ae-forgotten-export) The symbol "CamelCase" needs to be exported by the entry point index.d.ts - // - // (undocumented) - export type RuleDurations = { - [K in CamelCase]: number; - }; {}; } // (undocumented) diff --git a/packages/alfa-test-utils/src/audit/audit.ts b/packages/alfa-test-utils/src/audit/audit.ts index 36d0b821..62ed866c 100644 --- a/packages/alfa-test-utils/src/audit/audit.ts +++ b/packages/alfa-test-utils/src/audit/audit.ts @@ -138,7 +138,6 @@ export namespace Audit { export async function run(page: Page, options: Options = {}): Promise { const durations: Performance.Durations = Performance.empty(); const commonPerformance = Performance.recordCommon(durations); - const rulesPerformance = Performance.recordRule(durations); const start = commonPerformance.mark("total").start; sharedPerformance(commonPerformance, page); @@ -151,7 +150,7 @@ export namespace Audit { ); const audit = Sequence.from( - await alfaAudit.of(page, rulesToRun).evaluate(rulesPerformance) + await alfaAudit.of(page, rulesToRun).evaluate() ); commonPerformance.measure("total", start); diff --git a/packages/alfa-test-utils/src/audit/performance.ts b/packages/alfa-test-utils/src/audit/performance.ts index 824ac3f6..1bfa159b 100644 --- a/packages/alfa-test-utils/src/audit/performance.ts +++ b/packages/alfa-test-utils/src/audit/performance.ts @@ -1,7 +1,5 @@ -import type { Rule } from "@siteimprove/alfa-act"; import { Array } from "@siteimprove/alfa-array"; import { Performance as alfaPerformance } from "@siteimprove/alfa-performance"; -import type { Flattened } from "@siteimprove/alfa-rules"; const { isMeasure } = alfaPerformance.Measure; @@ -11,73 +9,21 @@ const { isMeasure } = alfaPerformance.Measure; * @public */ export namespace Performance { - const durationKeys = ["applicability", "expectation", "total"] as const; - /** @internal */ - export type DurationKey = (typeof durationKeys)[number]; - type RuleDurations = { [K in DurationKey]: number }; - - /** - * For each rule (key), records time taken for the applicability, - * the expectations, and total time. - * - * @public - */ - export type RulesDurations = { [key: string]: RuleDurations }; - - /** @internal */ - export function emptyRuleDurations(): RuleDurations { - return { applicability: 0, expectation: 0, total: 0 }; - } - const commonKeys = ["cascade", "aria-tree", "total"] as const; /** @internal */ export type CommonKeys = (typeof commonKeys)[number]; - type CommonDurations = { [K in CommonKeys]: number }; /** * Records the duration of resolving the CSS cascade, building the accessibility - * tree, and running each rule. - * - * @remarks - * The cascade and accessibility tree are cached, so we store their performance - * separately to avoid unfairly "charging" the first rule to use and build them. + * tree, and running the full audit. * * @public */ - export type Durations = { common: CommonDurations; rules: RulesDurations }; + export type Durations = { [K in CommonKeys]: number }; /** @internal */ export function empty(): Durations { - return { - common: { cascade: 0, "aria-tree": 0, total: 0 }, - rules: {}, - }; - } - - /** @internal */ - export type RuleEvent = Rule.Event< - Flattened.Input, - Flattened.Target, - Flattened.Question, - Flattened.Subject - >; - - /** @internal */ - export function recordRule(durations: Durations): alfaPerformance { - return alfaPerformance.of().on((entry) => { - if (isMeasure(entry)) { - const ruleId = entry.data.rule.uri; - - if (durations.rules[ruleId] === undefined) { - durations.rules[ruleId] = emptyRuleDurations(); - } - if (Array.includes(durationKeys, entry.data.name)) { - // Type is ensured by the previous test. - durations.rules[ruleId][entry.data.name as DurationKey] = - entry.duration; - } - } - }); + return { cascade: 0, "aria-tree": 0, total: 0 }; } /** @internal */ @@ -85,7 +31,7 @@ export namespace Performance { return alfaPerformance.of().on((entry) => { if (isMeasure(entry) && Array.includes(commonKeys, entry.data)) { // Type is ensured by the previous check - durations.common[entry.data as CommonKeys] = entry.duration; + durations[entry.data as CommonKeys] = entry.duration; } }); } diff --git a/packages/alfa-test-utils/src/report/sip.ts b/packages/alfa-test-utils/src/report/sip.ts index fab3e775..798ea7fd 100644 --- a/packages/alfa-test-utils/src/report/sip.ts +++ b/packages/alfa-test-utils/src/report/sip.ts @@ -23,8 +23,7 @@ import type { CommitInformation } from "./commit-information.js"; export namespace SIP { /** @internal */ export namespace Defaults { - export const URL = - "https://api.siteimprove.com/v2/a11y/AlfaDevCheck"; + export const URL = "https://api.siteimprove.com/v2/a11y/AlfaDevCheck"; export const Title = ""; export const Name = undefined; } @@ -154,7 +153,6 @@ export namespace SIP { */ export namespace Metadata { // We need to capitalize names for the API calls. - type RuleDurations = { [K in CamelCase]: number }; type CommonDurations = { [K in CamelCase]: number }; /** @internal */ @@ -214,7 +212,6 @@ export namespace SIP { Failed: number; Passed: number; CantTell: number; - Durations: RuleDurations; }>; /** @@ -295,9 +292,8 @@ export namespace SIP { ).map(([RuleId, data]) => ({ RuleId, ...toCamelCase(data), - Durations: toCamelCase(audit.durations.rules[RuleId]), })), - Durations: toCamelCase(audit.durations.common), + Durations: toCamelCase(audit.durations), }; commitInfo.forEach((info) => (result.CommitInformation = info)); diff --git a/packages/alfa-test-utils/test/audit/audit.spec.tsx b/packages/alfa-test-utils/test/audit/audit.spec.tsx index 6e21c3a7..8b726358 100644 --- a/packages/alfa-test-utils/test/audit/audit.spec.tsx +++ b/packages/alfa-test-utils/test/audit/audit.spec.tsx @@ -156,17 +156,9 @@ test(".run() build performance data", async (t) => { // We cannot test real values due to instability, only checking they've been // updated. - t.notEqual(actual.common.total, 0); - t.notEqual(actual.common.cascade, 0); - t.notEqual(actual.common["aria-tree"], 0); - - t.deepEqual(Object.keys(actual.rules), [ - "https://alfa.siteimprove.com/rules/sia-r2", - ]); - const rule = actual.rules["https://alfa.siteimprove.com/rules/sia-r2"]; - t.notEqual(rule.total, 0); - t.notEqual(rule.applicability, 0); - t.notEqual(rule.expectation, 0); + t.notEqual(actual.total, 0); + t.notEqual(actual.cascade, 0); + t.notEqual(actual["aria-tree"], 0); }); test(".run() excludes occurrences in `