-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
57 lines (50 loc) · 1.38 KB
/
index.ts
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
51
52
53
54
55
56
57
import chalk from 'chalk'
export const it = (message: string, callback: () => Promise<void>) => {
return {
message,
callback,
}
}
const benchmarks = ['small', 'medium', 'large']
export const benchmark = (message: string, callback: (path: string) => Promise<void>) => {
return {
message,
callback: async () => {
for (const testCase of benchmarks) {
console.time(`Benchmark ${message} : ${testCase}`)
await callback(`tests/fixtures/${testCase}.csv`)
console.timeEnd(`Benchmark ${message} : ${testCase}`)
}
},
}
}
export async function execute(suiteMessage: string, testSuite: ReturnType<typeof it>[]) {
let i = 0
let success = 0
let failure = 0
console.log()
console.log(chalk.underline(`Running test suite "${suiteMessage}"`))
for await (let test of testSuite) {
i++
const {message, callback} = test
try {
await callback()
console.log(chalk.green(`${i} => ${message}`))
success++
} catch (err: any) {
console.log()
console.log(chalk.red(`${i} => ${message}`))
console.log(chalk.yellow(err.message))
console.log()
failure++
}
}
console.log()
console.log('####')
if (failure === 0) {
console.log(`# ${chalk.green(`${success} OK`)}`)
} else {
console.log(`# ${chalk.green(`${success} OK`)} - ${chalk.red(`${failure} KO`)}`)
}
console.log('####')
}