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

feat(benchmark): move importTinybench to runner #4376

Merged
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
1 change: 0 additions & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@
"birpc": "0.2.14",
"chai-subset": "^1.6.0",
"cli-truncate": "^3.1.0",
"event-target-polyfill": "^0.0.3",
"execa": "^7.1.1",
"expect-type": "^0.16.0",
"fast-glob": "^3.3.0",
Expand Down
16 changes: 7 additions & 9 deletions packages/vitest/src/runtime/runners/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import type { BenchTask, Benchmark, BenchmarkResult } from '../../types/benchmar
import type { ResolvedConfig } from '../../types/config'
import type { VitestExecutor } from '../execute'

async function importTinybench() {
if (!globalThis.EventTarget)
await import('event-target-polyfill' as any)

return (await import('tinybench'))
}

function createBenchmarkResult(name: string): BenchmarkResult {
return {
name,
Expand All @@ -26,8 +19,9 @@ function createBenchmarkResult(name: string): BenchmarkResult {

const benchmarkTasks = new WeakMap<Benchmark, import('tinybench').Task>()

async function runBenchmarkSuite(suite: Suite, runner: VitestRunner) {
const { Task, Bench } = await importTinybench()
async function runBenchmarkSuite(suite: Suite, runner: NodeBenchmarkRunner) {
const { Task, Bench } = await runner.importTinybench()

const start = performance.now()

const benchmarkGroup: Benchmark[] = []
Expand Down Expand Up @@ -132,6 +126,10 @@ export class NodeBenchmarkRunner implements VitestRunner {

constructor(public config: ResolvedConfig) {}

async importTinybench() {
return await import('tinybench')
}

importFile(filepath: string, source: VitestRunnerImportSource): unknown {
if (source === 'setup')
getWorkerState().moduleCache.delete(filepath)
Expand Down
5 changes: 1 addition & 4 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f

api?: ApiConfig

benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & {
outputFile?: BenchmarkUserOptions['outputFile']
}

benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & Pick<BenchmarkUserOptions, 'outputFile'>
shard?: {
index: number
count: number
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading