Skip to content

Commit 9dfd315

Browse files
committed
test(core): add failing test case for global extends resolving
1 parent ee64fe6 commit 9dfd315

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-angular']
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-angular']
3+
};

@commitlint/core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"lodash": "^4.17.4",
9494
"path-exists": "^3.0.0",
9595
"resolve-from": "^3.0.0",
96+
"resolve-global": "^0.1.0",
9697
"semver": "^5.3.0"
9798
}
9899
}

@commitlint/core/src/library/resolve-extends.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import test from 'ava';
2+
import execa from 'execa';
3+
import {fix} from '@commitlint/test';
4+
import * as sander from '@marionebl/sander';
25
import resolveExtends from './resolve-extends';
36

47
const id = id => id;
@@ -14,6 +17,33 @@ test('returns an equivalent object as passed in', t => {
1417
t.deepEqual(actual, expected);
1518
});
1619

20+
test.serial.failing('falls back to global install', async t => {
21+
const prev = process.env.NPM_PACKAGES;
22+
23+
const cwd = await fix.bootstrap('fixtures/global-install');
24+
const prefix = `${cwd}/commitlint-npm-packages`;
25+
26+
const npm = args => execa('npm', args, {cwd});
27+
28+
await sander.mkdir(cwd, 'commitlint-npm-packages');
29+
await npm(['install', '--global', '@commitlint/config-angular', '--prefix', prefix]);
30+
31+
process.env.NPM_PACKAGES = prefix;
32+
33+
const input = {extends: ['@commitlint/config-angular']};
34+
35+
t.notThrows(() => resolveExtends(input, {cwd}));
36+
37+
process.env.NPM_PACKAGES = prev;
38+
});
39+
40+
test.serial('fails for missing extends', async t => {
41+
const cwd = await fix.bootstrap('fixtures/missing-install');
42+
const input = {extends: ['@commitlint/foo-bar']};
43+
44+
t.throws(() => resolveExtends(input, {cwd}), /Cannot find module "@commitlint\/foo-bar" from/);
45+
});
46+
1747
test('uses empty prefix by default', t => {
1848
const input = {extends: ['extender-name']};
1949

0 commit comments

Comments
 (0)