Advanced reporting configuration
Building a page title
The page title can be built from the page itself. Be aware that this examines the Alfa representation of the page where the API is somewhat different from the normal DOM API. For example, to get the first <h1>
heading of the page:
import { Element, Query } from "@siteimprove/alfa-dom";
const pageReportURL = Audit.run(alfaPage, {
rules: { include: Rules.componentFilter },
}).then((alfaResult) => {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME,
apiKey: process.env.SI_API_KEY,
siteID: "12345",
pageTitle: (alfaPage) =>
Query.getElementDescendants(alfaPage.document)
.filter(Element.isElement)
.find(Element.hasName("h1"))
.map((heading) => heading.textContent())
.getOr("Unnamed page"),
});
});
Building a page URL
Similarly, the page URL can be built from the Alfa representation of the page, which can be useful typically to overwrite localhost
URLs:
const pageReportURL = Audit.run(alfaPage, {
rules: { include: Rules.comnponentFilter },
}).then((alfaResult) => {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME,
apiKey: process.env.SI_API_KEY,
siteID: "12345",
pageURL: (alfaPage) =>
alfaPage.response.url.toString().replace("localhost:8080", "example.com"),
});
});
Building a test name
The testName
option can also be a function that produces a string
from basic commit information. For example, it can be convenient to name a test after the branch it originates from:
import { getCommitInformation } from "@siteimprove/alfa-test-utils/git";
const gitInformation = await getCommitInformation();
const pageReportURL = Audit.run(alfaPage, {
rules: { include: Rules.aaFilter },
}).then((alfaResult) => {
SIP.upload(alfaResult, {
userName: process.env.SI_USER_NAME,
apiKey: process.env.SI_API_KEY,
siteID: "12345",
commitInformation: gitInformation,
testName: (commit) =>
`WCAG 2.2 Level AA conformance test on ${commit.BranchName}`,
});
});