Skip to content

Commit c459847

Browse files
committed
feat: export as an object with analyzeCommits step
1 parent 193978f commit c459847

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules');
2222
*
2323
* @returns {String|null} the type of release to create based on the list of commits or `null` if no release has to be done.
2424
*/
25-
async function commitAnalyzer(pluginConfig, context) {
25+
async function analyzeCommits(pluginConfig, context) {
2626
const {commits, logger} = context;
2727
const releaseRules = loadReleaseRules(pluginConfig, context);
2828
const config = await loadParserConfig(pluginConfig, context);
@@ -68,4 +68,4 @@ async function commitAnalyzer(pluginConfig, context) {
6868
return releaseType;
6969
}
7070

71-
module.exports = commitAnalyzer;
71+
module.exports = {analyzeCommits};

test/integration.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22
import {stub} from 'sinon';
3-
import commitAnalyzer from '..';
3+
import {analyzeCommits} from '..';
44

55
const cwd = process.cwd();
66

@@ -12,7 +12,7 @@ test.beforeEach(t => {
1212

1313
test('Parse with "conventional-changelog-angular" by default', async t => {
1414
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
15-
const releaseType = await commitAnalyzer({}, {cwd, commits, logger: t.context.logger});
15+
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});
1616

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

2525
test('Accept "preset" option', async t => {
2626
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
27-
const releaseType = await commitAnalyzer({preset: 'eslint'}, {cwd, commits, logger: t.context.logger});
27+
const releaseType = await analyzeCommits({preset: 'eslint'}, {cwd, commits, logger: t.context.logger});
2828

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

3737
test('Accept "config" option', async t => {
3838
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
39-
const releaseType = await commitAnalyzer(
39+
const releaseType = await analyzeCommits(
4040
{config: 'conventional-changelog-eslint'},
4141
{cwd, commits, logger: t.context.logger}
4242
);
@@ -54,7 +54,7 @@ test('Accept a "parseOpts" object as option', async t => {
5454
{message: '%%BUGFIX%% First fix (fixes #123)'},
5555
{message: '%%FEATURE%% Second feature (fixes #456)'},
5656
];
57-
const releaseType = await commitAnalyzer(
57+
const releaseType = await analyzeCommits(
5858
{parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['tag', 'shortDesc']}},
5959
{cwd, commits, logger: t.context.logger}
6060
);
@@ -69,7 +69,7 @@ test('Accept a "parseOpts" object as option', async t => {
6969

7070
test('Accept a partial "parseOpts" object as option', async t => {
7171
const commits = [{message: '%%fix%% First fix (fixes #123)'}, {message: '%%Update%% Second feature (fixes #456)'}];
72-
const releaseType = await commitAnalyzer(
72+
const releaseType = await analyzeCommits(
7373
{
7474
config: 'conventional-changelog-eslint',
7575
parserOpts: {headerPattern: /^%%(.*?)%% (.*)$/, headerCorrespondence: ['type', 'shortDesc']},
@@ -91,7 +91,7 @@ test('Exclude commits if they have a matching revert commits', async t => {
9191
{hash: '456', message: 'revert: feat(scope): First feature\n\nThis reverts commit 123.\n'},
9292
{message: 'fix(scope): First fix'},
9393
];
94-
const releaseType = await commitAnalyzer({}, {cwd, commits, logger: t.context.logger});
94+
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});
9595

9696
t.is(releaseType, 'patch');
9797
t.true(t.context.log.calledWith('Analyzing commit: %s', commits[2].message));
@@ -101,7 +101,7 @@ test('Exclude commits if they have a matching revert commits', async t => {
101101

102102
test('Accept a "releaseRules" option that reference a requierable module', async t => {
103103
const commits = [{message: 'fix(scope1): First fix'}, {message: 'feat(scope2): Second feature'}];
104-
const releaseType = await commitAnalyzer(
104+
const releaseType = await analyzeCommits(
105105
{releaseRules: './test/fixtures/release-rules'},
106106
{cwd, commits, logger: t.context.logger}
107107
);
@@ -119,7 +119,7 @@ test('Return "major" if there is a breaking change, using default releaseRules',
119119
{message: 'Fix: First fix (fixes #123)'},
120120
{message: 'Update: Second feature (fixes #456) \n\n BREAKING CHANGE: break something'},
121121
];
122-
const releaseType = await commitAnalyzer({preset: 'eslint'}, {cwd, commits, logger: t.context.logger});
122+
const releaseType = await analyzeCommits({preset: 'eslint'}, {cwd, commits, logger: t.context.logger});
123123

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

132132
test('Return "patch" if there is only types set to "patch", using default releaseRules', async t => {
133133
const commits = [{message: 'fix: First fix (fixes #123)'}, {message: 'perf: perf improvement'}];
134-
const releaseType = await commitAnalyzer({}, {cwd, commits, logger: t.context.logger});
134+
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});
135135

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

144144
test('Allow to use regex in "releaseRules" configuration', async t => {
145145
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
146-
const releaseType = await commitAnalyzer(
146+
const releaseType = await analyzeCommits(
147147
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}, {message: '/README/', release: 'minor'}]},
148148
{cwd, commits, logger: t.context.logger}
149149
);
@@ -158,7 +158,7 @@ test('Allow to use regex in "releaseRules" configuration', async t => {
158158

159159
test('Return "null" if no rule match', async t => {
160160
const commits = [{message: 'doc: doc update'}, {message: 'chore: Chore'}];
161-
const releaseType = await commitAnalyzer({}, {cwd, commits, logger: t.context.logger});
161+
const releaseType = await analyzeCommits({}, {cwd, commits, logger: t.context.logger});
162162

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

171171
test('Process rules in order and apply highest match', async t => {
172172
const commits = [{message: 'Chore: First chore (fixes #123)'}, {message: 'Docs: update README (fixes #456)'}];
173-
const releaseType = await commitAnalyzer(
173+
const releaseType = await analyzeCommits(
174174
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'minor'}, {tag: 'Chore', release: 'patch'}]},
175175
{cwd, commits, logger: t.context.logger}
176176
);
@@ -188,7 +188,7 @@ test('Process rules in order and apply highest match from config even if default
188188
{message: 'Chore: First chore (fixes #123)'},
189189
{message: 'Docs: update README (fixes #456) \n\n BREAKING CHANGE: break something'},
190190
];
191-
const releaseType = await commitAnalyzer(
191+
const releaseType = await analyzeCommits(
192192
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}, {breaking: true, release: 'minor'}]},
193193
{cwd, commits, logger: t.context.logger}
194194
);
@@ -203,7 +203,7 @@ test('Process rules in order and apply highest match from config even if default
203203

204204
test('Use default "releaseRules" if none of provided match', async t => {
205205
const commits = [{message: 'Chore: First chore'}, {message: 'Update: new feature'}];
206-
const releaseType = await commitAnalyzer(
206+
const releaseType = await analyzeCommits(
207207
{preset: 'eslint', releaseRules: [{tag: 'Chore', release: 'patch'}]},
208208
{cwd, commits, logger: t.context.logger}
209209
);
@@ -217,40 +217,40 @@ test('Use default "releaseRules" if none of provided match', async t => {
217217
});
218218

219219
test('Throw error if "preset" doesn`t exist', async t => {
220-
const error = await t.throws(commitAnalyzer({preset: 'unknown-preset'}, {cwd}));
220+
const error = await t.throws(analyzeCommits({preset: 'unknown-preset'}, {cwd}));
221221

222222
t.is(error.code, 'MODULE_NOT_FOUND');
223223
});
224224

225225
test('Throw error if "releaseRules" is not an Array or a String', async t => {
226226
await t.throws(
227-
commitAnalyzer({releaseRules: {}}, {cwd}),
227+
analyzeCommits({releaseRules: {}}, {cwd}),
228228
/Error in commit-analyzer configuration: "releaseRules" must be an array of rules/
229229
);
230230
});
231231

232232
test('Throw error if "releaseRules" option reference a requierable module that is not an Array or a String', async t => {
233233
await t.throws(
234-
commitAnalyzer({releaseRules: './test/fixtures/release-rules-invalid'}, {cwd}),
234+
analyzeCommits({releaseRules: './test/fixtures/release-rules-invalid'}, {cwd}),
235235
/Error in commit-analyzer configuration: "releaseRules" must be an array of rules/
236236
);
237237
});
238238

239239
test('Throw error if "config" doesn`t exist', async t => {
240240
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
241-
const error = await t.throws(commitAnalyzer({config: 'unknown-config'}, {cwd, commits, logger: t.context.logger}));
241+
const error = await t.throws(analyzeCommits({config: 'unknown-config'}, {cwd, commits, logger: t.context.logger}));
242242

243243
t.is(error.code, 'MODULE_NOT_FOUND');
244244
});
245245

246246
test('Throw error if "releaseRules" reference invalid commit type', async t => {
247247
await t.throws(
248-
commitAnalyzer({preset: 'eslint', releaseRules: [{tag: 'Update', release: 'invalid'}]}, {cwd}),
248+
analyzeCommits({preset: 'eslint', releaseRules: [{tag: 'Update', release: 'invalid'}]}, {cwd}),
249249
/Error in commit-analyzer configuration: "invalid" is not a valid release type\. Valid values are:\[?.*\]/
250250
);
251251
});
252252

253253
test('Re-Throw error from "conventional-changelog-parser"', async t => {
254254
const commits = [{message: 'Fix: First fix (fixes #123)'}, {message: 'Update: Second feature (fixes #456)'}];
255-
await t.throws(commitAnalyzer({parserOpts: {headerPattern: '\\'}}, {cwd, commits, logger: t.context.logger}));
255+
await t.throws(analyzeCommits({parserOpts: {headerPattern: '\\'}}, {cwd, commits, logger: t.context.logger}));
256256
});

0 commit comments

Comments
 (0)