From eec9b17937873ed51152b8e89f76a4e8182b1605 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Thu, 9 May 2024 14:17:05 +0200 Subject: [PATCH] chore: store version, sort files --- packages/vitest/src/node/core.ts | 39 ++++++++++++++-------- packages/vitest/src/node/reporters/blob.ts | 7 ++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 67b8b503e1991..9f6286314622c 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -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' @@ -39,6 +40,8 @@ export interface VitestOptions { } export class Vitest { + version = version + config: ResolvedConfig = undefined! configOverride: Partial = {} @@ -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) } diff --git a/packages/vitest/src/node/reporters/blob.ts b/packages/vitest/src/node/reporters/blob.ts index c4d243bc7d62e..457ade8ae05ef 100644 --- a/packages/vitest/src/node/reporters/blob.ts +++ b/packages/vitest/src/node/reporters/blob.ts @@ -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) @@ -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) }