-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
56 lines (45 loc) · 1.33 KB
/
test.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
import { intro, outro, select, isCancel, cancel, note } from '@clack/prompts'
import { execSync } from 'node:child_process'
import fs from 'node:fs'
import color from 'picocolors'
async function main() {
intro(color.inverse(' run your test suite '))
const testFolder = './tests/'
const arrayOfTestFiles = fs.readdirSync(testFolder)
const options = arrayOfTestFiles.map((file) => {
return {
value: file.replace('.ts', ''),
label: `Test ${color.bold(color.magenta(file.replace('.ts', '')))}`,
}
})
options.push({
value: 'all',
label: `Run ${color.bold(color.magenta('all'))} suites`,
})
let projectType = undefined
const userInputNameOfSuite = process.argv[2]
if (
userInputNameOfSuite === 'all' ||
arrayOfTestFiles.includes(`${userInputNameOfSuite}.ts`)
) {
projectType = userInputNameOfSuite
note(`Selected ${color.bold(color.magenta(projectType))}`)
} else {
projectType = await select({
message: 'Pick which test suite you want to run',
options: options,
})
if (isCancel(projectType)) {
cancel('Operation cancelled')
return process.exit(0)
}
}
projectType = projectType === 'all' ? '' : projectType
outro(
`Running ${color.bold(color.magenta('pnpm run test-ci ' + projectType))}`,
)
execSync(`pnpm run test-ci ${projectType}`, {
stdio: 'inherit',
})
}
main().catch(console.error)