Skip to content

Commit

Permalink
Update for newest API (#122)
Browse files Browse the repository at this point in the history
* Update for newest API

* Update yarn

* Adapt code

* Add changeset

* Update documentation

* Do not compute individual durations
  • Loading branch information
Jym77 authored Jan 15, 2025
1 parent 75cfc54 commit 5404311
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 426 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-taxis-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-test-utils": minor
---

**Breaking:** The `siteID` parameter for uploading to the Siteimprove Intelligence Platform now needs to be a `number`, not a `string`.
7 changes: 7 additions & 0 deletions .changeset/gold-schools-live.md
Original file line number Diff line number Diff line change
@@ -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.
556 changes: 278 additions & 278 deletions .yarn/releases/yarn-4.5.1.cjs → .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ npmScopes:
siteimprove:
npmRegistryServer: "https://npm.pkg.github.com"

yarnPath: .yarn/releases/yarn-4.5.1.cjs
yarnPath: .yarn/releases/yarn-4.6.0.cjs
47 changes: 8 additions & 39 deletions docs/review/api/alfa-test-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string>;
// @internal (undocumented)
export function recordRule(durations: Durations): Performance_2<RuleEvent>;
// 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<Flattened.Input, Flattened.Target, Flattened.Question, Flattened.Subject>;
export type RulesDurations = {
[key: string]: RuleDurations;
};
{};
}

Expand All @@ -225,7 +199,7 @@ export namespace SIP {
// @internal (undocumented)
export namespace Defaults {
const // (undocumented)
URL = "https://api.siteimprove.com/v2/a11y/AlfaDevCheck/CreateReport";
URL = "https://api.siteimprove.com/v2/a11y/AlfaDevCheck";
const // (undocumented)
Title = "";
const // (undocumented)
Expand All @@ -238,6 +212,8 @@ export namespace SIP {
timestamp?: string;
httpsAgent?: Agent;
}): Promise<AxiosRequestConfig>;
// 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<Performance.CommonKeys>]: number;
Expand All @@ -255,19 +231,12 @@ export namespace SIP {
Failed: number;
Passed: number;
CantTell: number;
Durations: RuleDurations;
}>;
SiteId?: string;
SiteId?: number;
TestName?: string;
Version: `${number}.${number}.${number}`;
}
export function payload(audit: Audit | Audit.JSON, options: Partial<Options>, timestamp: string): Promise<Payload>;
// 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<Performance.DurationKey>]: number;
};
{};
}
// (undocumented)
Expand All @@ -276,7 +245,7 @@ export namespace SIP {
commitInformation?: CommitInformation | Option<CommitInformation> | Result<CommitInformation, unknown>;
pageTitle?: string | ((page: Page) => string);
pageURL?: string | ((page: Page) => string);
siteID?: string;
siteID?: number;
testName?: string | ((commit: CommitInformation) => string);
userName?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
"prettier": "^2.7.1",
"typescript": "^5.5.2"
},
"packageManager": "yarn@4.5.1"
"packageManager": "yarn@4.6.0"
}
6 changes: 3 additions & 3 deletions packages/alfa-test-utils/docs/usage/reporting/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
testName: (commit) =>
`WCAG 2.2 Level AA conformance test on ${commit.BranchName}`,
});
Expand All @@ -35,7 +35,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
pageTitle: // Gets the text content of the first `<h1>` element.
(alfaPage) =>
Query.getElementDescendants(alfaPage.document)
Expand All @@ -62,7 +62,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
pageURL: (alfaPage) =>
alfaPage.response.url.toString().replace("localhost:8080", "example.com"),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/alfa-test-utils/docs/usage/reporting/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SIP } from "@siteimprove/alfa-test-utils";
const pageReportURL = await SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
});
```

Expand Down Expand Up @@ -68,7 +68,7 @@ export default defineConfig({
const pageReportUrl = await SIP.upload(audit, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
});

Logging.fromAudit(audit, pageReportUrl).print();
Expand Down
10 changes: 5 additions & 5 deletions packages/alfa-test-utils/docs/usage/reporting/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
commitInformation: {
BranchName: "main",
CommitHash: "a1b2c3d4",
Expand All @@ -43,7 +43,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
commitInformation: gitInformation,
});
});
Expand All @@ -60,7 +60,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
pageTitle: "Paginated table component",
});
});
Expand All @@ -79,7 +79,7 @@ const pageReportURL = Audit.run(alfaPage).then((alfaResult) => {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
pageURL: "http://example.com/contact/about-us.html",
});
});
Expand All @@ -96,7 +96,7 @@ const pageReportURL = Audit.run(alfaPage, {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME, // email address of the user.
apiKey: process.env.SI_API_KEY, // API key generated in the platform.
siteID: "123456", // Site ID from the Siteimprove Intelligence Platform.
siteID: 123456, // Site ID from the Siteimprove Intelligence Platform.
testName: "WCAG 2.2 Level AA conformance test",
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/alfa-test-utils/src/audit/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export namespace Audit {
export async function run(page: Page, options: Options = {}): Promise<Audit> {
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);
Expand All @@ -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);

Expand Down
62 changes: 4 additions & 58 deletions packages/alfa-test-utils/src/audit/performance.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,81 +9,29 @@ 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<RuleEvent> {
return alfaPerformance.of<Performance.RuleEvent>().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 */
export function recordCommon(durations: Durations): alfaPerformance<string> {
return alfaPerformance.of<string>().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;
}
});
}
Expand Down
12 changes: 4 additions & 8 deletions packages/alfa-test-utils/src/report/sip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/CreateReport";
export const URL = "https://api.siteimprove.com/v2/a11y/AlfaDevCheck";
export const Title = "";
export const Name = undefined;
}
Expand Down Expand Up @@ -114,7 +113,7 @@ export namespace SIP {
/**
* The site ID in the Siteimprove Intelligence Platform.
*/
siteID?: string;
siteID?: number;

/**
* The URL of the page, or a function to build it from the audited page.
Expand Down Expand Up @@ -154,7 +153,6 @@ export namespace SIP {
*/
export namespace Metadata {
// We need to capitalize names for the API calls.
type RuleDurations = { [K in CamelCase<Performance.DurationKey>]: number };
type CommonDurations = { [K in CamelCase<Performance.CommonKeys>]: number };

/** @internal */
Expand All @@ -172,7 +170,7 @@ export namespace SIP {
/**
* The site ID to which the page belongs in the Siteimprove Intelligence Platform.
*/
SiteId?: string;
SiteId?: number;

/**
* Information about the latest git commit
Expand Down Expand Up @@ -214,7 +212,6 @@ export namespace SIP {
Failed: number;
Passed: number;
CantTell: number;
Durations: RuleDurations;
}>;

/**
Expand Down Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 5404311

Please sign in to comment.