Skip to content

Commit

Permalink
fix: snapshots are now updating (#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 21, 2022
1 parent 2a60557 commit 4f01b89
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/vitest/src/node/pool.ts
Expand Up @@ -7,7 +7,7 @@ import type { Options as TinypoolOptions } from 'tinypool'
import { Tinypool } from 'tinypool'
import { createBirpc } from 'birpc'
import type { RawSourceMap } from 'vite-node'
import type { WorkerContext, WorkerRPC } from '../types'
import type { ResolvedConfig, WorkerContext, WorkerRPC } from '../types'
import { distDir } from '../constants'
import { AggregateError, slash } from '../utils'
import type { Vitest } from './core'
Expand Down Expand Up @@ -66,9 +66,8 @@ export function createPool(ctx: Vitest): WorkerPool {

const runWithFiles = (name: string): RunWithFiles => {
let id = 0
const config = ctx.getSerializableConfig()

async function runFiles(files: string[], invalidates: string[] = []) {
async function runFiles(config: ResolvedConfig, files: string[], invalidates: string[] = []) {
const { workerPort, port } = createChannel(ctx)
const workerId = ++id
const data: WorkerContext = {
Expand All @@ -89,6 +88,8 @@ export function createPool(ctx: Vitest): WorkerPool {
}

return async (files, invalidates) => {
const config = ctx.getSerializableConfig()

if (config.shard) {
const { index, count } = config.shard
const shardSize = Math.ceil(files.length / count)
Expand All @@ -111,11 +112,11 @@ export function createPool(ctx: Vitest): WorkerPool {
}

if (!ctx.config.threads) {
await runFiles(files)
await runFiles(config, files)
}
else {
const results = await Promise.allSettled(files
.map(file => runFiles([file], invalidates)))
.map(file => runFiles(config, [file], invalidates)))

const errors = results.filter((r): r is PromiseRejectedResult => r.status === 'rejected').map(r => r.reason)
if (errors.length > 0)
Expand Down

0 comments on commit 4f01b89

Please sign in to comment.