-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathrunExamples.ts
48 lines (44 loc) · 1.27 KB
/
runExamples.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
import * as allExamples from './example'
import * as _ from 'lodash'
const interval = 1000
function waiter (ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function runExamples () {
let examples = Object.keys(allExamples)
const filter = process.argv[2]
if (filter) {
examples = examples.filter(v => v.toLowerCase().indexOf(filter.toLowerCase()) > -1)
}
console.log(`Total examples: ${examples.length}`)
console.log('------------------------------------------------')
for (const key of examples) {
console.log(`Run ${key}`)
const method = _.get(allExamples, key)
if (typeof method !== 'function') {
console.error(`Method ${key} isn't a function`)
continue
}
console.time(key)
let error: boolean | Error = false
try {
const response = await method()
if (filter) {
console.log(JSON.stringify(response))
}
} catch (e: any) {
error = e
} finally {
console.error(`Method ${key}: ${error ? 'FAIL' : 'OK'}`)
console.timeEnd(key)
console.log('------------------------------------------------')
if (error) {
console.error(error)
process.exit(1)
}
await waiter(interval)
}
}
}
runExamples()
.catch()