From 53faf3b5a1a75f25fd893dd59bad94fcb41498e7 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sat, 20 Jan 2018 23:13:26 -0500 Subject: [PATCH] fix: fix regex rules evaluation --- lib/analyze-commit.js | 2 +- test/analyze-commit.test.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/analyze-commit.js b/lib/analyze-commit.js index de23515c..6738d1b5 100644 --- a/lib/analyze-commit.js +++ b/lib/analyze-commit.js @@ -21,7 +21,7 @@ module.exports = (releaseRules, commit) => { commit, omit(rule, ['release', 'breaking']), (obj, src) => - /^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/.*\/$/.exec(src)[1]).test(obj) : undefined + /^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/(.*)\/$/.exec(src)[1]).test(obj) : undefined ) ) .every(match => { diff --git a/test/analyze-commit.test.js b/test/analyze-commit.test.js index 2e22bf4b..6abb9893 100644 --- a/test/analyze-commit.test.js +++ b/test/analyze-commit.test.js @@ -46,15 +46,21 @@ test('Return undefined if there is no match', t => { }); test('Match with regex', t => { - const commit = {type: 'docs', scope: 'README'}; + const rules = [{type: 'docs', scope: /test\(.*\)/, release: 'minor'}]; + const match = {type: 'docs', scope: 'test(readme): message'}; + const notMatch = {type: 'docs', scope: 'test2(readme): message'}; - t.is(analyzeCommit([{type: 'docs', scope: /RE..ME/, release: 'minor'}], commit), 'minor'); + t.is(analyzeCommit(rules, match), 'minor'); + t.is(analyzeCommit(rules, notMatch), undefined); }); test('Match with regex as string', t => { - const commit = {type: 'docs', scope: 'README'}; + const rules = [{type: 'docs', scope: '/test\\(.*\\)/', release: 'minor'}]; + const match = {type: 'docs', scope: 'test(readme): message'}; + const notMatch = {type: 'docs', scope: 'test2(readme): message'}; - t.is(analyzeCommit([{type: 'docs', scope: '/RE..ME/', release: 'minor'}], commit), 'minor'); + t.is(analyzeCommit(rules, match), 'minor'); + t.is(analyzeCommit(rules, notMatch), undefined); }); test('Return highest release type if multiple rules match', t => {