Skip to content

Commit cce4549

Browse files
authoredApr 11, 2023
fix: import performance from perf_hooks and AggregateError from utils (#3171)
1 parent 7af6444 commit cce4549

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed
 

‎packages/vitest/src/config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface UserConfig extends ViteUserConfig {
66
}
77

88
export interface UserWorkspaceConfig extends ViteUserConfig {
9-
extends?: string
109
test?: ProjectConfig
1110
}
1211

@@ -29,6 +28,6 @@ export function defineProject(config: UserProjectConfigExport) {
2928
return config
3029
}
3130

32-
export function defineWorkspace(config: (string | UserProjectConfigExport)[]) {
31+
export function defineWorkspace(config: (string | (UserProjectConfigExport & { extends?: string }))[]) {
3332
return config
3433
}

‎packages/vitest/src/node/pools/threads.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { distDir } from '../../paths'
99
import type { ContextTestEnvironment, ResolvedConfig, RuntimeRPC, Vitest, WorkerContext } from '../../types'
1010
import type { PoolProcessOptions, ProcessPool, RunWithFiles } from '../pool'
1111
import { envsOrder, groupFilesByEnv } from '../../utils/test-helpers'
12-
import { groupBy } from '../../utils/base'
12+
import { AggregateError, groupBy } from '../../utils/base'
1313
import type { WorkspaceProject } from '../workspace'
1414
import { createMethodsRPC } from './rpc'
1515

‎packages/vitest/src/node/workspace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface InitializeOptions {
1919
runner?: ViteNodeRunner
2020
}
2121

22-
export async function initializeProject(workspacePath: string | number, ctx: Vitest, options: UserWorkspaceConfig = {}) {
22+
export async function initializeProject(workspacePath: string | number, ctx: Vitest, options: (UserWorkspaceConfig & { extends?: string }) = {}) {
2323
const project = new WorkspaceProject(workspacePath, ctx)
2424

2525
const configFile = options.extends

‎packages/vitest/src/runtime/entry.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { performance } from 'node:perf_hooks'
12
import type { VitestRunner, VitestRunnerConstructor } from '@vitest/runner'
23
import { startTests } from '@vitest/runner'
34
import { resolve } from 'pathe'

‎packages/vitest/src/runtime/runners/benchmark.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { performance } from 'node:perf_hooks'
12
import type { Suite, Task, VitestRunner, VitestRunnerImportSource } from '@vitest/runner'
23
import { updateTask as updateRunnerTask } from '@vitest/runner'
34
import { createDefer, getSafeTimers } from '@vitest/utils'

‎packages/vitest/src/runtime/worker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { performance } from 'node:perf_hooks'
12
import { createBirpc } from 'birpc'
23
import { workerId as poolId } from 'tinypool'
34
import type { RuntimeRPC, WorkerContext } from '../types'

‎packages/vitest/src/utils/base.ts

+10
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,13 @@ export function getEnvironmentTransformMode(config: ResolvedConfig, environment:
133133
return undefined
134134
return (environment === 'happy-dom' || environment === 'jsdom') ? 'web' : 'ssr'
135135
}
136+
137+
// AggregateError is supported in Node.js 15.0.0+
138+
class AggregateErrorPonyfill extends Error {
139+
errors: unknown[]
140+
constructor(errors: Iterable<unknown>, message = '') {
141+
super(message)
142+
this.errors = [...errors]
143+
}
144+
}
145+
export { AggregateErrorPonyfill as AggregateError }

‎packages/vitest/src/utils/index.ts

-10
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ export function removeUndefinedValues<T extends Record<string, any>>(obj: T): T
5252
return obj
5353
}
5454

55-
// AggregateError is supported in Node.js 15.0.0+
56-
class AggregateErrorPonyfill extends Error {
57-
errors: unknown[]
58-
constructor(errors: Iterable<unknown>, message = '') {
59-
super(message)
60-
this.errors = [...errors]
61-
}
62-
}
63-
export { AggregateErrorPonyfill as AggregateError }
64-
6555
export function objectAttr(source: any, path: string, defaultValue = undefined) {
6656
// a[3].b -> a.3.b
6757
const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')

0 commit comments

Comments
 (0)
Please sign in to comment.