-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
runTests.ts
57 lines (46 loc) · 1.27 KB
/
runTests.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 { readdirSync } from 'node:fs'
import { run } from 'node:test'
import process from 'node:process'
import { spec as Spec } from 'node:test/reporters'
import { basename } from 'node:path'
import { cpus } from 'node:os'
const spec = new Spec()
let exitCode = 0
const files = readdirSync(__dirname)
.filter((f) => f.endsWith('.ts') && f !== basename(__filename))
.map((f) => `${__dirname}/${f}`)
const start = Date.now()
const testStream = run({
files,
timeout: 60 * 1000,
concurrency: cpus().length,
})
testStream.compose(spec).pipe(process.stdout)
const summary: string[] = []
testStream.on('test:fail', (data) => {
exitCode = 1
const error = data.details.error
summary.push(
`${data.file} - "${data.name}" (${Math.round(
data.details.duration_ms,
)}ms)\n${error.toString()} `,
)
})
testStream.on('test:stderr', (data) => {
summary.push(`${data.file} - Error:\n${data.message} `)
})
testStream.once('end', () => {
const duration = Date.now() - start
// print duration in blue
console.log(
'\x1b[34m%s\x1b[0m',
`\nℹ Duration: ${duration / 1000}s\n`,
'\x1b[0m',
)
if (summary.length > 0) {
console.error('\x1b[31m%s\x1b', '\n✖ failing tests:\n')
console.error(summary.join('\n'))
console.error('\n------', '\x1b[0m\n')
}
process.exit(exitCode)
})