Skip to content

Commit

Permalink
chore: store version, sort files
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 9, 2024
1 parent f29b01d commit eec9b17
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
39 changes: 25 additions & 14 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getCoverageProvider } from '../integrations/coverage'
import { CONFIG_NAMES, configFiles, workspacesFiles as workspaceFiles } from '../constants'
import { rootDir } from '../paths'
import { WebSocketReporter } from '../api/setup'
import { version } from '../../package.json'
import { createPool } from './pool'
import type { ProcessPool, WorkspaceSpec } from './pool'
import { createBenchmarkReporters, createReporters } from './reporters/utils'
Expand All @@ -39,6 +40,8 @@ export interface VitestOptions {
}

export class Vitest {
version = version

config: ResolvedConfig = undefined!
configOverride: Partial<ResolvedConfig> = {}

Expand Down Expand Up @@ -420,28 +423,36 @@ export class Vitest {
})
})

const files = blobs.flatMap(blob => blob.files)
const files = blobs.flatMap(blob => blob.files).sort((f1, f2) => {
const time1 = f1.result?.startTime || 0
const time2 = f2.result?.startTime || 0
return time1 - time2
})
const errors = blobs.flatMap(blob => blob.errors)
this.state.collectFiles(files)

const tasks = files.flatMap(file => getTasks(file))
await this.report('onCollected', files.map((file) => {
return { ...file, result: undefined }
}))

for (const file of files) {
const logs: UserConsoleLog[] = []
const taskPacks: TaskResultPack[] = []

await this.report('onCollected', files)
const tasks = getTasks(file)
for (const task of tasks) {
if (task.logs)
logs.push(...task.logs)
taskPacks.push([task.id, task.result, task.meta])
}
logs.sort((log1, log2) => log1.time - log2.time)

const logs: UserConsoleLog[] = []
const taskPacks: TaskResultPack[] = []
for (const log of logs)
await this.report('onUserConsoleLog', log)

for (const task of tasks) {
if (task.logs)
logs.push(...task.logs)
taskPacks.push([task.id, task.result, task.meta])
await this.report('onTaskUpdate', taskPacks)
}
logs.sort((log1, log2) => log1.time - log2.time)

for (const log of logs)
await this.report('onUserConsoleLog', log)

await this.report('onTaskUpdate', taskPacks)
await this.report('onFinished', files, errors)
}

Expand Down
7 changes: 3 additions & 4 deletions packages/vitest/src/node/reporters/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export class BlobReporter implements Reporter {
return [project.getName(), [...project.server.moduleGraph.idToModuleMap.keys()]]
})

// TODO: store module graph?
const report = stringify([files, errors, moduleKeys])
const report = stringify([this.ctx.version, files, errors, moduleKeys])

const reportFile = resolve(this.ctx.config.root, outputFile)

Expand All @@ -60,8 +59,8 @@ export async function readBlobs(blobsDirectory: string) {
const blobs = await readdir(resolvedDir)
const promises = blobs.map(async (file) => {
const content = await readFile(resolve(resolvedDir, file), 'utf-8')
const [files, errors, moduleKeys] = parse(content) as [files: File[], errors: unknown[], [string, string[]][]]
return { files, errors, moduleKeys }
const [version, files, errors, moduleKeys] = parse(content) as [string, files: File[], errors: unknown[], [string, string[]][]]
return { version, files, errors, moduleKeys }
})
return Promise.all(promises)
}

0 comments on commit eec9b17

Please sign in to comment.