-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcompat.ts
More file actions
50 lines (44 loc) · 1.82 KB
/
compat.ts
File metadata and controls
50 lines (44 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Compatibility layer for vitest imports across versions.
*
* Vitest 4.1 deprecated `vitest/runners` and `vitest/suite` subpath imports,
* moving exports to the main `vitest` entry point. This module resolves
* the correct imports at runtime to avoid deprecation warnings while
* maintaining compatibility with vitest 3.2+.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyClass = new (...args: any[]) => any;
// Resolve NodeBenchmarkRunner: vitest >= 4.1 exports it as BenchmarkRunner
// from the main entry; older versions export it from vitest/runners.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const vitestMod: any = await import("vitest");
const _BenchmarkRunner: AnyClass | undefined = vitestMod.BenchmarkRunner;
let _NodeBenchmarkRunner: AnyClass;
if (_BenchmarkRunner) {
_NodeBenchmarkRunner = _BenchmarkRunner;
} else {
const runners = await import("vitest/runners");
_NodeBenchmarkRunner = runners.NodeBenchmarkRunner;
}
export const NodeBenchmarkRunner = _NodeBenchmarkRunner;
// Resolve suite helpers: vitest >= 4.1 exposes them as TestRunner static
// methods; older versions export them from vitest/suite.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type SuiteFn = (...args: any[]) => any;
let _getHooks: SuiteFn;
let _getBenchFn: SuiteFn;
let _getBenchOptions: SuiteFn;
const TestRunner = vitestMod.TestRunner;
if (TestRunner?.getSuiteHooks) {
_getHooks = TestRunner.getSuiteHooks;
_getBenchFn = TestRunner.getBenchFn;
_getBenchOptions = TestRunner.getBenchOptions;
} else {
const suite = await import("vitest/suite");
_getHooks = suite.getHooks;
_getBenchFn = suite.getBenchFn;
_getBenchOptions = suite.getBenchOptions;
}
export const getHooks = _getHooks;
export const getBenchFn = _getBenchFn;
export const getBenchOptions = _getBenchOptions;