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

Function readBlobs

packages/vitest/src/node/reporters/blob.ts:112–212  ·  view source on GitHub ↗
(
  currentVersion: string,
  blobsDirectory: string,
  projectsArray: TestProject[],
)

Source from the content-addressed store, hash-verified

110}
111
112export async function readBlobs(
113 currentVersion: string,
114 blobsDirectory: string,
115 projectsArray: TestProject[],
116): Promise<MergedBlobs> {
117 // using process.cwd() because --merge-reports can only be used in CLI
118 const resolvedDir = resolve(process.cwd(), blobsDirectory)
119 const blobsFiles = await readdir(resolvedDir)
120 const promises = blobsFiles.map(async (filename) => {
121 const fullPath = resolve(resolvedDir, filename)
122 const stats = await stat(fullPath)
123 if (!stats.isFile()) {
124 throw new TypeError(
125 `vitest.mergeReports() expects all paths in "${blobsDirectory}" to be files generated by the blob reporter, but "${filename}" is not a file`,
126 )
127 }
128 const content = await readFile(fullPath, 'utf-8')
129 const [version, files, errors, coverage, executionTime, environmentModules] = parse(
130 content,
131 ) as MergeReport
132 if (!version) {
133 throw new TypeError(
134 `vitest.mergeReports() expects all paths in "${blobsDirectory}" to be files generated by the blob reporter, but "${filename}" is not a valid blob file`,
135 )
136 }
137 return { version, files, errors, coverage, file: filename, executionTime, environmentModules }
138 })
139 const blobs = await Promise.all(promises)
140
141 if (!blobs.length) {
142 throw new Error(
143 `vitest.mergeReports() requires at least one blob file in "${blobsDirectory}" directory, but none were found`,
144 )
145 }
146
147 const versions = new Set(blobs.map(blob => blob.version))
148 if (versions.size > 1) {
149 throw new Error(
150 `vitest.mergeReports() requires all blob files to be generated by the same Vitest version, received\n\n${blobs.map(b => `- "${b.file}" uses v${b.version}`).join('\n')}`,
151 )
152 }
153
154 if (!versions.has(currentVersion)) {
155 throw new Error(
156 `the blobs in "${blobsDirectory}" were generated by a different version of Vitest. Expected v${currentVersion}, but received v${blobs[0].version}`,
157 )
158 }
159
160 // Restore module graph
161 const projects = Object.fromEntries(
162 projectsArray.map(p => [p.name, p]),
163 )
164
165 for (const project of projectsArray) {
166 if (project.isBrowserEnabled()) {
167 await project._initBrowserServer()
168 }
169 }

Callers 1

mergeReportsMethod · 0.90

Calls 10

readFileFunction · 0.85
allMethod · 0.80
isBrowserEnabledMethod · 0.80
entriesMethod · 0.80
resolveFunction · 0.50
parseFunction · 0.50
hasMethod · 0.45
setMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected