Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting time of data gathering in middleware reporter #268

Merged
merged 4 commits into from
Jun 11, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions addon-test-support/setup-middleware-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@ export const TEST_SUITE_RESULTS: AxeTestResult[] = [];

let currentTestResult: AxeTestResult | undefined = undefined;
let currentViolationsMap: Map<string, Result> | undefined = undefined;
let currentUrls = new Set<string>();
let currentRouteNames = new Set<string>();
let currentUrls: Set<string> | undefined;
let currentRouteNames: Set<string> | undefined;
let currentTestHelpers: Set<string> | undefined;

/**
* A custom reporter that is invoke once per failed a11yAudit call. This can be called
scalvert marked this conversation as resolved.
Show resolved Hide resolved
* multiple times per test, and the results are accumulated until testDone.
*
* @param axeResults The axe results for each a11yAudit.
* @returns Early returns if no violations are found.
*/
export async function middlewareReporter(axeResults: AxeResults) {
if (axeResults.violations.length === 0) {
return;
}

let testMetaData = getTestMetadata(getContext());
scalvert marked this conversation as resolved.
Show resolved Hide resolved

if (!currentTestResult) {
let { module, testName } = QUnit.config.current;
let testMetaData = getTestMetadata(getContext());

let stack = (!DEBUG && new Error().stack) || '';

Expand All @@ -42,16 +51,23 @@ export async function middlewareReporter(axeResults: AxeResults) {
testName,
urls: [],
routes: [],
helpers: testMetaData.usedHelpers,
helpers: [],
stack,
violations: [],
};

currentViolationsMap = new Map();
currentUrls = new Set();
currentRouteNames = new Set();
currentTestHelpers = new Set();
}

currentUrls.add(currentURL());
currentRouteNames.add(currentRouteName());
currentTestHelpers = new Set([
...currentTestHelpers!.values(),
...testMetaData.usedHelpers,
scalvert marked this conversation as resolved.
Show resolved Hide resolved
]);
currentUrls!.add(currentURL());
currentRouteNames!.add(currentRouteName());

axeResults.violations.forEach((violation) => {
let rule = currentViolationsMap!.get(violation.id);
Expand All @@ -64,15 +80,24 @@ export async function middlewareReporter(axeResults: AxeResults) {
});
}

/**
* Invoked once per test. Accumulates the results into a set of results used for
* reporting via the middleware reporter.
*/
export function pushTestResult() {
if (typeof currentTestResult !== 'undefined') {
currentTestResult.violations = [...currentViolationsMap!.values()];
currentTestResult.urls = [...currentUrls.values()];
currentTestResult.routes = [...currentRouteNames.values()];
currentTestResult.urls = [...currentUrls!.values()];
currentTestResult.routes = [...currentRouteNames!.values()];
currentTestResult.helpers = [...currentTestHelpers!.values()];

TEST_SUITE_RESULTS.push(currentTestResult);

currentTestResult = undefined;
currentViolationsMap = undefined;
currentUrls = undefined;
currentRouteNames = undefined;
currentTestHelpers = undefined;
}
}

Expand Down