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(mvp-ado-extension-behavior): Add optional inputs to task.json and config #823

Merged
merged 5 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 29 additions & 13 deletions packages/ado-extension/src/task-config/ado-task-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ describe(ADOTaskConfig, () => {
}

it.each`
inputOption | inputValue | expectedValue | getInputFunc
${'repoToken'} | ${'token'} | ${'token'} | ${() => taskConfig.getToken()}
${'scanUrlRelativePath'} | ${'path'} | ${'path'} | ${() => taskConfig.getScanUrlRelativePath()}
${'chromePath'} | ${'./chromePath'} | ${getPlatformAgnosticPath(__dirname + '/chromePath')} | ${() => taskConfig.getChromePath()}
${'inputFile'} | ${'./inputFile'} | ${getPlatformAgnosticPath(__dirname + '/inputFile')} | ${() => taskConfig.getInputFile()}
${'outputDir'} | ${'./outputDir'} | ${getPlatformAgnosticPath(__dirname + '/outputDir')} | ${() => taskConfig.getReportOutDir()}
${'siteDir'} | ${'path'} | ${'path'} | ${() => taskConfig.getSiteDir()}
${'url'} | ${'url'} | ${'url'} | ${() => taskConfig.getUrl()}
${'discoveryPatterns'} | ${'abc'} | ${'abc'} | ${() => taskConfig.getDiscoveryPatterns()}
${'inputUrls'} | ${'abc'} | ${'abc'} | ${() => taskConfig.getInputUrls()}
${'maxUrls'} | ${'20'} | ${20} | ${() => taskConfig.getMaxUrls()}
${'scanTimeout'} | ${'100000'} | ${100000} | ${() => taskConfig.getScanTimeout()}
${'localhostPort'} | ${'8080'} | ${8080} | ${() => taskConfig.getLocalhostPort()}
inputOption | inputValue | expectedValue | getInputFunc
${'repoToken'} | ${'token'} | ${'token'} | ${() => taskConfig.getToken()}
${'scanUrlRelativePath'} | ${'path'} | ${'path'} | ${() => taskConfig.getScanUrlRelativePath()}
${'chromePath'} | ${'./chromePath'} | ${getPlatformAgnosticPath(__dirname + '/chromePath')} | ${() => taskConfig.getChromePath()}
${'inputFile'} | ${'./inputFile'} | ${getPlatformAgnosticPath(__dirname + '/inputFile')} | ${() => taskConfig.getInputFile()}
${'outputDir'} | ${'./outputDir'} | ${getPlatformAgnosticPath(__dirname + '/outputDir')} | ${() => taskConfig.getReportOutDir()}
${'siteDir'} | ${'path'} | ${'path'} | ${() => taskConfig.getSiteDir()}
${'url'} | ${'url'} | ${'url'} | ${() => taskConfig.getUrl()}
${'discoveryPatterns'} | ${'abc'} | ${'abc'} | ${() => taskConfig.getDiscoveryPatterns()}
${'inputUrls'} | ${'abc'} | ${'abc'} | ${() => taskConfig.getInputUrls()}
${'maxUrls'} | ${'20'} | ${20} | ${() => taskConfig.getMaxUrls()}
${'scanTimeout'} | ${'100000'} | ${100000} | ${() => taskConfig.getScanTimeout()}
${'localhostPort'} | ${'8080'} | ${8080} | ${() => taskConfig.getLocalhostPort()}
${'repoServiceConnectionName'} | ${'testName'} | ${'testName'} | ${() => taskConfig.getRepoServiceConnectionName()}
`(
`input value '$inputValue' returned as '$expectedValue' for '$inputOption' parameter`,
({ inputOption, getInputFunc, inputValue, expectedValue }) => {
Expand All @@ -55,6 +56,21 @@ describe(ADOTaskConfig, () => {
},
);

it.each`
inputOption | inputValue | expectedValue | getInputFunc
${'failOnAccessibilityError'} | ${true} | ${true} | ${() => taskConfig.getFailOnAccessibilityError()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is only one test case in this .each test. Do you see this test having more test cases in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, I mostly wanted this to read similarly to the above test case because they are doing almost the same thing.

`(
`bool input value '$inputValue' returned as '$expectedValue' for '$inputOption' parameter`,
({ inputOption, getInputFunc, inputValue, expectedValue }) => {
adoTaskMock
.setup((am) => am.getBoolInput(inputOption))
.returns(() => inputValue)
.verifiable(Times.once());
const retrievedOption = getInputFunc();
expect(retrievedOption).toStrictEqual(expectedValue);
},
);

it('should use environment value when chrome-path input is undefined', () => {
const chromePath = 'some path';
processStub = {
Expand Down
8 changes: 8 additions & 0 deletions packages/ado-extension/src/task-config/ado-task-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export class ADOTaskConfig extends TaskConfig {
return parseInt(this.processObj.env.BUILD_BUILDID, 10);
}

public getRepoServiceConnectionName(): string {
return this.adoTaskObj.getInput('repoServiceConnectionName');
}

public getFailOnAccessibilityError(): boolean {
return this.adoTaskObj.getBoolInput('failOnAccessibilityError');
}

private getAbsolutePath(path: string): string {
if (isEmpty(path)) {
return undefined;
Expand Down
8 changes: 8 additions & 0 deletions packages/ado-extension/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
"defaultValue": "90000",
"required": false,
"helpMarkDown": "The maximum timeout in milliseconds for the scan (excluding dependency setup)."
},
{
"name": "failOnAccessibilityError",
"type": "boolean",
"label": "Fail on Accessibility Error",
"defaultValue": false,
"required": false,
"helpMarkDown": "Fail the task if there are accessibility issues."
}
],
"execution": {
Expand Down