Skip to content

Commit

Permalink
refactor: throw an error if the internal suite is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 6, 2024
1 parent e6cce09 commit 9b78834
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/runner/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,14 @@ let runner: VitestRunner
let defaultSuite: SuiteCollector
let currentTestFilepath: string

function assert(condition: any, message: string) {
if (!condition) {
throw new Error(`Vitest failed to find ${message}. This is a bug in Vitest. Please, open an issue with reproduction.`)
}
}

export function getDefaultSuite(): SuiteCollector<object> {
assert(defaultSuite, 'the default suite')
return defaultSuite
}

Expand All @@ -193,6 +200,7 @@ export function getTestFilepath(): string {
}

export function getRunner(): VitestRunner {
assert(runner, 'the runner')
return runner
}

Expand All @@ -216,9 +224,11 @@ export function clearCollectorContext(
collectorContext.currentSuite = defaultSuite
}

export function getCurrentSuite<ExtraContext = object>() {
return (collectorContext.currentSuite
export function getCurrentSuite<ExtraContext = object>(): SuiteCollector<ExtraContext> {
const currentSuite = (collectorContext.currentSuite
|| defaultSuite) as SuiteCollector<ExtraContext>
assert(currentSuite, 'the current suite')
return currentSuite
}

export function createSuiteHooks(): SuiteHooks {
Expand Down

0 comments on commit 9b78834

Please sign in to comment.