diff --git a/tools/src/merger/OpenApiVersionExtractor.ts b/tools/src/merger/OpenApiVersionExtractor.ts index a70df93ef..33e246c29 100644 --- a/tools/src/merger/OpenApiVersionExtractor.ts +++ b/tools/src/merger/OpenApiVersionExtractor.ts @@ -23,7 +23,7 @@ export default class OpenApiVersionExtractor { constructor(source_spec: OpenAPIV3.Document, target_version?: string, target_distribution?: string, logger: Logger = new Logger()) { this._source_spec = source_spec - this._target_version = target_version !== undefined ? (semver.coerce(target_version)?.toString() ?? target_version) : target_version + this._target_version = semver.coerce(target_version)?.toString() ?? target_version this._target_distribution = target_distribution this._logger = logger this._spec = undefined diff --git a/tools/src/tester/StoryEvaluator.ts b/tools/src/tester/StoryEvaluator.ts index f8b7b46cd..8a375ff3c 100644 --- a/tools/src/tester/StoryEvaluator.ts +++ b/tools/src/tester/StoryEvaluator.ts @@ -27,7 +27,7 @@ export default class StoryEvaluator { } async evaluate({ story, display_path, full_path }: StoryFile, version?: string, distribution?: string, dry_run: boolean = false): Promise { - if (version !== undefined && story.version !== undefined && !StoryEvaluator.#semver_satisfies(version, story.version)) { + if (version !== undefined && story.version !== undefined && !semver.satisfies(version, story.version)) { return { result: Result.SKIPPED, display_path, @@ -92,7 +92,7 @@ export default class StoryEvaluator { if (dry_run) { const title = chapter.synopsis || `${chapter.method} ${chapter.path}` evaluations.push({ title, overall: { result: Result.SKIPPED, message: 'Dry Run', error: undefined } }) - } else if (version != undefined && chapter.version !== undefined && !StoryEvaluator.#semver_satisfies(version, chapter.version)) { + } else if (version != undefined && chapter.version !== undefined && semver.satisfies(version, chapter.version)) { const title = chapter.synopsis || `${chapter.method} ${chapter.path}` evaluations.push({ title, overall: { result: Result.SKIPPED, message: `Skipped because version ${version} does not satisfy ${chapter.version}.`, error: undefined } }) } else if (distribution != undefined && chapter.distributions !== undefined && !chapter.distributions.includes(distribution)) { @@ -236,8 +236,4 @@ export default class StoryEvaluator { static #failed_evaluation(title: string, message: string): ChapterEvaluation { return { title, overall: { result: Result.FAILED, message } } } - - static #semver_satisfies(version: string, range: string): boolean { - return _.every(range.split(','), (portion) => semver.satisfies(version, portion)) - } } diff --git a/tools/tests/tester/fixtures/evals/passed.yaml b/tools/tests/tester/fixtures/evals/passed.yaml index e38fc243f..39cfe6a1f 100644 --- a/tools/tests/tester/fixtures/evals/passed.yaml +++ b/tools/tests/tester/fixtures/evals/passed.yaml @@ -175,7 +175,7 @@ chapters: - title: This GET /_cat/health should be skipped (> 2.999.0). overall: result: SKIPPED - message: Skipped because version 2.16.0 does not satisfy >= 2.999.0. + message: Skipped because version 2.16.0 does not satisfy > 2.999.0. - title: This GET /_cat/health should not be skipped (> 2.0, < 10). overall: result: PASSED