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

Method start

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

* Initialize reporters, the coverage provider, and run tests. * This method can throw an error: * - `FilesNotFoundError` if no tests are found * - `GitNotFoundError` if `--related` flag is used, but git repository is not initialized * - `Error` from the user reporters * @param f

(filters?: string[])

Source from the content-addressed store, hash-verified

739 * @param filters String filters to match the test files
740 */
741 async start(filters?: string[]): Promise<TestRunResult> {
742 return this._traces.$('vitest.start', { context: this._traces.getContextFromEnv(process.env) }, async (startSpan) => {
743 startSpan.setAttributes({
744 config: this.vite.config.configFile,
745 })
746
747 try {
748 await this._traces.$('vitest.coverage.init', async () => {
749 await this.initCoverageProvider()
750 await this.coverageProvider?.clean(this._coverageOptions.clean)
751 })
752 }
753 finally {
754 await this.report('onInit', this)
755 }
756
757 this.filenamePattern = filters && filters?.length > 0 ? filters : undefined
758 startSpan.setAttribute('vitest.start.filters', this.filenamePattern || [])
759 let specifications = await this._traces.$(
760 'vitest.config.resolve_include_glob',
761 async () => {
762 const specifications = await this.specifications.getRelevantTestSpecifications(filters)
763 startSpan.setAttribute(
764 'vitest.start.specifications',
765 specifications.map((s) => {
766 const relativeModuleId = relative(s.project.config.root, s.moduleId)
767 if (s.project.name) {
768 return `|${s.project.name}| ${relativeModuleId}`
769 }
770 return relativeModuleId
771 }),
772 )
773 return specifications
774 },
775 )
776
777 if (this.config.experimental.preParse) {
778 // This populates specification.testModule with parsed information
779 await this.experimental_parseSpecifications(specifications)
780 specifications = specifications.filter(({ testModule }) => {
781 return !testModule || testModule.task.mode !== 'skip'
782 })
783 }
784
785 // if run with --changed, don't exit if no tests are found
786 if (!specifications.length) {
787 await this._traces.$('vitest.test_run', async () => {
788 await this._testRun.start([])
789 await this.coverageProvider?.onTestRunStart?.()
790 const coverage = await this.coverageProvider?.generateCoverage?.({ allTestsRun: true })
791
792 await this._testRun.end([], [], coverage)
793 // Report coverage for uncovered files
794 await this.reportCoverage(coverage, true)
795 })
796
797 if (!this.config.watch || !(this.config.changed || this.config.related?.length)) {
798 throw new FilesNotFoundError(this.mode)

Callers 5

initMethod · 0.45
mergeReportsMethod · 0.45
runFilesMethod · 0.45
startTracingFunction · 0.45
otel.jsFile · 0.45

Calls 15

initCoverageProviderMethod · 0.95
reportMethod · 0.95
reportCoverageMethod · 0.95
runFilesMethod · 0.95
$Method · 0.80
getContextFromEnvMethod · 0.80
endMethod · 0.80
populateStatsMethod · 0.80
filterMethod · 0.65
relativeFunction · 0.50
cleanMethod · 0.45

Tested by

no test coverage detected