@axe-core/reporter-earl
Version:
A EARL+JSON-LD reporter for axe-core
152 lines (144 loc) • 4.45 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/axeReporterEarl.ts
var axeReporterEarl_exports = {};
__export(axeReporterEarl_exports, {
createEarlReport: () => createEarlReport,
default: () => axeReporterEarl
});
module.exports = __toCommonJS(axeReporterEarl_exports);
// src/context.json
var context_default = {
"@vocab": "http://www.w3.org/ns/earl#",
earl: "http://www.w3.org/ns/earl#",
WCAG20: "http://www.w3.org/TR/WCAG20/#",
WCAG21: "http://www.w3.org/TR/WCAG21/#",
"auto-wcag": "https://auto-wcag.github.io/auto-wcag/rules/",
dct: "http://purl.org/dc/terms#",
sch: "https://schema.org/",
doap: "http://usefulinc.com/ns/doap#",
foaf: "http://xmlns.com/foaf/spec/#",
WebPage: "sch:WebPage",
url: "dct:source",
assertions: {
"@reverse": "subject"
},
assertedBy: {
"@type": "@id"
},
outcome: {
"@type": "@id"
},
mode: {
"@type": "@id"
},
pointer: {
"@type": "ptr:CSSSelectorPointer"
}
};
// src/testResult.ts
function cssToPointer(selector) {
const item = selector[0];
if (Array.isArray(item)) {
return item[0];
}
return item;
}
function testResult({ description }, outcomes = []) {
return outcomes.map(({ node, result }) => {
return {
"@type": "TestResult" /* TestResult */,
info: description,
outcome: "earl:" + result,
pointer: cssToPointer(node.selector)
};
});
}
// src/axeResultToEarl.ts
function axeResultToEarl(rawResults) {
return rawResults.reduce(
(asserts, axeResult) => {
let results = [];
results = results.concat(testResult(axeResult, axeResult.violations));
results = results.concat(testResult(axeResult, axeResult.passes));
results = results.concat(testResult(axeResult, axeResult.incomplete));
if (results.length === 0) {
results.push({
"@type": "TestResult" /* TestResult */,
outcome: "earl:inapplicable"
});
}
const newAsserts = results.map((result) => {
const match = axeResult.helpUrl.match(
/axe\/([1-9][0-9]*\.[1-9][0-9]*)\//
);
const version = match && match[1] || "";
return {
"@type": "Assertion" /* Assertion */,
mode: "earl:automatic",
assertedBy: {
"@id": `https://github.com/dequelabs/axe-core/releases/tag/${version}.0`,
"@type": ["earl:Assertor", "earl:Software", "doap:Project"],
"doap:name": "Axe",
"doap:vendor": {
"@id": "https://deque.com/",
"@type": "foaf:Organization",
"foaf:name": "Deque Systems"
}
},
test: {
"@type": "TestCase" /* TestCase */,
"@id": axeResult.helpUrl
},
result
};
});
return asserts.concat(newAsserts);
},
[]
);
}
// src/axeReporterEarl.ts
function createEarlReport(rawResults, url) {
debugger;
return {
"@context": context_default,
"@type": "WebPage" /* WebPage */,
url: url ? url : window.location.href,
assertions: axeResultToEarl(rawResults)
};
}
function axeReporterEarl(rawResults, {}, callback) {
callback(createEarlReport(rawResults));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createEarlReport
});
if (module.exports.default) {
var ___default_export = module.exports.default;
var ___export_entries = Object.entries(module.exports);
module.exports = ___default_export;
___export_entries.forEach(([key, value]) => {
if (module.exports[key]) {
throw new Error(`Export "${key}" already exists on default export`);
}
module.exports[key] = value;
});
}