-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsettings.unit.test.ts
More file actions
101 lines (93 loc) · 3.03 KB
/
settings.unit.test.ts
File metadata and controls
101 lines (93 loc) · 3.03 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type { CoreConfig } from '@code-pushup/models';
import type { ConfigPatterns } from './models.js';
import { parseConfigPatternsFromString } from './settings.js';
describe('parseConfigPatternsFromString', () => {
it('should return for empty string', () => {
expect(parseConfigPatternsFromString('')).toBeNull();
});
it('should parse full persist and upload configs', () => {
const configPatterns: Required<ConfigPatterns> = {
persist: {
outputDir: '.code-pushup/{projectName}',
filename: 'report',
format: ['json', 'md'],
skipReports: false,
},
upload: {
server: 'https://api.code-pushup.example.com/graphql',
apiKey: 'cp_...',
organization: 'example',
project: '{projectName}',
},
};
expect(
parseConfigPatternsFromString(JSON.stringify(configPatterns)),
).toEqual(configPatterns);
});
it('should parse full persist config without upload config', () => {
const configPatterns: ConfigPatterns = {
persist: {
outputDir: '.code-pushup/{projectName}',
filename: 'report',
format: ['json', 'md'],
skipReports: false,
},
};
expect(
parseConfigPatternsFromString(JSON.stringify(configPatterns)),
).toEqual(configPatterns);
});
it('should fill in default persist values where missing', () => {
expect(
parseConfigPatternsFromString(
JSON.stringify({
persist: {
filename: '{projectName}-report',
},
} satisfies Pick<CoreConfig, 'persist'>),
),
).toEqual<ConfigPatterns>({
persist: {
outputDir: '.code-pushup',
filename: '{projectName}-report',
format: ['json', 'md'],
skipReports: false,
},
});
});
it('should throw if input string is not valid JSON', () => {
expect(() =>
parseConfigPatternsFromString('outputDir: .code-pushup/{projectName}'),
).toThrow('Invalid JSON value for configPatterns input - Unexpected token');
});
it('should throw if persist config is missing', () => {
expect(() => parseConfigPatternsFromString('{}')).toThrow(
/Invalid shape of configPatterns input.*expected object, received undefined.*at persist/s,
);
});
it('should throw if persist config has invalid values', () => {
expect(() =>
parseConfigPatternsFromString(
JSON.stringify({ persist: { format: 'json' } }),
),
).toThrow(
/Invalid shape of configPatterns input.*expected array, received string.*at persist\.format/s,
);
});
it('should throw if upload config has missing values', () => {
expect(() =>
parseConfigPatternsFromString(
JSON.stringify({
persist: {},
upload: {
server: 'https://api.code-pushup.example.com/graphql',
organization: 'example',
project: '{projectName}',
},
}),
),
).toThrow(
/Invalid shape of configPatterns input.*expected string, received undefined.*at upload\.apiKey/s,
);
});
});