Skip to content

Commit

Permalink
fix: import performance from perf_hooks and AggregateError from utils (
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 11, 2023
1 parent 7af6444 commit cce4549
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/vitest/src/config.ts
Expand Up @@ -6,7 +6,6 @@ export interface UserConfig extends ViteUserConfig {
}

export interface UserWorkspaceConfig extends ViteUserConfig {
extends?: string
test?: ProjectConfig
}

Expand All @@ -29,6 +28,6 @@ export function defineProject(config: UserProjectConfigExport) {
return config
}

export function defineWorkspace(config: (string | UserProjectConfigExport)[]) {
export function defineWorkspace(config: (string | (UserProjectConfigExport & { extends?: string }))[]) {
return config
}
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/threads.ts
Expand Up @@ -9,7 +9,7 @@ import { distDir } from '../../paths'
import type { ContextTestEnvironment, ResolvedConfig, RuntimeRPC, Vitest, WorkerContext } from '../../types'
import type { PoolProcessOptions, ProcessPool, RunWithFiles } from '../pool'
import { envsOrder, groupFilesByEnv } from '../../utils/test-helpers'
import { groupBy } from '../../utils/base'
import { AggregateError, groupBy } from '../../utils/base'
import type { WorkspaceProject } from '../workspace'
import { createMethodsRPC } from './rpc'

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/workspace.ts
Expand Up @@ -19,7 +19,7 @@ interface InitializeOptions {
runner?: ViteNodeRunner
}

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

const configFile = options.extends
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/runtime/entry.ts
@@ -1,3 +1,4 @@
import { performance } from 'node:perf_hooks'
import type { VitestRunner, VitestRunnerConstructor } from '@vitest/runner'
import { startTests } from '@vitest/runner'
import { resolve } from 'pathe'
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/runtime/runners/benchmark.ts
@@ -1,3 +1,4 @@
import { performance } from 'node:perf_hooks'
import type { Suite, Task, VitestRunner, VitestRunnerImportSource } from '@vitest/runner'
import { updateTask as updateRunnerTask } from '@vitest/runner'
import { createDefer, getSafeTimers } from '@vitest/utils'
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/runtime/worker.ts
@@ -1,3 +1,4 @@
import { performance } from 'node:perf_hooks'
import { createBirpc } from 'birpc'
import { workerId as poolId } from 'tinypool'
import type { RuntimeRPC, WorkerContext } from '../types'
Expand Down
10 changes: 10 additions & 0 deletions packages/vitest/src/utils/base.ts
Expand Up @@ -133,3 +133,13 @@ export function getEnvironmentTransformMode(config: ResolvedConfig, environment:
return undefined
return (environment === 'happy-dom' || environment === 'jsdom') ? 'web' : 'ssr'
}

// AggregateError is supported in Node.js 15.0.0+
class AggregateErrorPonyfill extends Error {
errors: unknown[]
constructor(errors: Iterable<unknown>, message = '') {
super(message)
this.errors = [...errors]
}
}
export { AggregateErrorPonyfill as AggregateError }
10 changes: 0 additions & 10 deletions packages/vitest/src/utils/index.ts
Expand Up @@ -52,16 +52,6 @@ export function removeUndefinedValues<T extends Record<string, any>>(obj: T): T
return obj
}

// AggregateError is supported in Node.js 15.0.0+
class AggregateErrorPonyfill extends Error {
errors: unknown[]
constructor(errors: Iterable<unknown>, message = '') {
super(message)
this.errors = [...errors]
}
}
export { AggregateErrorPonyfill as AggregateError }

export function objectAttr(source: any, path: string, defaultValue = undefined) {
// a[3].b -> a.3.b
const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')
Expand Down

0 comments on commit cce4549

Please sign in to comment.