forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-config.spec.ts
More file actions
58 lines (47 loc) · 1.48 KB
/
cli-config.spec.ts
File metadata and controls
58 lines (47 loc) · 1.48 KB
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
import { fs, vol } from 'memfs';
import { loadCliConfig } from './cli-config';
vi.mock('fs/promises', async () => {
const memfs: { fs: typeof fs } = await vi.importActual('memfs');
return memfs.fs.promises;
});
vi.mock('os', () => ({
homedir: () => '/home/user'
}));
const exampleConfig = {
calmHubUrl: 'https://example.com/calmhub'
};
const exampleConfig2 = {
calmHubPlugin: '/my/plugin/script'
};
describe('cli-config', () => {
beforeEach(() => {
process.chdir('/');
});
afterEach(() => {
vol.reset();
});
it('loads user config from .calm.json in home dir', async () => {
vol.fromJSON({
'/home/user/.calm.json': JSON.stringify(exampleConfig)
});
const config = await loadCliConfig();
expect(config).toEqual(exampleConfig);
});
it('loads second user config from .calm.json in home dir', async () => {
vol.fromJSON({
'/home/user/.calm.json': JSON.stringify(exampleConfig2)
});
const config = await loadCliConfig();
expect(config).toEqual(exampleConfig2);
});
it('returns null when .calm.json does not exist', async () => {
const config = await loadCliConfig();
expect(config).toBeNull();
});
it('return undefined when .calm.json is invalid JSON', async () => {
vol.fromJSON({
'/home/user/.calm.json': 'invalid json'
});
await expect(loadCliConfig()).resolves.toBeNull();
});
});