-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
60 lines (48 loc) · 1.7 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
58
59
import chalk from 'chalk'
import HasteMap from 'jest-haste-map'
import { Worker } from 'jest-worker'
import { cpus } from 'os'
import { join, relative } from 'path'
import { TestResult } from './types'
const root = __dirname
const hasteMap = HasteMap.create({
rootDir: root,
roots: [root],
maxWorkers: cpus.length,
platforms: [],
extensions: ['js'],
name: 'parikshit-test-framework',
retainAllFiles: false
});
(async() => {
const { hasteFS } = await hasteMap.build()
const testFiles = hasteFS.matchFilesWithGlob([
process.argv[2] ? `**/${process.argv[2]}*`: "**/*.test.js"], root)
const worker = new Worker(join(root,'internals','worker.js'), {
enableWorkerThreads: true
})
let hasTestsFailed = false
for await(const testFile of testFiles) {
const { success, errorMessage, testResults } = await (worker as any).runTest(testFile)
const status = success ? chalk.green.inverse(' PASS ') : chalk.red.inverse(' FAIL ')
console.log(status + ' ' + chalk.dim(relative(root, testFile)))
if(!success) {
hasTestsFailed = true
if(testResults) {
(testResults as TestResult["testResults"])
.filter(result => result.errors.length)
.forEach(result => console.log(
result.testPath.slice(1).join(' >> ') + '\n' + result.errors[0]
))
}
if(errorMessage) {
console.log(' ' + errorMessage)
}
}
}
worker.end()
if(hasTestsFailed){
console.log(chalk.red.bold('\nThe test run failed, please fix your failing tests\n'))
process.exitCode = 1
}
})()