forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-test.js
124 lines (104 loc) · 3.19 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict'
const { test } = require('tap')
const { readFileSync } = require('fs')
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: { ...process.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 help output', (tt) => {
const usage = readFileSync('bin/usage.txt', { encoding: 'utf8' })
const ls = spawn('./bin/cmd.js', ['--help'])
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(),
usage.trim(),
'--help output is as expected')
tt.end()
})
})
t.test('test sha', (tt) => {
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', '2b98d02b52'])
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.match(compiledData.trim(),
/2b98d02b52/,
'output is as expected')
tt.end()
})
})
t.test('test url', (tt) => {
const ls = spawn('./bin/cmd.js', ['--no-validate-metadata', 'https://api.github.com/repos/nodejs/core-validate-commit/commits/2b98d02b52'])
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.match(compiledData.trim(),
/2b98d02b52/,
'output is as expected')
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()
})