Skip to content

Commit beb45df

Browse files
committed
feat: Return async function
BREAKING CHANGE: Returns async function instead of a function calling a callback
1 parent 680ed44 commit beb45df

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const {callbackify} = require('util');
21
const parser = require('conventional-commits-parser').sync;
32
const debug = require('debug')('semantic-release:commit-analyzer');
43
const loadParserConfig = require('./lib/load-parser-config');
@@ -63,4 +62,4 @@ async function commitAnalyzer(pluginConfig, {commits, logger}) {
6362
return releaseType;
6463
}
6564

66-
module.exports = callbackify(commitAnalyzer);
65+
module.exports = commitAnalyzer;

test/integration.test.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {promisify} from 'util';
21
import test from 'ava';
32
import {stub} from 'sinon';
43
import commitAnalyzer from '..';
@@ -11,7 +10,7 @@ test.beforeEach(t => {
1110

1211
test('Parse with "conventional-changelog-angular" by default', async t => {
1312
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
14-
const releaseType = await promisify(commitAnalyzer)({}, {commits, logger: t.context.logger});
13+
const releaseType = await commitAnalyzer({}, {commits, logger: t.context.logger});
1514

1615
t.is(releaseType, 'minor');
1716
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[0].message));
@@ -23,7 +22,7 @@ test('Parse with "conventional-changelog-angular" by default', async t => {
2322

2423
test('Accept "preset" option', async t => {
2524
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
26-
const releaseType = await promisify(commitAnalyzer)({preset: 'eslint'}, {commits, logger: t.context.logger});
25+
const releaseType = await commitAnalyzer({preset: 'eslint'}, {commits, logger: t.context.logger});
2726

2827
t.is(releaseType, 'minor');
2928
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[0].message));
@@ -35,7 +34,7 @@ test('Accept "preset" option', async t => {
3534

3635
test('Accept "config" option', async t => {
3736
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
38-
const releaseType = await promisify(commitAnalyzer)(
37+
const releaseType = await commitAnalyzer(
3938
{config: 'conventional-changelog-eslint'},
4039
{commits, logger: t.context.logger}
4140
);
@@ -53,7 +52,7 @@ test('Accept a "parseOpts" object as option', async t => {
5352
{message: '%%BUGFIX%% First fix (fixes #123)'},
5453
{message: '%%FEATURE%% Second feature (fixes #456)'},
5554
];
56-
const releaseType = await promisify(commitAnalyzer)(
55+
const releaseType = await commitAnalyzer(
5756
{parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
5857
{commits, logger: t.context.logger}
5958
);
@@ -68,7 +67,7 @@ test('Accept a "parseOpts" object as option', async t => {
6867

6968
test('Accept a partial "parseOpts" object as option', async t => {
7069
const commits = [{message: '%%fix%% First fix (fixes #123)'}, {message: '%%Update%% Second feature (fixes #456)'}];
71-
const releaseType = await promisify(commitAnalyzer)(
70+
const releaseType = await commitAnalyzer(
7271
{
7372
config: 'conventional-changelog-eslint',
7473
parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['type', 'shortDesc']},
@@ -86,7 +85,7 @@ test('Accept a partial "parseOpts" object as option', async t => {
8685

8786
test('Accept a "releaseRules" option that reference a requierable module', async t => {
8887
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
89-
const releaseType = await promisify(commitAnalyzer)(
88+
const releaseType = await commitAnalyzer(
9089
{releaseRules: './test/fixtures/release-rules'},
9190
{commits, logger: t.context.logger}
9291
);
@@ -104,7 +103,7 @@ test('Return "major" if there is a breaking change, using default releaseRules',
104103
{message: 'Fix: First fix (fixes #123)'},
105104
{message: 'Update: Second feature (fixes #456) \n\n BREAKING CHANGE: break something'},
106105
];
107-
const releaseType = await promisify(commitAnalyzer)({preset: 'eslint'}, {commits, logger: t.context.logger});
106+
const releaseType = await commitAnalyzer({preset: 'eslint'}, {commits, logger: t.context.logger});
108107

109108
t.is(releaseType, 'major');
110109
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[0].message));
@@ -116,7 +115,7 @@ test('Return "major" if there is a breaking change, using default releaseRules',
116115

117116
test('Return "patch" if there is only types set to "patch", using default releaseRules', async t => {
118117
const commits = [{message: 'fix: First fix (fixes #123)'}, {message: 'perf: perf improvement'}];
119-
const releaseType = await promisify(commitAnalyzer)({}, {commits, logger: t.context.logger});
118+
const releaseType = await commitAnalyzer({}, {commits, logger: t.context.logger});
120119

121120
t.is(releaseType, 'patch');
122121
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[0].message));
@@ -128,7 +127,7 @@ test('Return "patch" if there is only types set to "patch", using default releas
128127

129128
test('Allow to use regex in "releaseRules" configuration', async t => {
130129
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
131-
const releaseType = await promisify(commitAnalyzer)(
130+
const releaseType = await commitAnalyzer(
132131
{
133132
preset: 'eslint',
134133
releaseRules: [{tag: 'Chore', release: 'patch'}, {message: '/README/', release: 'minor'}],
@@ -146,7 +145,7 @@ test('Allow to use regex in "releaseRules" configuration', async t => {
146145

147146
test('Return "null" if no rule match', async t => {
148147
const commits = [{message: 'doc: doc update'}, {message: 'chore: Chore'}];
149-
const releaseType = await promisify(commitAnalyzer)({}, {commits, logger: t.context.logger});
148+
const releaseType = await commitAnalyzer({}, {commits, logger: t.context.logger});
150149

151150
t.is(releaseType, null);
152151
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[0].message));
@@ -158,7 +157,7 @@ test('Return "null" if no rule match', async t => {
158157

159158
test('Process rules in order and apply highest match', async t => {
160159
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
161-
const releaseType = await promisify(commitAnalyzer)(
160+
const releaseType = await commitAnalyzer(
162161
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'minor'}, {tag: 'Chore', release: 'patch'}]},
163162
{commits, logger: t.context.logger}
164163
);
@@ -176,7 +175,7 @@ test('Process rules in order and apply highest match from config even if default
176175
{message: 'Chore: First chore (fixes #123)'},
177176
{message: 'Docs: update README (fixes #456) \n\n BREAKING CHANGE: break something'},
178177
];
179-
const releaseType = await promisify(commitAnalyzer)(
178+
const releaseType = await commitAnalyzer(
180179
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}, {breaking: true, release: 'minor'}]},
181180
{commits, logger: t.context.logger}
182181
);
@@ -191,7 +190,7 @@ test('Process rules in order and apply highest match from config even if default
191190

192191
test('Use default "releaseRules" if none of provided match', async t => {
193192
const commits = [{message: 'Chore: First chore'}, {message: 'Update: new feature'}];
194-
const releaseType = await promisify(commitAnalyzer)(
193+
const releaseType = await commitAnalyzer(
195194
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}]},
196195
{commits, logger: t.context.logger}
197196
);
@@ -205,42 +204,40 @@ test('Use default "releaseRules" if none of provided match', async t => {
205204
});
206205

207206
test('Throw error if "preset" doesn`t exist', async t => {
208-
const error = await t.throws(promisify(commitAnalyzer)({preset: 'unknown-preset'}, {}));
207+
const error = await t.throws(commitAnalyzer({preset: 'unknown-preset'}, {}));
209208

210209
t.is(error.code, 'MODULE_NOT_FOUND');
211210
});
212211

213212
test('Throw error if "releaseRules" is not an Array or a String', async t => {
214213
await t.throws(
215-
promisify(commitAnalyzer)({releaseRules: {}}, {}),
214+
commitAnalyzer({releaseRules: {}}, {}),
216215
/Error in commit-analyzer configuration: "releaseRules" must be an array of rules/
217216
);
218217
});
219218

220219
test('Throw error if "releaseRules" option reference a requierable module that is not an Array or a String', async t => {
221220
await t.throws(
222-
promisify(commitAnalyzer)({releaseRules: './test/fixtures/release-rules-invalid'}, {}),
221+
commitAnalyzer({releaseRules: './test/fixtures/release-rules-invalid'}, {}),
223222
/Error in commit-analyzer configuration: "releaseRules" must be an array of rules/
224223
);
225224
});
226225

227226
test('Throw error if "config" doesn`t exist', async t => {
228227
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
229-
const error = await t.throws(
230-
promisify(commitAnalyzer)({config: 'unknown-config'}, {commits, logger: t.context.logger})
231-
);
228+
const error = await t.throws(commitAnalyzer({config: 'unknown-config'}, {commits, logger: t.context.logger}));
232229

233230
t.is(error.code, 'MODULE_NOT_FOUND');
234231
});
235232

236233
test('Throw error if "releaseRules" reference invalid commit type', async t => {
237234
await t.throws(
238-
promisify(commitAnalyzer)({preset: 'eslint', releaseRules: [{tag: 'Update', release: 'invalid'}]}, {}),
235+
commitAnalyzer({preset: 'eslint', releaseRules: [{tag: 'Update', release: 'invalid'}]}, {}),
239236
/Error in commit-analyzer configuration: "invalid" is not a valid release type\. Valid values are:\[?.*\]/
240237
);
241238
});
242239

243240
test('Re-Throw error from "conventional-changelog-parser"', async t => {
244241
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
245-
await t.throws(promisify(commitAnalyzer)({parserOpts: {headerPattern: '\\'}}, {commits, logger: t.context.logger}));
242+
await t.throws(commitAnalyzer({parserOpts: {headerPattern: '\\'}}, {commits, logger: t.context.logger}));
246243
});

0 commit comments

Comments
 (0)