Skip to content

Commit dc0f43c

Browse files
committed
test(load): add tests with all types of conventional presets
1 parent c44950f commit dc0f43c

File tree

9 files changed

+78
-1
lines changed

9 files changed

+78
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
parserPreset: 'conventional-changelog-angular'
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "parser-preset-angular",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"conventional-changelog-angular": "5.0.5"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
parserPreset: 'conventional-changelog-conventionalcommits'
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "parser-preset-conventionalcommits",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"conventional-changelog-conventionalcommits": "4.2.1"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['./first-extended']
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['./second-extended']
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
parserPreset: 'conventional-changelog-atom'
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@second-extend/recursive-parser-preset-conventional-atom",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"conventional-changelog-atom": "2.0.3"
6+
}
7+
}

@commitlint/load/src/index.test.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
2-
import {fix, git} from '@commitlint/test';
2+
import {fix, git, npm} from '@commitlint/test';
33
import test from 'ava';
4+
import execa from 'execa';
45
import resolveFrom from 'resolve-from';
56

67
import load from '.';
@@ -327,3 +328,43 @@ test('does not mutate config module reference', async t => {
327328

328329
t.is(before, after);
329330
});
331+
332+
test('resolves parser preset from conventional commits', async t => {
333+
const cwd = await npm.bootstrap('fixtures/parser-preset-conventionalcommits');
334+
const actual = await load({}, {cwd});
335+
336+
t.is(actual.parserPreset.name, 'conventional-changelog-conventionalcommits');
337+
t.is(typeof actual.parserPreset.parserOpts, 'object');
338+
t.deepEqual(
339+
actual.parserPreset.parserOpts.headerPattern,
340+
/^(\w*)(?:\((.*)\))?!?: (.*)$/
341+
);
342+
});
343+
344+
test('resolves parser preset from conventional angular', async t => {
345+
const cwd = await npm.bootstrap('fixtures/parser-preset-angular');
346+
const actual = await load({}, {cwd});
347+
348+
t.is(actual.parserPreset.name, 'conventional-changelog-angular');
349+
t.is(typeof actual.parserPreset.parserOpts, 'object');
350+
t.deepEqual(
351+
actual.parserPreset.parserOpts.headerPattern,
352+
/^(\w*)(?:\((.*)\))?: (.*)$/
353+
);
354+
});
355+
356+
test('recursive resolves parser preset from conventional atom', async t => {
357+
const cwd = await git.bootstrap(
358+
'fixtures/recursive-parser-preset-conventional-atom'
359+
);
360+
// the package file is nested in 2 folders, `npm.bootstrap` cant do that
361+
await execa('npm', ['install'], {
362+
cwd: path.resolve(cwd, 'first-extended', 'second-extended')
363+
});
364+
365+
const actual = await load({}, {cwd});
366+
367+
t.is(actual.parserPreset.name, 'conventional-changelog-atom');
368+
t.is(typeof actual.parserPreset.parserOpts, 'object');
369+
t.deepEqual(actual.parserPreset.parserOpts.headerPattern, /^(:.*?:) (.*)$/);
370+
});

0 commit comments

Comments
 (0)