generated from finos-labs/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from lbulanti-ms/issue-98-junit-report
Issue 98 - create test report in JUnit format
- Loading branch information
Showing
10 changed files
with
457 additions
and
63 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
116 changes: 116 additions & 0 deletions
116
cli/src/commands/validate/junit-report/junit.report.spec.ts
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,116 @@ | ||
import { ValidationOutput } from '../validation.output'; | ||
import createJUnitReport from './junit.report'; | ||
|
||
const jsonSchemaValidationOutput: ValidationOutput[] = [ | ||
new ValidationOutput( | ||
'json-schema', | ||
'error', | ||
'must be integer', | ||
'/path/to/node', | ||
'#/node' | ||
) | ||
]; | ||
|
||
const spectralValidationOutput: ValidationOutput[] = [ | ||
new ValidationOutput( | ||
'no-empty-properties', | ||
'error', | ||
'Must not contain string properties set to the empty string or numerical properties set to zero', | ||
'/relationships/0/relationship-type/connects/destination/interface' | ||
), | ||
new ValidationOutput( | ||
'no-placeholder-properties-numerical', | ||
'warning', | ||
'Numerical placeholder (-1) detected in instantiated pattern.', | ||
'/nodes/0/interfaces/0/port' | ||
) | ||
]; | ||
|
||
const ruleset = ['rules-number-1', 'rule-number-2', 'no-placeholder-properties-numerical', 'no-empty-properties']; | ||
|
||
|
||
describe('createJUnitReport', () => { | ||
it('should create a report with only JSON Schema Validations errors', async () => { | ||
const actual = createJUnitReport(jsonSchemaValidationOutput, [], ruleset); | ||
|
||
const expected = `<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites tests="5" failures="1" errors="0" skipped="0"> | ||
<testsuite name="JSON Schema Validation" tests="1" failures="1" errors="0" skipped="0"> | ||
<testcase name="must be integer at #/node"> | ||
<failure/> | ||
</testcase> | ||
</testsuite> | ||
<testsuite name="Spectral Suite" tests="4" failures="0" errors="0" skipped="0"> | ||
<testcase name="rules-number-1"/> | ||
<testcase name="rule-number-2"/> | ||
<testcase name="no-placeholder-properties-numerical"/> | ||
<testcase name="no-empty-properties"/> | ||
</testsuite> | ||
</testsuites>`; | ||
|
||
expect(actual.replace(/\s/g, '')).toBe(expected.replace(/\s/g, '')); | ||
}); | ||
|
||
it('should create a report with only Spectral issues', async () => { | ||
const actual = createJUnitReport([], spectralValidationOutput, ruleset); | ||
|
||
const expected = `<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites tests="5" failures="1" errors="0" skipped="0"> | ||
<testsuite name="JSON Schema Validation" tests="1" failures="0" errors="0" skipped="0"> | ||
<testcase name="JSON Schema Validation succeeded"/> | ||
</testsuite> | ||
<testsuite name="Spectral Suite" tests="4" failures="1" errors="0" skipped="0"> | ||
<testcase name="rules-number-1"/> | ||
<testcase name="rule-number-2"/> | ||
<testcase name="no-placeholder-properties-numerical"/> | ||
<testcase name="no-empty-properties"> | ||
<failure/> | ||
</testcase> | ||
</testsuite> | ||
</testsuites>`; | ||
expect(actual.replace(/\s/g, '')).toBe(expected.replace(/\s/g, '')); | ||
|
||
}); | ||
|
||
it('should create a report with Spectral issues and JSON Schema errors', async () => { | ||
const actual = createJUnitReport(jsonSchemaValidationOutput, spectralValidationOutput, ruleset); | ||
|
||
const expected = `<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites tests="5" failures="2" errors="0" skipped="0"> | ||
<testsuite name="JSON Schema Validation" tests="1" failures="1" errors="0" skipped="0"> | ||
<testcase name="must be integer at #/node"> | ||
<failure/> | ||
</testcase> | ||
</testsuite> | ||
<testsuite name="Spectral Suite" tests="4" failures="1" errors="0" skipped="0"> | ||
<testcase name="rules-number-1"/> | ||
<testcase name="rule-number-2"/> | ||
<testcase name="no-placeholder-properties-numerical"/> | ||
<testcase name="no-empty-properties"> | ||
<failure/> | ||
</testcase> | ||
</testsuite> | ||
</testsuites>`; | ||
expect(actual.replace(/\s/g, '')).toBe(expected.replace(/\s/g, '')); | ||
}); | ||
|
||
it('should create a report with no Spectral issues and no JSON Schema errors', async () => { | ||
const actual = createJUnitReport([], [], ruleset); | ||
|
||
const expected = `<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites tests="5" failures="0" errors="0" skipped="0"> | ||
<testsuite name="JSON Schema Validation" tests="1" failures="0" errors="0" skipped="0"> | ||
<testcase name="JSON Schema Validation succeeded"/> | ||
</testsuite> | ||
<testsuite name="Spectral Suite" tests="4" failures="0" errors="0" skipped="0"> | ||
<testcase name="rules-number-1"/> | ||
<testcase name="rule-number-2"/> | ||
<testcase name="no-placeholder-properties-numerical"/> | ||
<testcase name="no-empty-properties"/> | ||
</testsuite> | ||
</testsuites>`; | ||
|
||
expect(actual.replace(/\s/g, '')).toBe(expected.replace(/\s/g, '')); | ||
}); | ||
|
||
}); |
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,55 @@ | ||
import junitReportBuilder, { TestSuite } from 'junit-report-builder'; | ||
import { ValidationOutput } from '../validation.output'; | ||
|
||
export default function createJUnitReport( | ||
jsonSchemaValidationOutput: ValidationOutput[], | ||
spectralValidationOutput: ValidationOutput[], | ||
spectralRulesName: string[] | ||
): string { | ||
const builder = junitReportBuilder.newBuilder(); | ||
|
||
const jsonSchemaSuite = createTestSuite(builder, 'JSON Schema Validation'); | ||
|
||
if (jsonSchemaValidationOutput.length <= 0) { | ||
createSucceedingTestCase(jsonSchemaSuite, 'JSON Schema Validation succeeded'); | ||
} else { | ||
jsonSchemaValidationOutput.forEach(jsonSchemaError => { | ||
const testName = `${jsonSchemaError.message} at ${jsonSchemaError.schemaPath}`; | ||
createFailingTestCase(jsonSchemaSuite, testName); | ||
}); | ||
} | ||
|
||
const spectralSuite = createTestSuite(builder, 'Spectral Suite'); | ||
|
||
if (spectralValidationOutput.length <= 0) { | ||
spectralRulesName.forEach(ruleName => createSucceedingTestCase(spectralSuite,ruleName)); | ||
} else { | ||
spectralRulesName.forEach(ruleName => { | ||
if (spectralValidationOutput.filter(item => (item.code === ruleName) && item.severity === 'error').length > 0) { | ||
createFailingTestCase(spectralSuite, ruleName); | ||
} else { | ||
createSucceedingTestCase(spectralSuite, ruleName); | ||
} | ||
}); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
function createTestSuite(builder, testSuiteName: string){ | ||
return builder | ||
.testSuite() | ||
.name(testSuiteName); | ||
} | ||
|
||
function createSucceedingTestCase(testSuite: TestSuite, testName: string){ | ||
testSuite.testCase() | ||
.name(testName); | ||
} | ||
|
||
function createFailingTestCase(testSuite: TestSuite, testName: string){ | ||
testSuite.testCase() | ||
.name(testName) | ||
.failure(); | ||
} | ||
|
Oops, something went wrong.