|
1 | 1 | import path from 'node:path';
|
2 | 2 | import type { CoreConfig } from '@code-pushup/models';
|
3 |
| -import { parsePersistConfig, persistedFilesFromConfig } from './persist.js'; |
| 3 | +import { |
| 4 | + type EnhancedPersistConfig, |
| 5 | + parsePersistConfig, |
| 6 | + persistedFilesFromConfig, |
| 7 | +} from './persist.js'; |
4 | 8 |
|
5 | 9 | describe('persistedFilesFromConfig', () => {
|
6 | 10 | it('should return default report paths when no config is set', () => {
|
@@ -72,17 +76,47 @@ describe('persistedFilesFromConfig', () => {
|
72 | 76 | });
|
73 | 77 |
|
74 | 78 | describe('parsePersistConfig', () => {
|
75 |
| - it('should validate only persist config', async () => { |
| 79 | + it('should validate only persist and upload config', async () => { |
76 | 80 | await expect(
|
77 | 81 | parsePersistConfig({
|
78 | 82 | persist: {
|
79 | 83 | outputDir: '.code-pushup',
|
80 | 84 | filename: 'report',
|
81 | 85 | format: ['json', 'md'],
|
82 | 86 | },
|
| 87 | + upload: { |
| 88 | + server: 'https://code-pushup-api.dunder-mifflin.org/graphql', |
| 89 | + apiKey: 'cp_abcdef0123456789', |
| 90 | + organization: 'dunder-mifflin', |
| 91 | + project: 'website', |
| 92 | + }, |
83 | 93 | // missing props (slug, etc.)
|
84 | 94 | plugins: [{ title: 'some plugin', audits: [{ title: 'some audit' }] }],
|
85 | 95 | } as CoreConfig),
|
| 96 | + ).resolves.toEqual({ |
| 97 | + persist: { |
| 98 | + outputDir: '.code-pushup', |
| 99 | + filename: 'report', |
| 100 | + format: ['json', 'md'], |
| 101 | + }, |
| 102 | + upload: { |
| 103 | + server: 'https://code-pushup-api.dunder-mifflin.org/graphql', |
| 104 | + apiKey: 'cp_abcdef0123456789', |
| 105 | + organization: 'dunder-mifflin', |
| 106 | + project: 'website', |
| 107 | + }, |
| 108 | + } satisfies EnhancedPersistConfig); |
| 109 | + }); |
| 110 | + |
| 111 | + it('should accept missing upload config', async () => { |
| 112 | + await expect( |
| 113 | + parsePersistConfig({ |
| 114 | + persist: { |
| 115 | + outputDir: '.code-pushup', |
| 116 | + filename: 'report', |
| 117 | + format: ['json', 'md'], |
| 118 | + }, |
| 119 | + }), |
86 | 120 | ).resolves.toEqual({
|
87 | 121 | persist: {
|
88 | 122 | outputDir: '.code-pushup',
|
@@ -114,7 +148,20 @@ describe('parsePersistConfig', () => {
|
114 | 148 | await expect(
|
115 | 149 | parsePersistConfig({ persist: { format: ['json', 'html'] } }),
|
116 | 150 | ).rejects.toThrow(
|
117 |
| - /^Invalid persist config - ZodError:.*Invalid option: expected one of \\"json\\"\|\\"md\\"/s, |
| 151 | + /^Code PushUp config is invalid.*Invalid option: expected one of "json"\|"md".*at persist\.format\[1]/s, |
| 152 | + ); |
| 153 | + }); |
| 154 | + |
| 155 | + it('should error if upload config is invalid', async () => { |
| 156 | + await expect( |
| 157 | + parsePersistConfig({ |
| 158 | + upload: { |
| 159 | + organization: 'dunder-mifflin', |
| 160 | + project: 'website', |
| 161 | + }, |
| 162 | + }), |
| 163 | + ).rejects.toThrow( |
| 164 | + /^Code PushUp config is invalid.*Invalid input: expected string, received undefined.*at upload\.server.*at upload\.apiKey/s, |
118 | 165 | );
|
119 | 166 | });
|
120 | 167 | });
|
0 commit comments