Skip to content

Commit

Permalink
fix: rollback some unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Jan 30, 2021
1 parent 1c251d2 commit f1bf2d2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions @commitlint/resolve-extends/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,39 @@ test('parserPreset should be merged correctly', () => {

expect(actual).toEqual(expected);
});

test('should correctly merge nested configs', () => {
const input = {extends: ['extender-1']};

const require = (id: string) => {
switch (id) {
case 'extender-1':
return {extends: ['extender-3', 'extender-2']};
case 'extender-2':
return {extends: ['extender-4']};
case 'extender-3':
return {rules: {test: 3}};
case 'extender-4':
return {extends: ['extender-5', 'extender-6'], rules: {test: 4}};
case 'extender-5':
return {rules: {test: 5}};
case 'extender-6':
return {rules: {test: 6}};
default:
return {};
}
};

const ctx = {resolve: id, require: jest.fn(require)} as ResolveExtendsContext;

const actual = resolveExtends(input, ctx);

const expected = {
extends: ['extender-1'],
rules: {
test: 4,
},
};

expect(actual).toEqual(expected);
});
4 changes: 2 additions & 2 deletions @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function loadExtends(
const {extends: e} = config;
const ext = e ? (Array.isArray(e) ? e : [e]) : [];

return ext.reduceRight<ResolvedConfig[]>((configs, raw) => {
return ext.reduce<ResolvedConfig[]>((configs, raw) => {
const load = context.require || require;
const resolved = resolveConfig(raw, context);
const c = load(resolved);
Expand All @@ -81,7 +81,7 @@ function loadExtends(
config.parserPreset = parserPreset;
}

return [...loadExtends(c, ctx), c, ...configs];
return [...configs, ...loadExtends(c, ctx), c];
}, []);
}

Expand Down

0 comments on commit f1bf2d2

Please sign in to comment.