-
Notifications
You must be signed in to change notification settings - Fork 6
/
ecosystem-ci.ts
83 lines (75 loc) · 2.1 KB
/
ecosystem-ci.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import fs from 'fs'
import path from 'path'
import process from 'process'
import { cac } from 'cac'
import { setupEnvironment } from './utils'
import { CommandOptions, RunOptions } from './types'
const cli = cac()
cli
.command('[...suites]', 'run selected suites')
.option(
'--verify',
'verify checkouts by running tests before using next nx',
{ default: false },
)
.action(async (suites, options: CommandOptions) => {
const { root, workspace } = await setupEnvironment()
const suitesToRun = getSuitesToRun(suites, root)
const runOptions: RunOptions = {
root,
workspace,
release: options.release,
verify: options.verify,
skipGit: false,
}
for (const suite of suitesToRun) {
await run(suite, runOptions)
}
})
cli
.command('run-suites [...suites]', 'run single suite')
.option('--verify', 'verify checkout by running tests before using next nx', {
default: false,
})
.action(async (suites, options: CommandOptions) => {
const { root, workspace } = await setupEnvironment()
const suitesToRun = getSuitesToRun(suites, root)
const runOptions: RunOptions = {
...options,
root,
workspace,
}
for (const suite of suitesToRun) {
await run(suite, runOptions)
}
})
cli.help()
cli.parse()
async function run(suite: string, options: RunOptions) {
const { test } = await import(`./tests/${suite}.ts`)
await test({
...options,
workspace: path.resolve(options.workspace, suite),
})
}
function getSuitesToRun(suites: string[], root: string) {
let suitesToRun: string[] = suites
const availableSuites: string[] = fs
.readdirSync(path.join(root, 'tests'))
.filter((f: string) => !f.startsWith('_') && f.endsWith('.ts'))
.map((f: string) => f.slice(0, -3))
availableSuites.sort()
if (suitesToRun.length === 0) {
suitesToRun = availableSuites
} else {
const invalidSuites = suitesToRun.filter(
(x) => !x.startsWith('_') && !availableSuites.includes(x),
)
if (invalidSuites.length) {
console.log(`invalid suite(s): ${invalidSuites.join(', ')}`)
console.log(`available suites: ${availableSuites.join(', ')}`)
process.exit(1)
}
}
return suitesToRun
}