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

Commit 682fde8

Browse files
author
Charlike Mike Reagent
committed
fix(detection): improve breaking change string detection
and the tests Signed-off-by: Charlike Mike Reagent <[email protected]>
1 parent e74fd7a commit 682fde8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function isBreakingChange ({ subject, body, footer }) {
8282
body = body || ''
8383
footer = footer || ''
8484

85-
const re = 'BREAKING CHANGE:'
86-
return subject.includes(re) || body.includes(re) || footer.includes(re)
85+
const re = /^BREAKING(?: CHANGES?)?:/
86+
return re.test(subject) || re.test(body) || re.test(footer)
8787
}
8888

8989
/**

test/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

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

99
test('should .parse method to work correctly', (done) => {
1010
const commitMsg1 = `feat(ng-list): Allow custom separator
@@ -14,7 +14,7 @@ BREAKING CHANGE: some breaking change.
1414
Thanks @foobar
1515
`
1616

17-
const commit = parse(commitMsg1)
17+
const commit = parse(commitMsg1, plugins)
1818
// => { type: 'feat',
1919
// scope: 'ng-list',
2020
// subject: 'Allow custom separator',
@@ -32,10 +32,22 @@ Thanks @foobar
3232
commit.footer,
3333
'BREAKING CHANGE: some breaking change.\nThanks @foobar'
3434
)
35+
test.strictEqual(commit.increment, 'major')
3536
done()
3637
})
3738

3839
test('should .parse throw for invalid commit convention message', (done) => {
3940
test.throws(() => parse('foo bar baz'), /invalid commit message/)
4041
done()
4142
})
43+
44+
test('do not treat BREAKING CHANGE as major when not at the beginning', (done) => {
45+
const commitMessage = 'fix(abc): foo bar BREAKING CHANGE here is not valid'
46+
const commit = parse(commitMessage, plugins)
47+
48+
test.strictEqual(commit.type, 'fix')
49+
test.strictEqual(commit.scope, 'abc')
50+
test.strictEqual(commit.subject, 'foo bar BREAKING CHANGE here is not valid')
51+
test.strictEqual(commit.increment, 'patch')
52+
done()
53+
})

0 commit comments

Comments
 (0)