-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (57 loc) · 2 KB
/
index.js
File metadata and controls
68 lines (57 loc) · 2 KB
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
/**
* @copyright 2017-present, Charlike Mike Reagent <olsten.larck@gmail.com>
* @license Apache-2.0
*/
/* eslint-disable import/no-commonjs */
const test = require('mukla')
const gitcommit = require('../src/index')
test('should build arguments list from object', (done) => {
const items = gitcommit({
type: 'fix',
scope: 'sasa',
subject: 'this api is change to foo',
body: 'BREAKING CHANGE: instead of bar use foo',
footer: 'fixes #33, resolves #444',
})
test.strictEqual(items.length, 5)
test.strictEqual(items[0], '"fix(sasa): this api is change to foo"')
test.strictEqual(items[1], '""')
test.strictEqual(items[2], '"BREAKING CHANGE: instead of bar use foo"')
test.strictEqual(items[3], '""')
test.strictEqual(items[4], '"fixes #33, resolves #444"')
done()
})
test('should throw if no opts.subject or opts.type', (done) => {
function fixture() {
gitcommit({ body: 'foo bar baz' })
}
test.throws(fixture, 'gitcommit: options.type and options.subject required')
done()
})
test('should allow opts.scope to be optional', (done) => {
const items = gitcommit({
type: 'feat',
subject: 'exciting new feature',
body: 'some longer description of the change',
})
test.strictEqual(items.length, 3)
test.strictEqual(items[0], '"feat: exciting new feature"')
test.strictEqual(items[1], '""')
test.strictEqual(items[2], '"some longer description of the change"')
done()
})
test('should build git commit command', (done) => {
const items = gitcommit({
type: 'chore',
scope: 'pkg',
subject: 'update deps',
body: 'foo bar baz',
footer: 'Signed-off-by: Charlike Mike Reagent',
})
const flags = items.map((x) => `-m ${x}`).join(' ')
const cmd = `git commit --allow-empty-message ${flags}`
test.ok(flags.startsWith('-m "chore(pkg): update deps" -m "" -m "foo bar baz" -m ""'))
test.ok(flags.endsWith('-m "Signed-off-by: Charlike Mike Reagent"'))
test.ok(cmd.startsWith('git commit --allow-empty-message -m "chore(pkg): update deps"'))
done()
})