-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
90 lines (80 loc) · 3.19 KB
/
index.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
const nixt = require('nixt')
const os = require('os')
describe('co-commit', () => {
it('works using CLI arguments', done => {
nixt()
.run('node index.js -m "test commit" -co "mariiapunda" --dry-run')
.expect(({ stdout }) => {
const expectedGitCommand = `git commit -m "test commit${os.EOL +
os.EOL}Co-authored-by: mariiapunda <mariiapunda@users.noreply.github.com>" --dry-run`
if (!stdout.includes(expectedGitCommand))
return new Error('Does not output correct git command')
})
.code(0)
.end(done)
})
it('prompts for input if no arguments are provided', done => {
nixt()
.run('node index.js --dry-run')
.on(/Co-Author GitHub/)
.respond(`mariiapunda${os.EOL}`)
.on(/Commit Message:/)
.respond(`another test commit${os.EOL}`)
.expect(({ stdout }) => {
const expectedGitCommand = `git commit -m "another test commit${os.EOL +
os.EOL}Co-authored-by: mariiapunda <mariiapunda@users.noreply.github.com>" --dry-run`
if (!stdout.includes(expectedGitCommand))
return new Error('Does not output correct git command')
})
.code(0)
.end(done)
})
it('skips relevant prompts if some data is provided as an argument', done => {
nixt()
.run('node index.js -co "sophiebits" --dry-run')
.on(/Commit Message:/)
.respond(`committing with sophie${os.EOL}`)
.expect(({ stdout }) => {
const expectedGitCommand = `git commit -m "committing with sophie${os.EOL +
os.EOL}Co-authored-by: sophiebits <sophiebits@users.noreply.github.com>" --dry-run`
if (!stdout.includes(expectedGitCommand))
return new Error('Does not output correct git command')
})
.code(0)
.end(done)
})
it('supports comma-separated co-authors provided via the prompt', done => {
nixt()
.run('node index.js --dry-run')
.on(/Co-Author GitHub/)
.respond(`mariiapunda, tom-bonnike${os.EOL}`)
.on(/Commit Message:/)
.respond(`test commit with multiple authors${os.EOL}`)
.expect(({ stdout }) => {
const expectedGitCommand = `git commit -m "test commit with multiple authors${os.EOL +
os.EOL}Co-authored-by: mariiapunda <mariiapunda@users.noreply.github.com>${
os.EOL
}Co-authored-by: tom-bonnike <tom-bonnike@users.noreply.github.com>"`
if (!stdout.includes(expectedGitCommand))
return new Error('Does not output correct git command')
})
.code(0)
.end(done)
})
it('supports comma-separated co-authors provided as an argument', done => {
nixt()
.run(
'node index.js -m "test commit with multiple authors" -co "mariiapunda, tom-bonnike" --dry-run'
)
.expect(({ stdout }) => {
const expectedGitCommand = `git commit -m "test commit with multiple authors${os.EOL +
os.EOL}Co-authored-by: mariiapunda <mariiapunda@users.noreply.github.com>${
os.EOL
}Co-authored-by: tom-bonnike <tom-bonnike@users.noreply.github.com>"`
if (!stdout.includes(expectedGitCommand))
return new Error('Does not output correct git command')
})
.code(0)
.end(done)
})
})