Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import performance from perf_hooks and AggregateError from utils #3171

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/vitest/src/config.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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