-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial update for converter to output sarif v2.1.2 [Part 1] (#45)
*Note: I copied sarif v2 converter files and renamed them with `...-21` to indicate that they are for the new sarif version. These files will be renamed appropriately when the converter is complete, and the old sarif converter v2.0.0 files will be deleted. Currently, the converter still works to convert axe results and raw axe results to sarif v2.0.0.* - Created and modified temporary sarif typings files to support sarif v2.1.2 (`custom-sarif-types-21.ts`, `sarif-2.1.2.ts`, `sarif-log-21.ts`). These files will be replaced when sarif 2.1.2 is available for download from yarn. - Added `simple-axe-results.json` to test-resources to incrementally test converting from simple axe results to sarif v2.1.2. Converting from axe raw results will be done in a later PR. - Generated sarif v2.0.0 (`simple-output-sarifv2.sarif`) from `simple-axe-results.json` and started modifying it in a copy (`simple-output-sarifv21.sarif`) to match the format of sarif v2.1.2. - Created `invocation-provider-21.ts` and corresponding unit test - Created `axe-tool-property-provider-21.ts` and corresponding unit test - Created `converter-property-provider.ts` and corresponding unit test. Note that this doesn't have the `-21` suffix because it was not present in the sarif v2.0.0 converter. - Created and updated `sarif-converter-21.ts` and corresponding test file to use the sarif v2.1.2 typings, `invocation-provider-21`, `axe-tool-property-provider-21`, and `converter-property-provider`.
- Loading branch information
Showing
14 changed files
with
8,704 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { getAxeToolProperties21 } from './axe-tool-property-provider-21'; | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
describe('axe-tool-property-provider 2.1', () => { | ||
describe('getAxeToolProperties21', () => { | ||
it("returns the axe properties as a Sarif.Run['tool']", () => { | ||
const expectedResults: Sarif.Run['tool'] = { | ||
driver: { | ||
name: 'axe-core', | ||
fullName: 'axe for Web v3.2.2', | ||
shortDescription: { | ||
text: | ||
'An open source accessibility rules library for automated testing.', | ||
}, | ||
version: '3.2.2', | ||
semanticVersion: '3.2.2', | ||
informationUri: 'https://www.deque.com/axe/axe-for-web/', | ||
downloadUri: | ||
'https://www.npmjs.com/package/axe-core/v/3.2.2', | ||
properties: { | ||
'microsoft/qualityDomain': 'Accessibility', | ||
}, | ||
supportedTaxonomies: [ | ||
{ | ||
name: 'WCAG', | ||
index: 0, | ||
guid: '', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const actualResults: Sarif.Run['tool'] = getAxeToolProperties21(); | ||
expect(actualResults).toEqual(expectedResults); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
export function getAxeToolProperties21(): Sarif.Run['tool'] { | ||
return { | ||
driver: { | ||
name: 'axe-core', | ||
fullName: 'axe for Web v3.2.2', | ||
shortDescription: { | ||
text: | ||
'An open source accessibility rules library for automated testing.', | ||
}, | ||
version: '3.2.2', | ||
semanticVersion: '3.2.2', | ||
informationUri: 'https://www.deque.com/axe/axe-for-web/', | ||
downloadUri: 'https://www.npmjs.com/package/axe-core/v/3.2.2', | ||
properties: { | ||
'microsoft/qualityDomain': 'Accessibility', | ||
}, | ||
supportedTaxonomies: [ | ||
{ | ||
name: 'WCAG', | ||
index: 0, | ||
guid: '', | ||
}, | ||
], | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { getConverterProperties } from './converter-property-provider'; | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
describe('converter-property-provider', () => { | ||
describe('getConverterProperties', () => { | ||
it('returns the converter properties as a Sarif.Run["conversion"', () => { | ||
const expectedResults: Sarif.Run['conversion'] = { | ||
tool: { | ||
driver: { | ||
name: 'axe-sarif-converter', | ||
fullName: 'axe-sarif-converter v1.3.0', | ||
version: '1.3.0', | ||
semanticVersion: '1.3.0', | ||
informationUri: | ||
'https://github.com/microsoft/axe-sarif-converter/releases/tag/v1.3.0', | ||
downloadUri: | ||
'https://www.npmjs.com/package/axe-sarif-converter/v/1.3.0', | ||
}, | ||
}, | ||
}; | ||
|
||
const actualResults: Sarif.Run['conversion'] = getConverterProperties(); | ||
expect(actualResults).toEqual(expectedResults); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
export function getConverterProperties(): Sarif.Run['conversion'] { | ||
return { | ||
tool: { | ||
driver: { | ||
name: 'axe-sarif-converter', | ||
fullName: 'axe-sarif-converter v1.3.0', | ||
version: '1.3.0', | ||
semanticVersion: '1.3.0', | ||
informationUri: | ||
'https://github.com/microsoft/axe-sarif-converter/releases/tag/v1.3.0', | ||
downloadUri: | ||
'https://www.npmjs.com/package/axe-sarif-converter/v/1.3.0', | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { EnvironmentData } from './environment-data'; | ||
import { getInvocations21 } from './invocation-provider-21'; | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
describe('invocation-provider-2.1', () => { | ||
describe('getInvocations21', () => { | ||
it('populates invocations with data from environmentData parameter', () => { | ||
const environmentDataStub: EnvironmentData = { | ||
targetPageUrl: 'https://example.com', | ||
targetPageTitle: 'Environment Data Stub', | ||
timestamp: '2018-03-23T21:36:58.321Z', | ||
}; | ||
const invocationStub: Sarif.Invocation[] = [ | ||
{ | ||
startTimeUtc: '2018-03-23T21:36:58.321Z', | ||
endTimeUtc: '2018-03-23T21:36:58.321Z', | ||
executionSuccessful: true, | ||
}, | ||
]; | ||
const actualResults: Sarif.Invocation[] = getInvocations21( | ||
environmentDataStub, | ||
); | ||
expect(actualResults).toEqual(invocationStub); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { EnvironmentData } from './environment-data'; | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
export function getInvocations21( | ||
environmentData: EnvironmentData, | ||
): Sarif.Invocation[] { | ||
return [ | ||
{ | ||
startTimeUtc: environmentData.timestamp, | ||
endTimeUtc: environmentData.timestamp, | ||
executionSuccessful: true, | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
import { IMock, It, Mock, Times } from 'typemoq'; | ||
import { getAxeToolProperties21 } from './axe-tool-property-provider-21'; | ||
import { ConverterOptions } from './converter-options'; | ||
import { getConverterProperties } from './converter-property-provider'; | ||
import { DecoratedAxeResults } from './decorated-axe-results'; | ||
import { EnvironmentData } from './environment-data'; | ||
import { getInvocations } from './invocation-provider'; | ||
import { SarifConverter21 } from './sarif-converter-21'; | ||
import * as Sarif from './sarif/sarif-2.1.2'; | ||
|
||
describe('SarifConverter21', () => { | ||
describe('convert', () => { | ||
const stubConverterProperties: Sarif.Run['conversion'] = { | ||
tool: { | ||
driver: { | ||
name: 'stub_converter_property', | ||
}, | ||
}, | ||
}; | ||
const stubToolProperties: Sarif.Run['tool'] = { | ||
driver: { | ||
name: 'stub_tool_property', | ||
}, | ||
}; | ||
const stubInvocations: Sarif.Invocation[] = [ | ||
{ commandLine: 'stub_invocation' }, | ||
]; | ||
const stubTimestamp: string = 'stub_timestamp'; | ||
const stubTargetPageUrl: string = 'stub_url'; | ||
const stubTargetPageTitle: string = 'stub_title'; | ||
const stubEnvironmentData: EnvironmentData = { | ||
timestamp: stubTimestamp, | ||
targetPageUrl: stubTargetPageUrl, | ||
targetPageTitle: stubTargetPageTitle, | ||
}; | ||
const converterPropertyProviderStub: () => Sarif.Run['conversion'] = () => { | ||
return {} as Sarif.Run['conversion']; | ||
}; | ||
const axeToolPropertyProviderStub: () => Sarif.Run['tool'] = () => { | ||
return {} as Sarif.Run['tool']; | ||
}; | ||
const invocationProviderStub: () => Sarif.Invocation[] = () => { | ||
return stubInvocations; | ||
}; | ||
|
||
it('outputs a sarif log whose run uses the axeToolPropertyProvider to populate the tool property', () => { | ||
const axeToolPropertyProviderMock: IMock< | ||
() => Sarif.Run['tool'] | ||
> = Mock.ofInstance(getAxeToolProperties21); | ||
axeToolPropertyProviderMock | ||
.setup(ap => ap()) | ||
.returns(() => stubToolProperties) | ||
.verifiable(Times.once()); | ||
|
||
const irrelevantResults: DecoratedAxeResults = {} as DecoratedAxeResults; | ||
const irrelevantOptions: ConverterOptions = {}; | ||
|
||
const testSubject = new SarifConverter21( | ||
converterPropertyProviderStub, | ||
axeToolPropertyProviderMock.object, | ||
invocationProviderStub, | ||
); | ||
|
||
const actualResults = testSubject.convert( | ||
irrelevantResults, | ||
irrelevantOptions, | ||
); | ||
|
||
axeToolPropertyProviderMock.verifyAll(); | ||
expect(actualResults).toHaveProperty('runs'); | ||
expect(actualResults.runs[0]).toHaveProperty( | ||
'tool', | ||
stubToolProperties, | ||
); | ||
}); | ||
|
||
it('outputs a sarif log whose run uses the invocationsProvider to populate the invocations property', () => { | ||
const stubResults: DecoratedAxeResults = { | ||
timestamp: stubTimestamp, | ||
targetPageUrl: stubTargetPageUrl, | ||
targetPageTitle: stubTargetPageTitle, | ||
passes: [], | ||
violations: [], | ||
inapplicable: [], | ||
incomplete: [], | ||
}; | ||
const irrelevantOptions: ConverterOptions = {}; | ||
|
||
const invocationProviderMock: IMock< | ||
(environmentData: EnvironmentData) => Sarif.Invocation[] | ||
> = Mock.ofInstance(getInvocations); | ||
invocationProviderMock | ||
.setup(ip => | ||
ip(It.isObjectWith<EnvironmentData>(stubEnvironmentData)), | ||
) | ||
.returns(() => stubInvocations) | ||
.verifiable(Times.once()); | ||
|
||
const testSubject = new SarifConverter21( | ||
converterPropertyProviderStub, | ||
axeToolPropertyProviderStub, | ||
invocationProviderMock.object, | ||
); | ||
|
||
const actualResults = testSubject.convert( | ||
stubResults, | ||
irrelevantOptions, | ||
); | ||
|
||
invocationProviderMock.verifyAll(); | ||
expect(actualResults).toHaveProperty('runs'); | ||
expect(actualResults.runs[0]).toHaveProperty( | ||
'invocations', | ||
stubInvocations, | ||
); | ||
}); | ||
|
||
it('outputs a sarif log whose run uses the converterPropertyProvider to populate the conversion property', () => { | ||
const converterPropertyProviderMock: IMock< | ||
() => Sarif.Run['conversion'] | ||
> = Mock.ofInstance(getConverterProperties); | ||
converterPropertyProviderMock | ||
.setup(cp => cp()) | ||
.returns(() => stubConverterProperties) | ||
.verifiable(Times.once()); | ||
|
||
const irrelevantResults: DecoratedAxeResults = {} as DecoratedAxeResults; | ||
const irrelevantOptions: ConverterOptions = {}; | ||
|
||
const testSubject = new SarifConverter21( | ||
converterPropertyProviderMock.object, | ||
axeToolPropertyProviderStub, | ||
invocationProviderStub, | ||
); | ||
|
||
const actualResults = testSubject.convert( | ||
irrelevantResults, | ||
irrelevantOptions, | ||
); | ||
|
||
converterPropertyProviderMock.verifyAll(); | ||
expect(actualResults).toHaveProperty('runs'); | ||
expect(actualResults.runs[0]).toHaveProperty( | ||
'conversion', | ||
stubConverterProperties, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.