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

feat(pr-baseline-2): Modify ADO PR comments to include baseline info #909

Merged
merged 22 commits into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7c565a6
fix typings in test file
lisli1 Oct 8, 2021
f6133ea
add BaselineEvaluation to comment creator and markdown convertor/buil…
lisli1 Oct 8, 2021
ac11766
add baselineFIleName as a parameter to buildContent
lisli1 Oct 8, 2021
50a1f47
update tests
lisli1 Oct 9, 2021
1fd55a3
initial additions for result-markdown-builder for pr comments with ba…
lisli1 Oct 19, 2021
2f900ad
trying out new format of pr comments for both baseline and non-baseli…
lisli1 Oct 20, 2021
f9159a2
update snapshots
lisli1 Oct 20, 2021
aa53b21
revert axe-descriptions.snap.md
lisli1 Oct 22, 2021
a530ae7
update scenarios with baseline
lisli1 Oct 22, 2021
0be46f3
add canBaseline param to determine if baselining is available before …
lisli1 Oct 22, 2021
e6a2bfd
Merge branch 'main' of github.com:microsoft/accessibility-insights-ac…
lisli1 Oct 22, 2021
63da95d
fix ado-pull-request-comment-creator test
lisli1 Oct 22, 2021
fbd7824
ran format:fix
lisli1 Oct 22, 2021
e7a22aa
remove unused import
lisli1 Oct 22, 2021
cb1b40c
simplify baseline params to baselineInfo
lisli1 Oct 23, 2021
382bf9b
ran format:fix
lisli1 Oct 23, 2021
2275aad
reduce number of parameters for baselineInfo in baselineDetails function
lisli1 Oct 23, 2021
f1159cc
totalBaselineViolations is optional
lisli1 Oct 25, 2021
88c6770
refactor based on pr comment
lisli1 Oct 25, 2021
ab79e19
Merge branch 'lisli1/pr-comment-baseline' of github.com:microsoft/acc…
lisli1 Oct 25, 2021
2de2d78
change wording of case when there are no new failures
lisli1 Oct 26, 2021
5be4209
update snapshot
lisli1 Oct 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,7 +7,7 @@ import * as GitApi from 'azure-devops-node-api/GitApi';
import * as nodeApi from 'azure-devops-node-api';
import * as GitInterfaces from 'azure-devops-node-api/interfaces/GitInterfaces';

