Skip to content

Commit

Permalink
fix(cli): make onlyPlugins filter based on plugin not audit/group slug
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlacenka committed Feb 15, 2024
1 parent c0038b2 commit e963c36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/lib/implementation/only-plugins.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import { CategoryConfig, CoreConfig } from '@code-pushup/models';
import type { CategoryConfig, CoreConfig } from '@code-pushup/models';

export function filterPluginsBySlug(
plugins: CoreConfig['plugins'],
Expand Down Expand Up @@ -29,14 +29,14 @@ export function filterCategoryByPluginSlug(

return categories.filter(category =>
category.refs.every(ref => {
const isNotSkipped = onlyPlugins.includes(ref.slug);
const isNotSkipped = onlyPlugins.includes(ref.plugin);

if (!isNotSkipped && verbose) {
console.info(
`${chalk.yellow('⚠')} Category "${
category.title
}" is ignored because it references audits from skipped plugin "${
ref.slug
ref.plugin
}"`,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,47 @@ describe('filterCategoryByPluginSlug', () => {
expect(
filterCategoryByPluginSlug(
[
{ refs: [{ slug: 'plugin1' }, { slug: 'plugin2' }] },
{ refs: [{ slug: 'plugin3' }] },
{
refs: [{ plugin: 'plugin1' }, { plugin: 'plugin2' }],
},
{ refs: [{ plugin: 'plugin3' }] },
] as CategoryConfig[],
{},
),
).toEqual([
{ refs: [{ slug: 'plugin1' }, { slug: 'plugin2' }] },
{ refs: [{ slug: 'plugin3' }] },
{
refs: [{ plugin: 'plugin1' }, { plugin: 'plugin2' }],
},
{ refs: [{ plugin: 'plugin3' }] },
]);
});

it('should return categories containing only defined plugins', () => {
expect(
filterCategoryByPluginSlug(
[
{ refs: [{ slug: 'plugin1' }, { slug: 'plugin2' }] },
{ refs: [{ slug: 'plugin3' }] },
{
refs: [{ plugin: 'plugin1' }, { plugin: 'plugin2' }],
},
{ refs: [{ plugin: 'plugin3' }] },
] as CategoryConfig[],
{ onlyPlugins: ['plugin1', 'plugin3'] },
),
).toEqual([{ refs: [{ slug: 'plugin3' }] }]);
).toEqual([{ refs: [{ plugin: 'plugin3' }] }]);
});

it('should print ignored category and its first violating plugin', () => {
filterCategoryByPluginSlug(
[
{
title: 'category1',
refs: [{ slug: 'plugin1' }, { slug: 'plugin2' }, { slug: 'plugin4' }],
refs: [
{ plugin: 'plugin1' },
{ plugin: 'plugin2' },
{ plugin: 'plugin4' },
],
},
{ title: 'category2', refs: [{ slug: 'plugin3' }] },
{ title: 'category2', refs: [{ plugin: 'plugin3' }] },
] as CategoryConfig[],
{
onlyPlugins: ['plugin1', 'plugin3'],
Expand Down

0 comments on commit e963c36

Please sign in to comment.