/
config.js
85 lines (73 loc) · 2.89 KB
/
config.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
/* @flow */
import type {CLIFunctionReturn} from '../../src/types.js';
import * as reporters from '../../src/reporters/index.js';
import * as configCmd from '../../src/cli/commands/config.js';
import {run as buildRun} from './_helpers.js';
import * as fs from '../../src/util/fs.js';
const path = require('path');
const runConfig = buildRun.bind(
null,
reporters.ConsoleReporter,
'',
(args, flags, config, reporter): CLIFunctionReturn => {
config.registries.yarn.homeConfigLoc = path.join(config.cwd, '.yarnrc');
return configCmd.run(config, reporter, flags, args);
},
);
test('write cache-folder config into .yarnrc file', (): Promise<void> => {
return runConfig(['set', 'cache-folder', 'folder_dir_for_test'], {}, '', async config => {
const configFile = await fs.readFile(config.registries.yarn.homeConfigLoc);
expect(configFile).toContain('folder_dir_for_test');
});
});
test('cache-folder flag has higher priorities than .yarnrc file', (): Promise<void> => {
return runConfig(
['set', 'cache-folder', 'set_config_folder_dir'],
{cacheFolder: 'flag_config_folder_dir'},
'',
config => {
expect(config.cacheFolder).toContain('flag_config_folder_dir');
},
);
});
test('write global-folder config into .yarnrc file', (): Promise<void> => {
return runConfig(['set', 'global-folder', 'folder_dir_for_test'], {}, '', async config => {
const configFile = await fs.readFile(config.registries.yarn.homeConfigLoc);
expect(configFile).toContain('folder_dir_for_test');
});
});
test('global-folder flag has higher priorities than .yarnrc file', (): Promise<void> => {
return runConfig(
['set', 'global-folder', 'set_config_folder_dir'],
{globalFolder: 'flag_config_folder_dir'},
'',
config => {
expect(config.globalFolder).toContain('flag_config_folder_dir');
},
);
});
test('bin-links flag has higher priorities than .yarnrc file', (): Promise<void> => {
return runConfig(['set', 'bin-links', 'true'], {binLinks: false}, '', config => {
expect(config.binLinks).toBe(false);
});
});
test('set true when option value is undefined', (): Promise<void> => {
return runConfig(['set', 'strict-ssl'], {}, '', config => {
expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(true);
});
});
test('set empty string to an option', (): Promise<void> => {
return runConfig(['set', 'version-tag-prefix', ''], {}, '', config => {
expect(config.registries.yarn.homeConfig['version-tag-prefix']).toBe('');
});
});
test('set value "false" to an option', (): Promise<void> => {
return runConfig(['set', 'strict-ssl', 'false'], {}, '', config => {
expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(false);
});
});
test('set value "true" to an option', (): Promise<void> => {
return runConfig(['set', 'strict-ssl', 'true'], {}, '', config => {
expect(config.registries.yarn.homeConfig['strict-ssl']).toBe(true);
});
});