Skip to content

Commit

Permalink
Refactored to accept options as an object
Browse files Browse the repository at this point in the history
  • Loading branch information
lpelypenko committed Oct 29, 2020
1 parent 8934467 commit 08c35e5
Show file tree
Hide file tree
Showing 6 changed files with 5,412 additions and 2,145 deletions.
1 change: 0 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ <h5>
</ol>
</small>
</h5>

<h5>axe-core found <span class="badge badge-warning">85</span> violations</h5>
<table class="table table-striped table-bordered">
<thead>
Expand Down
28 changes: 15 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ export interface ResultsMinimal {
inapplicable?: Result[];
}

export interface CreateReport {
results: AxeResults | ResultsMinimal; // user can decide to pass only 'violations' or full AxeResults object
export interface Options {
reportFileName?: string;
outputDir?: string;
projectKey?: string;
customSummary?: string;
}

export interface CreateReport {
results: AxeResults | ResultsMinimal; // user can decide to pass only 'violations' or full AxeResults object
options?: Options;
}

export interface PreparedResults {
violations: Result[];
passes?: Result[];
Expand All @@ -30,13 +34,7 @@ export interface PreparedResults {
export const missingRequiredParamsError =
"'violations' is required for HTML accessibility report. Example: createHtmlReport({ results : { violations: Result[] } })";

export function createHtmlReport({
results,
reportFileName,
outputDir,
projectKey,
customSummary,
}: CreateReport): void {
export function createHtmlReport({ results, options }: CreateReport): void {
if (!results.violations) {
throw new Error(missingRequiredParamsError);
}
Expand All @@ -49,7 +47,7 @@ export function createHtmlReport({
inapplicable: results.inapplicable,
});
const htmlContent = mustache.render(template, {
url: results.url,
url: results.url || undefined,
violationsSummary: preparedReportData.violationsSummary,
violations: preparedReportData.violationsSummaryTable,
violationDetails: preparedReportData.violationsDetails,
Expand All @@ -62,10 +60,14 @@ export function createHtmlReport({
incompleteTotal: preparedReportData.checksIncomplete
? preparedReportData.checksIncomplete.length
: 0,
projectKey,
customSummary,
projectKey: options?.projectKey,
customSummary: options?.customSummary,
});
saveHtmlReport({
htmlContent,
reportFileName: options?.reportFileName,
outputDir: options?.outputDir,
});
saveHtmlReport({ htmlContent, reportFileName, outputDir });
} catch (e) {
console.warn(`HTML report was not created due to the error ${e.message}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/util/template/pageTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<h3>
AXE Accessibility Results{{#projectKey}} for {{projectKey}} project{{/projectKey}}
</h3>
{{#url}}
<h5>
<small class="text-muted"
>Page URL:
Expand All @@ -67,7 +68,7 @@ <h5>
{{{customSummary}}} {{/customSummary}}
</small>
</h5>

{{/url}}
<h5>{{{violationsSummary}}}</h5>
{{#violationDetails.length}}
<table class="table table-striped table-bordered">
Expand Down
1 change: 0 additions & 1 deletion temp/tcPassesViolationsIncomplete.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ <h5>

</small>
</h5>

<h5>axe-core found <span class="badge badge-warning">85</span> violations</h5>
<table class="table table-striped table-bordered">
<thead>
Expand Down
Loading

0 comments on commit 08c35e5

Please sign in to comment.