-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathself-exam.js
78 lines (59 loc) · 1.62 KB
/
self-exam.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict'
import { describe, it, reporter } from './testease.js'
import { benchmark } from './bench.js'
async function selfExam () {
describe('Testease Framework')
it('synchronous success', function () {
return true
})
await it('async success', async function () {
return true
})
it.fails('synchronous failure', function () {
return false
})
await it.fails('async failure', async function () {
return false
})
await it.fails('timeout of async tests', async function () {
await new Promise((resolve) => setTimeout(resolve, 100))
return true
}, 0)
it.fails('catches synchronous errors', function () {
throw new Error('Hello, error!')
})
await it.fails('catches async errors', async function () {
throw new Error('Hello, error!')
})
it.fails('non-boolean as test result causes failure', function () {
return 0
})
it.fails('errors on attempted timeout of sync code', function () {
}, 0)
it('fails successfully (for coverage)', function () {
throw new Error('Oops')
})
const results = await reporter()
return results
}
const args = process?.argv.slice(2).map((a) => a.toLowerCase())
const options = {
silent: false
}
if (args.includes('--silent') || args.includes('-q')) {
options.silent = true
}
if (args.includes('--bench') || args.includes('-b')) {
const timeLimit = parseInt(args.filter((a) => /\d+/.test(a))[0]) || 500
benchmark(selfExam, timeLimit).then((result) => {
if (!options.silent) {
console.log(result)
}
})
} else {
selfExam().then((result) => {
if (!options.silent) {
console.log(result)
}
})
}