Skip to content

Commit

Permalink
# process.exit(1)
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed May 29, 2024
1 parent d415287 commit 438737f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
20 changes: 8 additions & 12 deletions tools/src/tester/TestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import StoryEvaluator, { type StoryFile } from './StoryEvaluator'
import fs from 'fs'
import { type Story } from './types/story.types'
import { read_yaml } from '../../helpers'
import { type StoryEvaluation } from './types/eval.types'
import { Result, type StoryEvaluation } from './types/eval.types'
import ResultsDisplayer, { type DisplayOptions } from './ResultsDisplayer'
import SharedResources from './SharedResources'
import { resolve, basename } from 'path'
Expand All @@ -28,20 +28,16 @@ export default class TestsRunner {
}

async run (): Promise<void> {
const evaluations = await this.evaluate()
for (const evaluation of evaluations) {
let failed = false
const story_files = this.#collect_story_files(this.path, '', '').sort((a, b) => a.display_path.localeCompare(b.display_path))
for (const story_file of story_files) {
const evaluator = new StoryEvaluator(story_file)
const evaluation = await evaluator.evaluate()
const displayer = new ResultsDisplayer(evaluation, this.opts)
displayer.display()
if ([Result.ERROR, Result.FAILED].includes(evaluation.result)) failed = true
}
}

async evaluate (): Promise<StoryEvaluation[]> {
const story_files = this.#collect_story_files(this.path, '', '')
const promises = story_files.map(async story_file => {
const evaluator = new StoryEvaluator(story_file)
return await evaluator.evaluate()
})
return (await Promise.all(promises)).sort((a, b) => a.display_path.localeCompare(b.display_path))
if (failed) process.exit(1)
}

#collect_story_files (folder: string, file: string, prefix: string): StoryFile[] {
Expand Down
3 changes: 2 additions & 1 deletion tools/src/tester/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OpenApiMerger from '../merger/OpenApiMerger'
import { LogLevel } from '../Logger'
import TestsRunner from './TestsRunner'
import { Command, Option } from '@commander-js/extra-typings'
import _ from 'lodash'

const command = new Command()
.description('Run test stories against the OpenSearch spec.')
Expand All @@ -19,4 +20,4 @@ const display_options = {
}
const spec = (new OpenApiMerger(opts.spec_path, LogLevel.error)).merge()
const runner = new TestsRunner(spec, opts.tests_path, display_options)
void runner.run().then(() => { console.log('Tests run successfully.') })
void runner.run().then(() => { _.noop() })

0 comments on commit 438737f

Please sign in to comment.