-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
39 lines (33 loc) · 1.07 KB
/
test.ts
File metadata and controls
39 lines (33 loc) · 1.07 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
// A lib to allow testing with vitest or mocha
import type {
test as testType,
describe as describeType,
expect as expectType
} from 'vitest';
export interface TestContext {
fullName: string;
}
export const isVitest = process.env.VITEST == 'true';
export const isMocha = !isVitest;
let testImpl, describeImpl, beforeEachImpl, expectImpl;
if (isMocha) {
const { test, describe, beforeEach } = await import('./setup-mocha.js');
const { expect } = await import('expect');
expectImpl = expect;
testImpl = test;
describeImpl = describe;
beforeEachImpl = beforeEach;
} else {
const { test, describe, beforeEach } = await import('./setup-vitest.js');
const { expect } = await import('vitest');
expectImpl = expect;
testImpl = test;
describeImpl = describe;
beforeEachImpl = beforeEach;
}
export function beforeEach(callback: (context: TestContext) => any) {
return beforeEachImpl!(callback);
}
export const test = testImpl as typeof testType;
export const describe = describeImpl as typeof describeType;
export const expect = expectImpl as typeof expectType;