Skip to content

Commit 3ca2f45

Browse files
committed
test: adjust tests for new cache options
1 parent 10d3b9a commit 3ca2f45

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

examples/plugins/src/file-size/src/file-size.plugin.int.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ describe('create', () => {
6363

6464
it('should return PluginConfig that executes correctly', async () => {
6565
const pluginConfig = create(baseOptions);
66-
await expect(executePlugin(pluginConfig)).resolves.toMatchObject({
66+
await expect(
67+
executePlugin(pluginConfig, {
68+
persist: { outputDir: '.code-pushup' },
69+
}),
70+
).resolves.toMatchObject({
6771
description:
6872
'A plugin to measure and assert size of files in a directory.',
6973
slug,
@@ -79,7 +83,9 @@ describe('create', () => {
7983
...baseOptions,
8084
pattern: /\.js$/,
8185
});
82-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
86+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
87+
persist: { outputDir: '.code-pushup' },
88+
});
8389

8490
expect(auditOutputs).toHaveLength(1);
8591
expect(auditOutputs[0]?.score).toBe(1);
@@ -91,7 +97,9 @@ describe('create', () => {
9197
...baseOptions,
9298
budget: 0,
9399
});
94-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
100+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
101+
persist: { outputDir: '.code-pushup' },
102+
});
95103

96104
expect(auditOutputs).toHaveLength(1);
97105
expect(auditOutputs[0]?.score).toBe(0);

examples/plugins/src/package-json/src/package-json.plugin.int.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ describe('create-package-json', () => {
4747

4848
it('should return PluginConfig that executes correctly', async () => {
4949
const pluginConfig = create(baseOptions);
50-
const pluginOutput = await executePlugin(pluginConfig);
50+
const pluginOutput = await executePlugin(pluginConfig, {
51+
persist: { outputDir: '.code-pushup' },
52+
});
5153

5254
expect(() => pluginReportSchema.parse(pluginOutput)).not.toThrow();
5355
expect(pluginOutput).toMatchObject(
@@ -68,7 +70,9 @@ describe('create-package-json', () => {
6870
...baseOptions,
6971
license: 'MIT',
7072
});
71-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
73+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
74+
persist: { outputDir: '.code-pushup' },
75+
});
7276

7377
expect(auditOutputs[0]?.value).toBe(1);
7478
expect(auditOutputs[0]?.score).toBe(0);
@@ -85,7 +89,9 @@ describe('create-package-json', () => {
8589
...baseOptions,
8690
type: 'module',
8791
});
88-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
92+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
93+
persist: { outputDir: '.code-pushup' },
94+
});
8995

9096
expect(auditOutputs[1]?.slug).toBe('package-type');
9197
expect(auditOutputs[1]?.score).toBe(0);
@@ -104,7 +110,9 @@ describe('create-package-json', () => {
104110
test: '0',
105111
},
106112
});
107-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
113+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
114+
persist: { outputDir: '.code-pushup' },
115+
});
108116

109117
expect(auditOutputs).toHaveLength(audits.length);
110118
expect(auditOutputs[2]?.slug).toBe('package-dependencies');
@@ -125,7 +133,9 @@ describe('create-package-json', () => {
125133
test: '0',
126134
},
127135
});
128-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
136+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
137+
persist: { outputDir: '.code-pushup' },
138+
});
129139

130140
expect(auditOutputs).toHaveLength(audits.length);
131141
expect(auditOutputs[2]?.score).toBe(0);
@@ -146,7 +156,9 @@ describe('create-package-json', () => {
146156
test: '0',
147157
},
148158
});
149-
const { audits: auditOutputs } = await executePlugin(pluginConfig);
159+
const { audits: auditOutputs } = await executePlugin(pluginConfig, {
160+
persist: { outputDir: '.code-pushup' },
161+
});
150162

151163
expect(auditOutputs).toHaveLength(audits.length);
152164
expect(auditOutputs[2]?.score).toBe(0);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
*
2727
* @public
2828
* @param pluginConfig - {@link ProcessConfig} object with runner and meta
29+
* @param opt
2930
* @returns {Promise<AuditOutput[]>} - audit outputs from plugin runner
3031
* @throws {AuditOutputsMissingAuditError} - if plugin runner output is invalid
3132
*
@@ -45,7 +46,7 @@ import {
4546
export async function executePlugin(
4647
pluginConfig: PluginConfig,
4748
opt: {
48-
cache: CacheConfig;
49+
cache?: CacheConfig;
4950
persist: Required<Pick<PersistConfig, 'outputDir'>>;
5051
},
5152
): Promise<PluginReport> {
@@ -58,7 +59,7 @@ export async function executePlugin(
5859
groups,
5960
...pluginMeta
6061
} = pluginConfig;
61-
const { write: cacheWrite = false, read: cacheRead = false } = cache;
62+
const { write: cacheWrite = false, read: cacheRead = false } = cache ?? {};
6263
const { outputDir } = persist;
6364

6465
const { audits, ...executionMeta } = cacheRead

0 commit comments

Comments
 (0)