Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('filterMiddleware', () => {
);

it('should trigger verbose logging when skipPlugins or onlyPlugins removes categories', () => {
vi.stubEnv('CP_VERBOSE', 'true');
logger.setVerbose(true);

filterMiddleware({
onlyPlugins: ['p1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { PluginConfig } from '@code-pushup/models';
import {
capitalize,
filterItemRefsBy,
isVerbose,
logger,
pluralize,
} from '@code-pushup/utils';
Expand Down Expand Up @@ -51,14 +50,14 @@ export function validateFilterOption(
}
logger.warn(message);
}
if (skippedValidItems.length > 0 && isVerbose()) {
if (skippedValidItems.length > 0 && logger.isVerbose()) {
const item = getItemType(option, skippedValidItems.length);
const prefix = skippedValidItems.length === 1 ? `a skipped` : `skipped`;
logger.warn(
`The --${option} argument references ${prefix} ${item}: ${skippedValidItems.join(', ')}.`,
);
}
if (isPluginOption(option) && categories.length > 0 && isVerbose()) {
if (isPluginOption(option) && categories.length > 0 && logger.isVerbose()) {
const removedCategories = filterItemRefsBy(categories, ({ plugin }) =>
isOnlyOption(option)
? !itemsToFilterSet.has(plugin)
Expand All @@ -82,7 +81,7 @@ export function validateSkippedCategories(
const skippedCategories = originalCategories.filter(
original => !filteredCategories.some(({ slug }) => slug === original.slug),
);
if (skippedCategories.length > 0 && isVerbose()) {
if (skippedCategories.length > 0 && logger.isVerbose()) {
skippedCategories.forEach(category => {
logger.info(
`Category ${category.slug} was removed because all its refs were skipped. Affected refs: ${category.refs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('validateFilterOption', () => {
});

it('should log a category ignored as a result of plugin filtering', () => {
vi.stubEnv('CP_VERBOSE', 'true');
logger.setVerbose(true);

validateFilterOption(
'onlyPlugins',
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('validateFilterOption', () => {
});

it('should log skipped items if verbose mode is enabled', () => {
vi.stubEnv('CP_VERBOSE', 'true');
logger.setVerbose(true);

const plugins = [
{ slug: 'p1', audits: [{ slug: 'a1-p1' }] },
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('validateSkippedCategories', () => {
] as NonNullable<Filterables['categories']>;

it('should log info when categories are removed', () => {
vi.stubEnv('CP_VERBOSE', 'true');
logger.setVerbose(true);

validateSkippedCategories(categories, [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from 'ansis';
import ansis from 'ansis';
import debug from 'debug';
import log from 'lighthouse-logger';
import type Details from 'lighthouse/types/lhr/audit-details';
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('toAuditOutputs', () => {
{ verbose: true },
),
).toThrow(
`Audit ${bold('cumulative-layout-shift')} failed parsing details:`,
`Audit ${ansis.bold('cumulative-layout-shift')} failed parsing details:`,
);
});
});
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export {
coerceBooleanValue,
isCI,
isEnvVarEnabled,
isVerbose,
runnerArgsFromEnv,
runnerArgsToEnv,
} from './lib/env.js';
Expand Down
4 changes: 0 additions & 4 deletions packages/utils/src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export function isCI() {
return isEnvVarEnabled('CI');
}

export function isVerbose() {
return isEnvVarEnabled('CP_VERBOSE');
}

export function isEnvVarEnabled(name: string): boolean {
const value = coerceBooleanValue(process.env[name]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from 'ansis';
import ansis from 'ansis';
import { vol } from 'memfs';
import { describe, expect, it, vi } from 'vitest';
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('teardownTestFolder', () => {
'/tmp/unit': null,
});
expect(warnSpy).toHaveBeenCalledWith(
`⚠️ You are trying to delete a file instead of a directory - ${bold('/tmp/unit/package.json')}.`,
`⚠️ You are trying to delete a file instead of a directory - ${ansis.bold('/tmp/unit/package.json')}.`,
);
});
});
Loading