Skip to content

Commit

Permalink
# added verbose arg
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed May 28, 2024
1 parent 8ece8c1 commit 5a81260
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions tools/src/tester/TestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import ResultsDisplayer from './ResultsDisplayer'
import SharedResources from './SharedResources'
import { resolve, basename } from 'path'

interface TestsRunnerOptions {
ignored_results: Set<Result> // Chapter results to ignore when displaying results
verbose: boolean // Whether to print the full stack trace of errors
}

export default class TestsRunner {
path: string // Path to a story file or a directory containing story files
ignored_results: Set<Result> // Chapter results to ignore when displaying results
opts: TestsRunnerOptions

constructor (spec: OpenAPIV3.Document, path: string, ignored_results: Set<Result>) {
constructor (spec: OpenAPIV3.Document, path: string, opts: TestsRunnerOptions) {
this.path = resolve(path)
this.ignored_results = ignored_results
this.opts = opts

// TODO: Grab server URL from environment variable and add authentication.
const chapter_reader = new ChapterReader('http://localhost:9200')
Expand All @@ -29,7 +34,7 @@ export default class TestsRunner {
async run (): Promise<void> {
const evaluations = await this.evaluate()
for (const evaluation of evaluations) {
const displayer = new ResultsDisplayer(evaluation, this.ignored_results)
const displayer = new ResultsDisplayer(evaluation, this.opts.ignored_results)
displayer.display()
}
}
Expand Down
6 changes: 4 additions & 2 deletions tools/src/tester/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const command = new Command()
.addOption(new Option('--spec, --spec_path <path>', 'path to the root folder of the multi-file spec').default('./spec'))
.addOption(new Option('--tests, --tests_path <path>', 'path to the root folder of the tests').default('./tests'))
.addOption(new Option('--ignore <results>', 'comma-separated list of chapter results to ignore. Ignorable results are SKIPPED and PASSED').default('PASSED'))
.addOption(new Option('--verbose', 'whether to print the full stack trace of errors'))
.allowExcessArguments(false)
.parse()

const opts = command.opts()
const ignored_results = new Set<Result>(opts.ignore.split(',').map(r => Result[r as keyof typeof Result]))
const ignored_results = new Set(opts.ignore.split(',').map(r => Result[r as keyof typeof Result]))
const verbose = opts.verbose ?? false
const spec = (new OpenApiMerger(opts.spec_path, LogLevel.error)).merge()
const runner = new TestsRunner(spec, opts.tests_path, new Set(ignored_results))
const runner = new TestsRunner(spec, opts.tests_path, { ignored_results, verbose })
void runner.run().then(() => { console.log('Tests run successfully.') })

0 comments on commit 5a81260

Please sign in to comment.