test(server): harden HttpApi exercise coverage
This commit is contained in:
@@ -24,8 +24,13 @@ export function parseOptions(args: string[]): Options {
|
||||
return {
|
||||
mode,
|
||||
include: option(args, "--include"),
|
||||
startAt: option(args, "--start-at"),
|
||||
stopAt: option(args, "--stop-at"),
|
||||
failOnMissing: args.includes("--fail-on-missing"),
|
||||
failOnSkip: args.includes("--fail-on-skip"),
|
||||
scenarioTimeout: option(args, "--scenario-timeout") ?? "30 seconds",
|
||||
progress: args.includes("--progress"),
|
||||
trace: args.includes("--trace"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +43,21 @@ export function matches(options: Options, scenario: Scenario) {
|
||||
)
|
||||
}
|
||||
|
||||
export function selectedScenarios(options: Options, scenarios: Scenario[]) {
|
||||
const included = scenarios.filter((scenario) => matches(options, scenario))
|
||||
const start = options.startAt ? included.findIndex((scenario) => matchesName(options.startAt!, scenario)) : 0
|
||||
const end = options.stopAt
|
||||
? included.findIndex((scenario) => matchesName(options.stopAt!, scenario))
|
||||
: included.length - 1
|
||||
if (start === -1) throw new Error(`--start-at matched no scenario: ${options.startAt}`)
|
||||
if (end === -1) throw new Error(`--stop-at matched no scenario: ${options.stopAt}`)
|
||||
return included.slice(start, end + 1)
|
||||
}
|
||||
|
||||
function matchesName(value: string, scenario: Scenario) {
|
||||
return scenario.name.includes(value) || scenario.path.includes(value) || scenario.method.includes(value.toUpperCase())
|
||||
}
|
||||
|
||||
function option(args: string[], name: string) {
|
||||
const index = args.indexOf(name)
|
||||
if (index === -1) return undefined
|
||||
|
||||
Reference in New Issue
Block a user