Skip to content

Commit f4b4a01

Browse files
committed
refactor(utils): remove duplicate isVerbose helper
1 parent c50ffb9 commit f4b4a01

File tree

7 files changed

+11
-17
lines changed

7 files changed

+11
-17
lines changed

packages/cli/src/lib/implementation/filter.middleware.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe('filterMiddleware', () => {
291291
);
292292

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

296296
filterMiddleware({
297297
onlyPlugins: ['p1'],

packages/cli/src/lib/implementation/validate-filter-options.utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { PluginConfig } from '@code-pushup/models';
22
import {
33
capitalize,
44
filterItemRefsBy,
5-
isVerbose,
65
logger,
76
pluralize,
87
} from '@code-pushup/utils';
@@ -51,14 +50,14 @@ export function validateFilterOption(
5150
}
5251
logger.warn(message);
5352
}
54-
if (skippedValidItems.length > 0 && isVerbose()) {
53+
if (skippedValidItems.length > 0 && logger.isVerbose()) {
5554
const item = getItemType(option, skippedValidItems.length);
5655
const prefix = skippedValidItems.length === 1 ? `a skipped` : `skipped`;
5756
logger.warn(
5857
`The --${option} argument references ${prefix} ${item}: ${skippedValidItems.join(', ')}.`,
5958
);
6059
}
61-
if (isPluginOption(option) && categories.length > 0 && isVerbose()) {
60+
if (isPluginOption(option) && categories.length > 0 && logger.isVerbose()) {
6261
const removedCategories = filterItemRefsBy(categories, ({ plugin }) =>
6362
isOnlyOption(option)
6463
? !itemsToFilterSet.has(plugin)
@@ -82,7 +81,7 @@ export function validateSkippedCategories(
8281
const skippedCategories = originalCategories.filter(
8382
original => !filteredCategories.some(({ slug }) => slug === original.slug),
8483
);
85-
if (skippedCategories.length > 0 && isVerbose()) {
84+
if (skippedCategories.length > 0 && logger.isVerbose()) {
8685
skippedCategories.forEach(category => {
8786
logger.info(
8887
`Category ${category.slug} was removed because all its refs were skipped. Affected refs: ${category.refs

packages/cli/src/lib/implementation/validate-filter-options.utils.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('validateFilterOption', () => {
113113
});
114114

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

118118
validateFilterOption(
119119
'onlyPlugins',
@@ -210,7 +210,7 @@ describe('validateFilterOption', () => {
210210
});
211211

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

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

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

456456
validateSkippedCategories(categories, [
457457
{

packages/plugin-lighthouse/src/lib/runner/utils.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold } from 'ansis';
1+
import ansis from 'ansis';
22
import debug from 'debug';
33
import log from 'lighthouse-logger';
44
import type Details from 'lighthouse/types/lhr/audit-details';
@@ -308,7 +308,7 @@ describe('toAuditOutputs', () => {
308308
{ verbose: true },
309309
),
310310
).toThrow(
311-
`Audit ${bold('cumulative-layout-shift')} failed parsing details:`,
311+
`Audit ${ansis.bold('cumulative-layout-shift')} failed parsing details:`,
312312
);
313313
});
314314
});

packages/utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export {
1616
coerceBooleanValue,
1717
isCI,
1818
isEnvVarEnabled,
19-
isVerbose,
2019
runnerArgsFromEnv,
2120
runnerArgsToEnv,
2221
} from './lib/env.js';

packages/utils/src/lib/env.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ export function isCI() {
1111
return isEnvVarEnabled('CI');
1212
}
1313

14-
export function isVerbose() {
15-
return isEnvVarEnabled('CP_VERBOSE');
16-
}
17-
1814
export function isEnvVarEnabled(name: string): boolean {
1915
const value = coerceBooleanValue(process.env[name]);
2016

testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold } from 'ansis';
1+
import ansis from 'ansis';
22
import { vol } from 'memfs';
33
import { describe, expect, it, vi } from 'vitest';
44
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
@@ -144,7 +144,7 @@ describe('teardownTestFolder', () => {
144144
'/tmp/unit': null,
145145
});
146146
expect(warnSpy).toHaveBeenCalledWith(
147-
`⚠️ You are trying to delete a file instead of a directory - ${bold('/tmp/unit/package.json')}.`,
147+
`⚠️ You are trying to delete a file instead of a directory - ${ansis.bold('/tmp/unit/package.json')}.`,
148148
);
149149
});
150150
});

0 commit comments

Comments
 (0)