Skip to content

Commit eec9b17

Browse files
committed
chore: store version, sort files
1 parent f29b01d commit eec9b17

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

packages/vitest/src/node/core.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { getCoverageProvider } from '../integrations/coverage'
1818
import { CONFIG_NAMES, configFiles, workspacesFiles as workspaceFiles } from '../constants'
1919
import { rootDir } from '../paths'
2020
import { WebSocketReporter } from '../api/setup'
21+
import { version } from '../../package.json'
2122
import { createPool } from './pool'
2223
import type { ProcessPool, WorkspaceSpec } from './pool'
2324
import { createBenchmarkReporters, createReporters } from './reporters/utils'
@@ -39,6 +40,8 @@ export interface VitestOptions {
3940
}
4041

4142
export class Vitest {
43+
version = version
44+
4245
config: ResolvedConfig = undefined!
4346
configOverride: Partial<ResolvedConfig> = {}
4447

@@ -420,28 +423,36 @@ export class Vitest {
420423
})
421424
})
422425

423-
const files = blobs.flatMap(blob => blob.files)
426+
const files = blobs.flatMap(blob => blob.files).sort((f1, f2) => {
427+
const time1 = f1.result?.startTime || 0
428+
const time2 = f2.result?.startTime || 0
429+
return time1 - time2
430+
})
424431
const errors = blobs.flatMap(blob => blob.errors)
425432
this.state.collectFiles(files)
426433

427-
const tasks = files.flatMap(file => getTasks(file))
434+
await this.report('onCollected', files.map((file) => {
435+
return { ...file, result: undefined }
436+
}))
437+
438+
for (const file of files) {
439+
const logs: UserConsoleLog[] = []
440+
const taskPacks: TaskResultPack[] = []
428441

429-
await this.report('onCollected', files)
442+
const tasks = getTasks(file)
443+
for (const task of tasks) {
444+
if (task.logs)
445+
logs.push(...task.logs)
446+
taskPacks.push([task.id, task.result, task.meta])
447+
}
448+
logs.sort((log1, log2) => log1.time - log2.time)
430449

431-
const logs: UserConsoleLog[] = []
432-
const taskPacks: TaskResultPack[] = []
450+
for (const log of logs)
451+
await this.report('onUserConsoleLog', log)
433452

434-
for (const task of tasks) {
435-
if (task.logs)
436-
logs.push(...task.logs)
437-
taskPacks.push([task.id, task.result, task.meta])
453+
await this.report('onTaskUpdate', taskPacks)
438454
}
439-
logs.sort((log1, log2) => log1.time - log2.time)
440-
441-
for (const log of logs)
442-
await this.report('onUserConsoleLog', log)
443455

444-
await this.report('onTaskUpdate', taskPacks)
445456
await this.report('onFinished', files, errors)
446457
}
447458

packages/vitest/src/node/reporters/blob.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export class BlobReporter implements Reporter {
3737
return [project.getName(), [...project.server.moduleGraph.idToModuleMap.keys()]]
3838
})
3939

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

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

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

0 commit comments

Comments
 (0)