MCPcopy
hub / github.com/vitest-dev/vitest / createSuite

Function createSuite

packages/runner/src/suite.ts:584–742  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

582}
583
584function createSuite() {
585 function suiteFn(
586 this: Record<string, boolean | undefined>,
587 name: string | Function,
588 factoryOrOptions?: SuiteFactory | SuiteOptions,
589 optionsOrFactory?: number | SuiteFactory,
590 ) {
591 if (getCurrentTest()) {
592 throw new Error(
593 'Calling the suite function inside test function is not allowed. It can be only called at the top level or inside another suite function.',
594 )
595 }
596
597 const currentSuite: SuiteCollector | undefined = collectorContext.currentSuite || defaultSuite
598
599 let { options, handler: factory } = parseArguments(
600 factoryOrOptions,
601 optionsOrFactory,
602 ) as { options: SuiteOptions; handler: SuiteFactory | undefined }
603
604 const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false
605 const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false
606
607 const { meta: parentMeta, ...parentOptions } = currentSuite?.options || {}
608 // inherit options from current suite
609 options = {
610 ...parentOptions,
611 ...options,
612 }
613
614 const shuffle = this.shuffle ?? options.shuffle ?? currentSuite?.options?.shuffle ?? runner?.config.sequence.shuffle
615 if (shuffle != null) {
616 options.shuffle = shuffle
617 }
618
619 let mode: RunMode = (this.only ?? options.only)
620 ? 'only'
621 : (this.skip ?? options.skip)
622 ? 'skip'
623 : (this.todo ?? options.todo)
624 ? 'todo'
625 : 'run'
626
627 // passed as test(name), assume it's a "todo"
628 if (mode === 'run' && !factory) {
629 mode = 'todo'
630 }
631
632 // inherit concurrent / sequential from suite
633 const isConcurrent = isConcurrentSpecified || (options.concurrent && !isSequentialSpecified)
634 const isSequential = isSequentialSpecified || (options.sequential && !isConcurrentSpecified)
635 if (isConcurrent != null) {
636 options.concurrent = isConcurrent && !isSequential
637 }
638 if (isSequential != null) {
639 options.sequential = isSequential && !isConcurrent
640 }
641

Callers 1

suite.tsFile · 0.85

Calls 8

getChainableContextFunction · 0.90
toArrayFunction · 0.90
createChainableFunction · 0.90
formatTemplateStringFunction · 0.85
formatTitleFunction · 0.85
formatNameFunction · 0.70
parseArgumentsFunction · 0.70
handlerFunction · 0.50

Tested by

no test coverage detected