forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-test.js
65 lines (54 loc) · 1.72 KB
/
cli-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
57
58
59
60
61
62
63
64
65
'use strict'
const { test } = require('tap')
const { spawn } = require('child_process')
const subsystems = require('../lib/rules/subsystem')
test('Test cli flags', (t) => {
t.test('test list-subsystems', (tt) => {
const ls = spawn('./bin/cmd.js', ['--list-subsystems'], {
env: { FORCE_COLOR: 0 }
})
let compiledData = ''
ls.stdout.on('data', (data) => {
compiledData += data
})
ls.stderr.on('data', (data) => {
tt.fail('This should not happen')
})
ls.on('close', (code) => {
// Get the list of subsytems as an Array.
// Need to match words that also have the "-" in them
const subsystemsFromOutput = compiledData.match(/[\w'-]+/g)
const defaultSubsystems = subsystems.defaults.subsystems
tt.equal(subsystemsFromOutput.length,
defaultSubsystems.length,
'Should have the same length')
// Loop through the output list and compare with the real list
// to make sure they are all there
const missing = []
subsystemsFromOutput.forEach((sub) => {
if (!defaultSubsystems.find((x) => { return x === sub })) {
missing.push(sub)
}
})
tt.equal(missing.length, 0, 'Should have no missing subsystems')
tt.end()
})
})
t.test('test version flag', (tt) => {
const ls = spawn('./bin/cmd.js', ['--version'])
let compiledData = ''
ls.stdout.on('data', (data) => {
compiledData += data
})
ls.stderr.on('data', (data) => {
tt.fail('This should not happen')
})
ls.on('close', (code) => {
tt.equal(compiledData.trim(),
`core-validate-commit v${require('../package.json').version}`,
'output is equal')
tt.end()
})
})
t.end()
})