Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit 89a1fd7

Browse files
author
Charlike Mike Reagent
committed
feat(tests): add some basic tests and ensure immutability
Signed-off-by: Charlike Mike Reagent <[email protected]>
1 parent cc12c73 commit 89a1fd7

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

.all-contributorsrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"projectName": "detect-next-version",
2+
"projectName": "parse-commit-message",
33
"projectOwner": "tunnckoCore",
44
"files": [
55
"CONTRIBUTORS.md"

.nycrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"functions": 0,
44
"branches": 0,
55
"lines": 0,
6-
"exclude": ["test"]
6+
"exclude": [
7+
"test"
8+
]
79
}

CONTRIBUTORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
55

66
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
77
<!-- prettier-ignore -->
8-
| [<img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="150px;"/><br /><sub><b>Charlike Mike Reagent</b></sub>](https://i.am.charlike.online)<br />[💬](#question-olstenlarck "Answering Questions") [💻](https://github.com/tunnckoCore/detect-next-version/commits?author=olstenlarck "Code") [📖](https://github.com/tunnckoCore/detect-next-version/commits?author=olstenlarck "Documentation") [👀](#review-olstenlarck "Reviewed Pull Requests") [⚠️](https://github.com/tunnckoCore/detect-next-version/commits?author=olstenlarck "Tests") |
8+
| [<img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="150px;"/><br /><sub><b>Charlike Mike Reagent</b></sub>](https://i.am.charlike.online)<br />[💬](#question-olstenlarck "Answering Questions") [💻](https://github.com/tunnckoCore/parse-commit-message/commits?author=olstenlarck "Code") [📖](https://github.com/tunnckoCore/parse-commit-message/commits?author=olstenlarck "Documentation") [👀](#review-olstenlarck "Reviewed Pull Requests") [⚠️](https://github.com/tunnckoCore/parse-commit-message/commits?author=olstenlarck "Tests") |
99
| :---: |
1010
<!-- ALL-CONTRIBUTORS-LIST:END -->
1111

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function parse (commitMessage, plugins) {
3737
footer,
3838
}
3939

40-
return arrayify(plugins).reduce((acc, fn) => Object.assign({}, acc, fn(acc)), commit)
40+
return arrayify(plugins).reduce((acc, fn) => {
41+
const result = fn(Object.assign({}, acc))
42+
43+
return Object.assign({}, acc, result)
44+
}, commit)
4145
}
4246

4347
/**

test/index.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,38 @@
44
*/
55

66
const test = require('mukla')
7-
const fn = require('../src/index.js')
7+
const { parse } = require('../src/index.js')
88

9-
test('foo bar', () => {
10-
test.ok(fn)
9+
test('should .parse method to work correctly', (done) => {
10+
const commitMsg1 = `feat(ng-list): Allow custom separator
11+
bla bla bla
12+
13+
BREAKING CHANGE: some breaking change.
14+
Thanks @foobar
15+
`
16+
17+
const commit = parse(commitMsg1)
18+
// => { type: 'feat',
19+
// scope: 'ng-list',
20+
// subject: 'Allow custom separator',
21+
// header: 'feat(ng-list): Allow custom separator',
22+
// body: 'bla bla bla',
23+
// footer: 'BREAKING CHANGE: some breaking change.\nThanks @foobar' }
24+
25+
test.strictEqual(typeof commit, 'object')
26+
test.strictEqual(commit.type, 'feat')
27+
test.strictEqual(commit.scope, 'ng-list')
28+
test.strictEqual(commit.subject, 'Allow custom separator')
29+
test.strictEqual(commit.body, 'bla bla bla')
30+
test.strictEqual(commit.header, 'feat(ng-list): Allow custom separator')
31+
test.strictEqual(
32+
commit.footer,
33+
'BREAKING CHANGE: some breaking change.\nThanks @foobar'
34+
)
35+
done()
36+
})
37+
38+
test('should .parse throw for invalid commit convention message', (done) => {
39+
test.throws(() => parse('foo bar baz'), /invalid commit message/)
40+
done()
1141
})

0 commit comments

Comments
 (0)