Skip to content

Commit a5dafd2

Browse files
committed
fix: adjust caching tests and types
1 parent c2d951b commit a5dafd2

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

packages/core/src/lib/implementation/collect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export async function collect(options: CollectOptions): Promise<Report> {
2525
const pluginOutputs = await executePlugins(
2626
{
2727
plugins,
28-
persist: { ...persist, outputDir: DEFAULT_PERSIST_OUTPUT_DIR },
28+
persist: { outputDir: DEFAULT_PERSIST_OUTPUT_DIR, ...persist },
2929
// implement together with CLI option
30-
cache: {},
30+
cache: { read: false, write: false },
3131
},
3232
otherOptions,
3333
);

packages/core/src/lib/implementation/execute-plugin.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
Audit,
44
AuditOutput,
55
AuditReport,
6-
CacheConfig,
6+
CacheConfigObject,
77
PersistConfig,
88
PluginConfig,
99
PluginReport,
@@ -46,7 +46,7 @@ import {
4646
export async function executePlugin(
4747
pluginConfig: PluginConfig,
4848
opt: {
49-
cache?: CacheConfig;
49+
cache: CacheConfigObject;
5050
persist: Required<Pick<PersistConfig, 'outputDir'>>;
5151
},
5252
): Promise<PluginReport> {
@@ -59,7 +59,7 @@ export async function executePlugin(
5959
groups,
6060
...pluginMeta
6161
} = pluginConfig;
62-
const { write: cacheWrite = false, read: cacheRead = false } = cache ?? {};
62+
const { write: cacheWrite = false, read: cacheRead = false } = cache;
6363
const { outputDir } = persist;
6464

6565
const { audits, ...executionMeta } = cacheRead
@@ -101,7 +101,7 @@ const wrapProgress = async (
101101
cfg: {
102102
plugin: PluginConfig;
103103
persist: Required<Pick<PersistConfig, 'outputDir'>>;
104-
cache: CacheConfig;
104+
cache: CacheConfigObject;
105105
},
106106
steps: number,
107107
progressBar: ProgressBar | null,
@@ -127,7 +127,7 @@ const wrapProgress = async (
127127
/**
128128
* Execute multiple plugins and aggregates their output.
129129
* @public
130-
* @param plugins array of {@link PluginConfig} objects
130+
* @param cfg
131131
* @param {Object} [options] execution options
132132
* @param {boolean} options.progress show progress bar
133133
* @returns {Promise<PluginReport[]>} plugin report
@@ -149,7 +149,7 @@ export async function executePlugins(
149149
cfg: {
150150
plugins: PluginConfig[];
151151
persist: Required<Pick<PersistConfig, 'outputDir'>>;
152-
cache: CacheConfig;
152+
cache: CacheConfigObject;
153153
},
154154
options?: { progress?: boolean },
155155
): Promise<PluginReport[]> {

packages/core/src/lib/implementation/execute-plugin.unit.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('executePlugin', () => {
2222
await expect(
2323
executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK, {
2424
persist: { outputDir: '' },
25-
cache: {},
25+
cache: { read: false, write: false },
2626
}),
2727
).resolves.toStrictEqual({
2828
slug: 'node',
@@ -60,7 +60,7 @@ describe('executePlugin', () => {
6060
await expect(
6161
executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK, {
6262
persist: { outputDir: 'dummy-path-result-is-mocked' },
63-
cache: { read: true },
63+
cache: { read: true, write: false },
6464
}),
6565
).resolves.toStrictEqual({
6666
slug: 'node',
@@ -103,7 +103,7 @@ describe('executePlugin', () => {
103103
await expect(
104104
executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK, {
105105
persist: { outputDir: 'dummy-path-result-is-mocked' },
106-
cache: { read: true },
106+
cache: { read: true, write: false },
107107
}),
108108
).resolves.toStrictEqual({
109109
slug: 'node',
@@ -138,7 +138,7 @@ describe('executePlugins', () => {
138138
},
139139
],
140140
persist: { outputDir: '.code-pushup' },
141-
cache: {},
141+
cache: { read: false, write: false },
142142
},
143143
{ progress: false },
144144
);
@@ -170,7 +170,7 @@ describe('executePlugins', () => {
170170
},
171171
] satisfies PluginConfig[],
172172
persist: { outputDir: '.code-pushup' },
173-
cache: {},
173+
cache: { read: false, write: false },
174174
},
175175
{ progress: false },
176176
),
@@ -202,7 +202,7 @@ describe('executePlugins', () => {
202202
},
203203
] satisfies PluginConfig[],
204204
persist: { outputDir: '.code-pushup' },
205-
cache: {},
205+
cache: { read: false, write: false },
206206
},
207207
{ progress: false },
208208
),
@@ -243,7 +243,7 @@ describe('executePlugins', () => {
243243
},
244244
] satisfies PluginConfig[],
245245
persist: { outputDir: '.code-pushup' },
246-
cache: {},
246+
cache: { read: false, write: false },
247247
},
248248
{ progress: false },
249249
),
@@ -285,7 +285,7 @@ describe('executePlugins', () => {
285285
},
286286
] satisfies PluginConfig[],
287287
persist: { outputDir: '.code-pushup' },
288-
cache: {},
288+
cache: { read: false, write: false },
289289
},
290290
{ progress: false },
291291
),
@@ -338,7 +338,7 @@ describe('executePlugins', () => {
338338
},
339339
],
340340
persist: { outputDir: '.code-pushup' },
341-
cache: {},
341+
cache: { read: false, write: false },
342342
},
343343
{ progress: false },
344344
);

packages/models/src/lib/cache-config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const cacheConfigShorthandSchema = z
2222
export type CacheConfigShorthand = z.infer<typeof cacheConfigShorthandSchema>;
2323

2424
export const cacheConfigSchema = z
25-
.union(cacheConfigShorthandSchema, cacheConfigObjectSchema)
26-
.describe('Cache configuration for read and write operations');
25+
.union([cacheConfigShorthandSchema, cacheConfigObjectSchema])
26+
.describe('Cache configuration for read and write operations')
27+
.default(false);
2728

2829
export type CacheConfig = z.infer<typeof cacheConfigSchema>;

0 commit comments

Comments
 (0)