-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathrc.js
56 lines (46 loc) · 1.88 KB
/
rc.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
/* @flow */
import {getRcArgs} from '../src/rc.js';
import * as path from 'path';
const fixturesLoc = path.join(__dirname, 'fixtures', 'rc');
test('resolve .yarnrc args and use --cwd if present', () => {
const args = getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'empty')]);
expect(args.indexOf('--foo') !== -1).toBe(true);
});
test("don't resolve .yarnrc args from the default locations when using --no-default-rc", () => {
const args = getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'empty'), '--no-default-rc']);
expect(args.indexOf('--foo') !== -1).toBe(false);
});
test('resolve .yarnrc args from the extraneous locations when using --use-yarnrc', () => {
const args = getRcArgs('install', [
'--cwd',
path.join(fixturesLoc, 'empty'),
'--no-default-rc',
'--use-yarnrc',
path.join(fixturesLoc, 'empty', '.yarnrc'),
]);
expect(args.indexOf('--foo') !== -1).toBe(true);
});
test('resolve .yarnrc args and use process.cwd() if no --cwd present', () => {
const cwd = process.cwd();
process.chdir(path.join(fixturesLoc, 'empty'));
try {
const args = getRcArgs('install', []);
expect(args.indexOf('--foo') !== -1).toBe(true);
} finally {
process.chdir(cwd);
}
});
test('resolve .yarnrc args and handle --cwd arg inside .yarnrc', () => {
const args = getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'inside')]);
expect(args.indexOf('--foo') !== -1).toBe(true);
});
test('resolve .yarnrc args and bail out of recursive --cwd args inside of .yarnrc', () => {
expect(() => {
getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'recursive')]);
}).toThrowError();
});
test('resolve .yarnrc args and adds command name prefixed arguments', () => {
const args = getRcArgs('add', ['--cwd', path.join(fixturesLoc, 'prefixed')]);
expect(args.indexOf('--foo') !== -1).toBe(true);
expect(args.indexOf('--bar') !== -1).toBe(false);
});