import { It, Mock, Times, IMock, MockBehavior } from 'typemoq';
import { Mock, Times, IMock, MockBehavior } from 'typemoq';
import {
AdoPullRequestCommentCreator as ADOPullRequestCommentCreator,
AdoPullRequestCommentCreator,
Expand All @@ -17,6 +17,7 @@ import { CombinedReportParameters } from 'accessibility-insights-report';

import { Logger, ReportMarkdownConvertor } from '@accessibility-insights-action/shared';
import { BaselineEvaluation, BaselineFileContent } from '@accessibility-insights-action/shared/dist/baseline-types';
import { BaselineInfo } from '@accessibility-insights-action/shared/dist/baseline-info';

describe(ADOPullRequestCommentCreator, () => {
let adoTaskMock: IMock<typeof adoTask>;
Expand Down Expand Up @@ -193,6 +194,7 @@ describe(ADOPullRequestCommentCreator, () => {
gitApiMock.setup((o) => o.createThread(newThread, repoId, prId)).verifiable(Times.once());
setupIsSupportedReturnsTrue();
setupFailOnAccessibilityError(false);
setupBaselineFileParameterDoesNotExist();
setupInitializeWithoutServiceConnectionName();
setupInitializeSetConnection(webApiMock.object);
prCommentCreator = buildPrCommentCreatorWithMocks();
Expand All @@ -217,6 +219,7 @@ describe(ADOPullRequestCommentCreator, () => {
gitApiMock.setup((o) => o.createComment(newComment, repoId, prId, threadId)).verifiable(Times.once());
setupIsSupportedReturnsTrue();
setupFailOnAccessibilityError(true);
setupBaselineFileParameterDoesNotExist();
setupInitializeWithoutServiceConnectionName();
setupInitializeSetConnection(webApiMock.object);
prCommentCreator = buildPrCommentCreatorWithMocks();
Expand Down Expand Up @@ -244,6 +247,7 @@ describe(ADOPullRequestCommentCreator, () => {
gitApiMock.setup((o) => o.updateComment(expectedComment, repoId, prId, threadId, commentId)).verifiable(Times.once());
setupIsSupportedReturnsTrue();
setupFailOnAccessibilityError(true);
setupBaselineFileParameterDoesNotExist();
setupInitializeWithoutServiceConnectionName();
setupInitializeSetConnection(webApiMock.object);
prCommentCreator = buildPrCommentCreatorWithMocks();
Expand All @@ -263,15 +267,25 @@ describe(ADOPullRequestCommentCreator, () => {
const baselineEvaluationStub = {
suggestedBaselineUpdate: {} as BaselineFileContent,
} as BaselineEvaluation;
const baselineInfo: BaselineInfo = {
baselineFileName: 'baseline-file',
baselineEvaluation: baselineEvaluationStub,
};

setupReturnPrThread(repoId, prId, reportStub, reportMd, threadsStub);
reportMarkdownConvertorMock.reset();
reportMarkdownConvertorMock
.setup((o) => o.convert(reportStub, ADOPullRequestCommentCreator.CURRENT_COMMENT_TITLE, baselineInfo))
.returns(() => ADOPullRequestCommentCreator.CURRENT_COMMENT_TITLE + reportMd)
.verifiable(Times.once());
loggerMock.setup((o) => o.logInfo(`Didn't find an existing thread, making a new thread`)).verifiable(Times.once());
gitApiMock.setup((o) => o.createThread(newThread, repoId, prId)).verifiable(Times.once());
setupIsSupportedReturnsTrue();
setupFailOnAccessibilityError(false);
setupBaselineFileParameterExists();
setupInitializeWithoutServiceConnectionName();
setupInitializeSetConnection(webApiMock.object);

prCommentCreator = buildPrCommentCreatorWithMocks();

await expect(prCommentCreator.completeRun(reportStub, baselineEvaluationStub)).rejects.toThrowError(
Expand Down Expand Up @@ -342,7 +356,14 @@ describe(ADOPullRequestCommentCreator, () => {
const setupBaselineFileParameterExists = () => {
adoTaskConfigMock
.setup((o) => o.getBaselineFile())
.returns(() => It.isAnyString())
.returns(() => 'baseline-file')
.verifiable(Times.atLeastOnce());
};

const setupBaselineFileParameterDoesNotExist = () => {
adoTaskConfigMock
.setup((o) => o.getBaselineFile())
.returns(() => undefined)
.verifiable(Times.atLeastOnce());
};

Expand Down Expand Up @@ -488,8 +509,9 @@ describe(ADOPullRequestCommentCreator, () => {
threadsStub: GitInterfaces.GitPullRequestCommentThread[],
) => {
makeGitApiMockThenable();
const baselineInfoStub = {};
reportMarkdownConvertorMock
.setup((o) => o.convert(reportStub, ADOPullRequestCommentCreator.CURRENT_COMMENT_TITLE))
.setup((o) => o.convert(reportStub, ADOPullRequestCommentCreator.CURRENT_COMMENT_TITLE, baselineInfoStub))
.returns(() => ADOPullRequestCommentCreator.CURRENT_COMMENT_TITLE + reportMd)
.verifiable(Times.once());
adoTaskMock
Expand Down
Expand Up @@ -14,6 +14,7 @@ import * as GitApi from 'azure-devops-node-api/GitApi';
import * as GitInterfaces from 'azure-devops-node-api/interfaces/GitInterfaces';
import * as VsoBaseInterfaces from 'azure-devops-node-api/interfaces/common/VsoBaseInterfaces';
import { BaselineEvaluation, BaselineFileContent } from '@accessibility-insights-action/shared/src/baseline-types';
import { BaselineInfo } from '@accessibility-insights-action/shared/src/baseline-info';

@injectable()
export class AdoPullRequestCommentCreator extends ProgressReporter {
Expand Down Expand Up @@ -97,6 +98,7 @@ export class AdoPullRequestCommentCreator extends ProgressReporter {
const reportMarkdown = this.reportMarkdownConvertor.convert(
combinedReportResult,
AdoPullRequestCommentCreator.CURRENT_COMMENT_TITLE,
this.getBaselineInfo(baselineEvaluation),
);
this.traceMarkdown(reportMarkdown);

Expand Down Expand Up @@ -175,6 +177,16 @@ export class AdoPullRequestCommentCreator extends ProgressReporter {
throw message;
}

private getBaselineInfo(baselineEvaluation?: BaselineEvaluation): BaselineInfo {
const baselineFileName = this.adoTaskConfig.getBaselineFile();

if (!baselineFileName) {
return {} as BaselineInfo;
}

return { baselineFileName, baselineEvaluation };
}

private failOnAccessibilityError(combinedReportResult: CombinedReportParameters): void {
if (this.adoTaskConfig.getFailOnAccessibilityError() && combinedReportResult.results.urlResults.failedUrls > 0) {
throw new Error('Failed Accessibility Error');
Expand Down
9 changes: 9 additions & 0 deletions packages/shared/src/baseline-info.ts
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { BaselineEvaluation } from './baseline-types';

export type BaselineInfo = {
baselineFileName?: string;
baselineEvaluation?: BaselineEvaluation;
};
1 change: 1 addition & 0 deletions packages/shared/src/baseline-types.ts
Expand Up @@ -24,6 +24,7 @@ export type BaselineEvaluation = {
fixedViolationsByRule: CountsByRule;
totalNewViolations: number;
totalFixedViolations: number;
totalBaselineViolations?: number;
};

export type BaselineResult = {
Expand Down
Expand Up @@ -39,3 +39,170 @@ You can review the log to troubleshoot the issue. Fix it and re-run the workflow
---
"
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are baseline failures and new failures 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action

**4 failure instances not in baseline**
* (3) **rule id**: rule description
* (1) **rule id 2**: rule description 2

**1 failure instances in baseline**
(not shown; see [baselining docs](temporarily-empty) for how to include new failures into the baseline)

See all failures and scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 5 with failures, 1 passed, 7 not scannable
**Rules**: 4 with failures, 1 passed, 2 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are baseline failures and no new failures 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action
**:white_check_mark: No failures not in baseline**
No failures were detected by automatic scanning except those which exist in the baseline.

**:point_right: Next step:** Manually assess keyboard accessibility with [Accessibility Insights Tab Stops](https://accessibilityinsights.io/docs/en/web/getstarted/fastpass/#complete-the-manual-test-for-tab-stops)

**1 failure instances in baseline**
(not shown; see [baselining docs](temporarily-empty))

See all failures and scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 0 with failures, 0 passed, 0 not scannable
**Rules**: 0 with failures, 0 passed, 0 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are new failures and no baseline detected 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action

**4 failure instances**
* (3) **rule id**: rule description
* (1) **rule id 2**: rule description 2

**Baseline not detected**
To update the baseline with these changes, copy the updated baseline file to [scan arguments](temporarily-empty). See [baselining docs](temporarily-empty) for more.

See all failures and scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 5 with failures, 1 passed, 7 not scannable
**Rules**: 4 with failures, 1 passed, 2 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are new failures and no baseline failures 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action

**4 failure instances**
* (3) **rule id**: rule description
* (1) **rule id 2**: rule description 2

**Baseline not detected**
To update the baseline with these changes, copy the updated baseline file to [scan arguments](temporarily-empty). See [baselining docs](temporarily-empty) for more.

See all failures and scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 5 with failures, 1 passed, 7 not scannable
**Rules**: 4 with failures, 1 passed, 2 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are no baseline failures and no new failures 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action
**:white_check_mark: No failures detected**
No failures were detected by automatic scanning.

**:point_right: Next step:** Manually assess keyboard accessibility with [Accessibility Insights Tab Stops](https://accessibilityinsights.io/docs/en/web/getstarted/fastpass/#complete-the-manual-test-for-tab-stops)



See scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 0 with failures, 1 passed, 7 not scannable
**Rules**: 0 with failures, 1 passed, 2 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are no new failures and baseline failures are undefined 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action
**:white_check_mark: No failures detected**
No failures were detected by automatic scanning.

**:point_right: Next step:** Manually assess keyboard accessibility with [Accessibility Insights Tab Stops](https://accessibilityinsights.io/docs/en/web/getstarted/fastpass/#complete-the-manual-test-for-tab-stops)

**Baseline not configured**
A baseline lets you mark known failures so it's easier to identify new failures as they're introduced. See [baselining docs](temporarily-empty) for more.

See scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 0 with failures, 0 passed, 0 not scannable
**Rules**: 0 with failures, 0 passed, 0 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there are no new failures and no baseline detected 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action
**:white_check_mark: No failures detected**
No failures were detected by automatic scanning.

**:point_right: Next step:** Manually assess keyboard accessibility with [Accessibility Insights Tab Stops](https://accessibilityinsights.io/docs/en/web/getstarted/fastpass/#complete-the-manual-test-for-tab-stops)

**Baseline not detected**
To update the baseline with these changes, copy the updated baseline file to [scan arguments](temporarily-empty). See [baselining docs](temporarily-empty) for more.

See all failures and scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 0 with failures, 0 passed, 0 not scannable
**Rules**: 0 with failures, 0 passed, 0 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;

exports[`ResultMarkdownBuilder with baseline builds content when there is no baseline configured 1`] = `
"### ![Accessibility Insights](https://accessibilityinsights.io/img/a11yinsights-blue.svg) Accessibility Insights Action

**4 failure instances**
* (3) **rule id**: rule description
* (1) **rule id 2**: rule description 2

**Baseline not configured**
A baseline lets you mark known failures so it's easier to identify new failures as they're introduced. See [baselining docs](temporarily-empty) for more.

See all failures and scan details by downloading the report from [run artifacts](temporarily-empty)

---
#### Scan summary
**URLs**: 5 with failures, 1 passed, 7 not scannable
**Rules**: 4 with failures, 1 passed, 2 not applicable

---
This scan used [axe-core axeVersion](https://github.com/dequelabs/axe-core/releases/tag/vaxeVersion) with userAgent."
`;
29 changes: 21 additions & 8 deletions packages/shared/src/mark-down/report-markdown-convertor.spec.ts
Expand Up @@ -6,6 +6,7 @@ import { IMock, Mock } from 'typemoq';
import { ReportMarkdownConvertor } from './report-markdown-convertor';
import { ResultMarkdownBuilder } from './result-markdown-builder';
import { CombinedReportParameters } from 'accessibility-insights-report';
import { BaselineEvaluation } from '../baseline-types';

describe(ReportMarkdownConvertor, () => {
let resultMarkdownBuilderMock: IMock<ResultMarkdownBuilder>;
Expand Down Expand Up @@ -34,17 +35,29 @@ describe(ReportMarkdownConvertor, () => {
expect(reportMarkdownConvertor).not.toBeNull();
});

it('convert report', () => {
resultMarkdownBuilderMock.setup((o) => o.buildContent(combinedReportResult, undefined)).verifiable();
describe('convert', () => {
it('report', () => {
resultMarkdownBuilderMock.setup((o) => o.buildContent(combinedReportResult, undefined, undefined)).verifiable();

reportMarkdownConvertor.convert(combinedReportResult);
});
reportMarkdownConvertor.convert(combinedReportResult);
});

it('report with title', () => {
const title = 'some title';
resultMarkdownBuilderMock.setup((o) => o.buildContent(combinedReportResult, title, undefined)).verifiable();

reportMarkdownConvertor.convert(combinedReportResult, title);
});

it('convert report with title', () => {
const title = 'some title';
resultMarkdownBuilderMock.setup((o) => o.buildContent(combinedReportResult, title)).verifiable();
it('report with baseline', () => {
const baselineInfo = {
baselineFileName: 'some filename',
baselineEvaluationStub: {} as BaselineEvaluation,
};
resultMarkdownBuilderMock.setup((o) => o.buildContent(combinedReportResult, undefined, baselineInfo)).verifiable();

reportMarkdownConvertor.convert(combinedReportResult, title);
reportMarkdownConvertor.convert(combinedReportResult, undefined, baselineInfo);
});
});

it('get error markdown', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/mark-down/report-markdown-convertor.ts
Expand Up @@ -4,13 +4,14 @@
import { inject, injectable } from 'inversify';
import { ResultMarkdownBuilder } from './result-markdown-builder';
import { CombinedReportParameters } from 'accessibility-insights-report';
import { BaselineInfo } from '../baseline-info';

@injectable()
export class ReportMarkdownConvertor {
constructor(@inject(ResultMarkdownBuilder) private readonly checkResultMarkdownBuilder: ResultMarkdownBuilder) {}

public convert(combinedReportResult: CombinedReportParameters, title?: string): string {
return this.checkResultMarkdownBuilder.buildContent(combinedReportResult, title);
public convert(combinedReportResult: CombinedReportParameters, title?: string, baselineInfo?: BaselineInfo): string {
return this.checkResultMarkdownBuilder.buildContent(combinedReportResult, title, baselineInfo);
}

public getErrorMarkdown(): string {
Expand Down