diff --git a/packages/core/package.json b/packages/core/package.json index c45c6dcc1..2a228c939 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -6,9 +6,7 @@ "@code-pushup/models": "*", "@code-pushup/utils": "*", "@code-pushup/portal-client": "^0.6.1", - "chalk": "^5.3.0", - "memfs": "^4.5.0", - "vitest": "1.3.1" + "chalk": "^5.3.0" }, "type": "commonjs", "main": "./index.cjs" diff --git a/packages/core/src/lib/implementation/execute-plugin.ts b/packages/core/src/lib/implementation/execute-plugin.ts index 731f77679..f4cbb42c1 100644 --- a/packages/core/src/lib/implementation/execute-plugin.ts +++ b/packages/core/src/lib/implementation/execute-plugin.ts @@ -142,8 +142,7 @@ export async function executePlugins( progressBar?.endProgress('Done running plugins'); - const errorsTransform = ({ reason }: PromiseRejectedResult) => - String(reason); + const errorsTransform = ({ reason }: PromiseRejectedResult) => String(reason); const results = await Promise.allSettled(pluginsResult); logMultipleResults(results, 'Plugins', undefined, errorsTransform); diff --git a/packages/core/src/lib/implementation/execute-plugin.unit-test.ts b/packages/core/src/lib/implementation/execute-plugin.unit.test.ts similarity index 83% rename from packages/core/src/lib/implementation/execute-plugin.unit-test.ts rename to packages/core/src/lib/implementation/execute-plugin.unit.test.ts index afafc9c8d..992e1bbd2 100644 --- a/packages/core/src/lib/implementation/execute-plugin.unit-test.ts +++ b/packages/core/src/lib/implementation/execute-plugin.unit.test.ts @@ -12,13 +12,10 @@ import { executePlugins, } from './execute-plugin'; -const nodePluginSlug = MINIMAL_PLUGIN_CONFIG_MOCK.slug; - -// eslint-disable-next-line max-lines-per-function describe('executePlugin', () => { it('should execute a valid plugin config', async () => { const pluginResult = await executePlugin(MINIMAL_PLUGIN_CONFIG_MOCK); - expect(pluginResult.audits[0]?.slug).toBe(nodePluginSlug); + expect(pluginResult.audits[0]?.slug).toBe('node-version'); }); it('should yield audit outputs for valid runner config', async () => { @@ -26,9 +23,9 @@ describe('executePlugin', () => { { 'output.json': JSON.stringify([ { - slug: nodePluginSlug, + slug: 'node-version', score: 1, - value: 2, + value: 1, }, ]), }, @@ -43,7 +40,7 @@ describe('executePlugin', () => { outputFile: 'output.json', }, }); - expect(pluginResult.audits[0]?.slug).toBe(nodePluginSlug); + expect(pluginResult.audits[0]?.slug).toBe('node-version'); }); it('should yield audit outputs for a valid runner function', async () => { @@ -51,7 +48,7 @@ describe('executePlugin', () => { ...MINIMAL_PLUGIN_CONFIG_MOCK, runner: () => [ { - slug: nodePluginSlug, + slug: 'node-version', score: 0, value: 1, }, @@ -59,10 +56,10 @@ describe('executePlugin', () => { }); expect(pluginResult.audits).toEqual([ expect.objectContaining({ - slug: nodePluginSlug, + slug: 'node-version', title: 'Node version', score: 0, - value: 2, + value: 1, }), ]); }); @@ -73,7 +70,7 @@ describe('executePlugin', () => { ...MINIMAL_PLUGIN_CONFIG_MOCK, audits: [{ slug: '-invalid-slug', title: 'Invalid audit' }], }), - ).rejects.toThrow(new PluginOutputMissingAuditError(nodePluginSlug)); + ).rejects.toThrow(new PluginOutputMissingAuditError('node-version')); }); it('should throw if invalid runnerOutput is produced', async () => { @@ -92,7 +89,6 @@ describe('executePlugin', () => { }); }); -// eslint-disable-next-line max-lines-per-function describe('executePlugins', () => { it('should execute valid plugins', async () => { const pluginResult = await executePlugins( @@ -108,7 +104,7 @@ describe('executePlugins', () => { expect(pluginResult[0]?.icon).toBe('javascript'); expect(pluginResult[1]?.icon).toBe('nodejs'); - expect(pluginResult[0]?.audits[0]?.slug).toBe(nodePluginSlug); + expect(pluginResult[0]?.audits[0]?.slug).toBe('node-version'); }); it('should throw for invalid plugins', async () => { @@ -131,7 +127,9 @@ describe('executePlugins', () => { it('should print invalid plugin errors and throw', async () => { const pluginConfig = { ...MINIMAL_PLUGIN_CONFIG_MOCK, - runner: vi.fn().mockRejectedValue('plugin 1 error'), + runner: vi + .fn() + .mockRejectedValue('Audit metadata not found for slug node-version'), }; const pluginConfig2 = { ...MINIMAL_PLUGIN_CONFIG_MOCK, @@ -147,15 +145,17 @@ describe('executePlugins', () => { progress: false, }), ).rejects.toThrow( - 'Plugins failed: 2 errors: plugin 1 error, plugin 3 error', + 'Plugins failed: 2 errors: Audit metadata not found for slug node-version, plugin 3 error', ); const logs = ui() .logger.getRenderer() .getLogs() .map(({ message }) => message); expect(logs[0]).toBe('[ yellow(warn) ] Plugins failed: '); - expect(logs[1]).toBe('[ yellow(warn) ] plugin 1 error'); - expect(logs[2]).toBe('[ yellow(warn) ] plugin 3 error'); + expect(logs[1]).toBe( + '[ yellow(warn) ] Audit metadata not found for slug node-version', + ); + expect(pluginConfig.runner).toHaveBeenCalled(); expect(pluginConfig2.runner).toHaveBeenCalled(); expect(pluginConfig3.runner).toHaveBeenCalled(); @@ -166,9 +166,9 @@ describe('executePlugins', () => { { 'output.json': JSON.stringify([ { - slug: nodePluginSlug, + slug: 'node-version', score: 1, - value: 2, + value: 1, }, ]), }, @@ -188,7 +188,7 @@ describe('executePlugins', () => { { slug: (outputs as AuditOutputs)[0]!.slug, score: 1, - value: 2, + value: 1, displayValue: '2.0.0', }, ]), @@ -197,7 +197,7 @@ describe('executePlugins', () => { ], { progress: false }, ); - expect(pluginResult[0]?.audits[0]?.slug).toBe(nodePluginSlug); + expect(pluginResult[0]?.audits[0]?.slug).toBe('node-version'); expect(pluginResult[0]?.audits[0]?.displayValue).toBe('2.0.0'); }); });