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

Method collectTests

packages/vitest/src/node/core.ts:1115–1167  ·  view source on GitHub ↗

* Collect tests in specified modules. Vitest will run the files to collect tests. * @param specifications A list of specifications to run.

(specifications: TestSpecification[])

Source from the content-addressed store, hash-verified

1113 * @param specifications A list of specifications to run.
1114 */
1115 public async collectTests(specifications: TestSpecification[]): Promise<TestRunResult> {
1116 const filepaths = specifications.map(spec => spec.moduleId)
1117 this.state.collectPaths(filepaths)
1118
1119 // previous run
1120 await this.cancelPromise
1121 await this.runningPromise
1122 this._onCancelListeners.clear()
1123 this.isCancelling = false
1124
1125 // schedule the new run
1126 this.runningPromise = (async () => {
1127 if (!this.pool) {
1128 this.pool = createPool(this)
1129 }
1130
1131 const invalidates = Array.from(this.watcher.invalidates)
1132 this.watcher.invalidates.clear()
1133 this.snapshot.clear()
1134 this.state.clearErrors()
1135
1136 await this.initializeGlobalSetup(specifications)
1137
1138 try {
1139 await this.pool.collectTests(specifications, invalidates)
1140 }
1141 catch (err) {
1142 this.state.catchError(err, 'Unhandled Error')
1143 }
1144
1145 const files = this.state.getFiles()
1146
1147 // can only happen if there was a syntax error in describe block
1148 // or there was an error importing a file
1149 if (hasFailed(files)) {
1150 process.exitCode = 1
1151 }
1152
1153 return {
1154 testModules: this.state.getTestModules(),
1155 unhandledErrors: this.state.getUnhandledErrors(),
1156 }
1157 })()
1158 .finally(() => {
1159 this.runningPromise = undefined
1160
1161 // all subsequent runs will treat this as a fresh run
1162 this.config.changed = false
1163 this.config.related = undefined
1164 })
1165
1166 return await this.runningPromise
1167 }
1168
1169 /**
1170 * Gracefully cancel the current test run. Vitest will wait until all running tests are finished before cancelling.

Callers 6

collectMethod · 0.95
executeTestsFunction · 0.45
onMessageFunction · 0.45
startTypecheckerFunction · 0.45
collectTestsFunction · 0.45

Calls 10

initializeGlobalSetupMethod · 0.95
createPoolFunction · 0.90
hasFailedFunction · 0.90
clearErrorsMethod · 0.80
catchErrorMethod · 0.80
getTestModulesMethod · 0.80
getUnhandledErrorsMethod · 0.80
clearMethod · 0.65
collectPathsMethod · 0.45
getFilesMethod · 0.45

Tested by

no test coverage detected