-
Notifications
You must be signed in to change notification settings - Fork 74
/
load-parser-config.test.js
100 lines (85 loc) · 3.76 KB
/
load-parser-config.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import test from 'ava';
import loadParserConfig from '../lib/load-parser-config.js';
import conventionalChangelogAngular from 'conventional-changelog-angular';
const cwd = process.cwd();
/**
* AVA macro to verify that `loadParserConfig` return a parserOpts object.
*
* @method loadPreset
* @param {Object} t AVA assertion library.
* @param {[type]} preset the `conventional-changelog` preset to test.
* @param {Object} pluginOptions The plugin configuration.
*/
async function loadPreset(t, preset, pluginOptions) {
t.truthy((await loadParserConfig({...pluginOptions, preset}, {cwd})).headerPattern);
}
loadPreset.title = (providedTitle, preset) => `${providedTitle} Load "${preset}" preset`.trim();
/**
* AVA macro to verify that `loadParserConfig` return a parserOpts object.
*
* @method loadPreset
* @param {Object} t AVA assertion library.
* @param {[type]} config the `conventional-changelog` config to test.
* @param {Object} pluginOptions The plugin configuration.
*/
async function loadConfig(t, config, pluginOptions) {
t.truthy(
(await loadParserConfig({...pluginOptions, config: `conventional-changelog-${config}`}, {cwd})).headerPattern
);
}
loadConfig.title = (providedTitle, config) => `${providedTitle} Load "${config}" config`.trim();
test('Load "conventional-changelog-angular" by default', async t => {
t.deepEqual(await loadParserConfig({}, {cwd}), (await conventionalChangelogAngular).parserOpts);
});
test('Accept a "parserOpts" object as option', async t => {
const customParserOptions = {
headerPattern: /^##(?<type>.*?)## (?<subject>.*)$/,
headerCorrespondence: ['tag', 'shortDesc'],
};
const parserOptions = await loadParserConfig({parserOpts: customParserOptions}, {cwd});
t.is(customParserOptions.headerPattern, parserOptions.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, parserOptions.headerCorrespondence);
});
test('Accept a partial "parserOpts" object as option that overlaod a preset', async t => {
const customParserOptions = {
headerPattern: /^##(?<type>.*?)## (?<subject>.*)$/,
headerCorrespondence: ['tag', 'shortDesc'],
};
const parserOptions = await loadParserConfig({parserOpts: customParserOptions, preset: 'angular'}, {cwd});
t.is(customParserOptions.headerPattern, parserOptions.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, parserOptions.headerCorrespondence);
t.truthy(parserOptions.noteKeywords);
});
test('Accept a partial "parserOpts" object as option that overlaod a config', async t => {
const customParserOptions = {
headerPattern: /^##(?<type>.*?)## (?<subject>.*)$/,
headerCorrespondence: ['tag', 'shortDesc'],
};
const parserOptions = await loadParserConfig(
{parserOpts: customParserOptions, config: 'conventional-changelog-angular'},
{cwd}
);
t.is(customParserOptions.headerPattern, parserOptions.headerPattern);
t.deepEqual(customParserOptions.headerCorrespondence, parserOptions.headerCorrespondence);
t.truthy(parserOptions.noteKeywords);
});
test(loadPreset, 'angular');
test(loadConfig, 'angular');
test(loadPreset, 'atom');
test(loadConfig, 'atom');
test(loadPreset, 'ember');
test(loadConfig, 'ember');
test(loadPreset, 'eslint');
test(loadConfig, 'eslint');
test(loadPreset, 'express');
test(loadConfig, 'express');
test(loadPreset, 'jshint');
test(loadConfig, 'jshint');
test(loadPreset, 'conventionalcommits', {presetConfig: {}});
test(loadConfig, 'conventionalcommits', {presetConfig: {}});
test('Throw error if "config" doesn`t exist', async t => {
await t.throwsAsync(loadParserConfig({config: 'unknown-config'}, {cwd}), {code: 'MODULE_NOT_FOUND'});
});
test('Throw error if "preset" doesn`t exist', async t => {
await t.throwsAsync(loadParserConfig({preset: 'unknown-preset'}, {cwd}), {code: 'MODULE_NOT_FOUND'});
});