-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rudimentary test coverage counting paths being tested. (#443)
* Added test coverage. Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
23 changed files
with
380 additions
and
44 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 |
---|---|---|
|
@@ -47,6 +47,7 @@ aarch | |
actiongroup | ||
actiongroups | ||
aggregatable | ||
argjson | ||
asciifolding | ||
authc | ||
authinfo | ||
|
8 changes: 8 additions & 0 deletions
8
.github/pr-comment-templates/pr-test-coverage-analysis.template.md
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,8 @@ | ||
## Spec Test Coverage Analysis | ||
{{with .test_coverage}} | ||
|
||
| Total | Tested | | ||
|-------------------|----------------------------------------------------------| | ||
| {{.paths_count}} | {{.evaluated_paths_count}} ({{.evaluated_paths_pct}} %) | | ||
|
||
{{end}} |
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
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
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
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
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
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
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
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,48 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import _ from "lodash"; | ||
import MergedOpenApiSpec from "./MergedOpenApiSpec"; | ||
import { StoryEvaluations } from "./types/eval.types"; | ||
import { SpecTestCoverage } from "./types/test.types"; | ||
import { write_json } from "../helpers"; | ||
|
||
export default class TestResults { | ||
protected _spec: MergedOpenApiSpec | ||
protected _evaluations: StoryEvaluations | ||
|
||
constructor(spec: MergedOpenApiSpec, evaluations: StoryEvaluations) { | ||
this._spec = spec | ||
this._evaluations = evaluations | ||
} | ||
|
||
evaluated_paths_count(): number { | ||
return _.uniq(_.compact(_.flatten(_.map(this._evaluations.evaluations, (evaluation) => | ||
_.map(evaluation.chapters, (chapter) => chapter.path) | ||
)))).length | ||
} | ||
|
||
spec_paths_count(): number { | ||
return Object.values(this._spec.paths()).reduce((acc, methods) => acc + methods.length, 0); | ||
} | ||
|
||
test_coverage(): SpecTestCoverage { | ||
return { | ||
evaluated_paths_count: this.evaluated_paths_count(), | ||
paths_count: this.spec_paths_count(), | ||
evaluated_paths_pct: this.spec_paths_count() > 0 ? Math.round( | ||
this.evaluated_paths_count() / this.spec_paths_count() * 100 * 100 | ||
) / 100 : 0, | ||
} | ||
} | ||
|
||
write_coverage(file_path: string): void { | ||
write_json(file_path, this.test_coverage()) | ||
} | ||
} |
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
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
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
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,14 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
export interface SpecTestCoverage { | ||
paths_count: number | ||
evaluated_paths_count: number, | ||
evaluated_paths_pct: number | ||
} |
Oops, something went wrong.