Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(utils): use cliui as central logger #487

Merged
merged 92 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
51e054c
refactor: replace table with new logger
BioPhoton Feb 7, 2024
0f948ee
wip
BioPhoton Feb 7, 2024
d011474
refactor(core): use new logger
BioPhoton Feb 8, 2024
c36e4c6
refactor(cli): use new logger
BioPhoton Feb 8, 2024
d05b6fb
refactor(cli): use new logger in more places
BioPhoton Feb 8, 2024
501d1dc
test(cli): fix unit tests
BioPhoton Feb 15, 2024
22e1b1b
test: add setup script for cliui
BioPhoton Feb 15, 2024
d15aede
revert
BioPhoton Feb 15, 2024
fca0ffe
Merge branch 'main' into use-table-from-cliui
BioPhoton Feb 15, 2024
a13b9cd
fix merge
BioPhoton Feb 15, 2024
0e80809
merge main
BioPhoton Feb 17, 2024
df12a11
test: use setup scripts for cliui tests
BioPhoton Feb 17, 2024
9aa946d
fix(cli): typing
BioPhoton Feb 18, 2024
70605ad
Merge branch 'main' into use-table-from-cliui
BioPhoton Feb 23, 2024
8998692
Merge branch 'main' into use-table-from-cliui
BioPhoton Feb 23, 2024
df13bed
Merge remote-tracking branch 'origin/use-table-from-cliui' into use-t…
BioPhoton Feb 23, 2024
a09095a
test(utils): fix flaky toGitPath tests
matejchalk Feb 29, 2024
bb33a71
Merge branch 'main' into use-table-from-cliui
BioPhoton Feb 29, 2024
0048870
Merge branch 'main' into use-table-from-cliui
BioPhoton Feb 29, 2024
1c7e2a2
marge main
BioPhoton Feb 29, 2024
fe76fb3
Merge branch 'main' into use-table-from-cliui
BioPhoton Mar 1, 2024
58c483a
marge main
BioPhoton Mar 1, 2024
27f66b3
Merge branch 'main' into git-tests-fix
BioPhoton Mar 1, 2024
54fabe4
wip
BioPhoton Mar 1, 2024
1de146c
test(utils): added test folder per describe
BioPhoton Mar 2, 2024
cde964d
test(utils): move git tests folder out of tmp
BioPhoton Mar 2, 2024
974a724
test(utils): add config
BioPhoton Mar 2, 2024
3cd6739
Merge branch 'git-tests-fix' into use-table-from-cliui
BioPhoton Mar 2, 2024
09fc11b
wip
BioPhoton Mar 2, 2024
76aefb4
test: use nested describe within tmp folder
Tlacenka Mar 4, 2024
22258e4
Merge branch 'main' into use-table-from-cliui
BioPhoton Mar 5, 2024
0f8aee3
refactor(utils): fix tests
BioPhoton Mar 6, 2024
e0b6d6b
refactor(core): fix tests in persist
BioPhoton Mar 6, 2024
70d32f4
Merge branch 'main' into use-table-from-cliui
BioPhoton Mar 6, 2024
58b60f3
refactor: fix tests
BioPhoton Mar 7, 2024
d25fc97
Merge branch 'main' into use-table-from-cliui
BioPhoton Mar 7, 2024
35f6071
refactor(core): fix lint
BioPhoton Mar 7, 2024
ec15166
test: use setup scripts for logger mode
BioPhoton Mar 7, 2024
dad96ba
Update .github/workflows/ci.yml
BioPhoton Mar 7, 2024
41f6253
Update packages/utils/src/lib/execute-process.ts
BioPhoton Mar 7, 2024
dcea0c9
test(utils): refactor setup scripts
BioPhoton Mar 7, 2024
35adb48
test(utils): refactor setup scripts
BioPhoton Mar 7, 2024
aa37c21
refactor(utils): rename errorCallback to errorsTransform
BioPhoton Mar 8, 2024
5b893e6
Update packages/core/src/lib/implementation/execute-plugin.unit-test.ts
BioPhoton Mar 8, 2024
0eeb75e
Update packages/utils/package.json
BioPhoton Mar 8, 2024
4bea57e
Merge branch 'main' into use-table-from-cliui
BioPhoton Mar 8, 2024
82fb9d7
refactor(utils): rename Callback to Transform
BioPhoton Mar 8, 2024
ef9a437
Merge remote-tracking branch 'origin/use-table-from-cliui' into use-t…
BioPhoton Mar 8, 2024
ef9661f
Update packages/utils/src/lib/log-results.unit.test.ts
BioPhoton Mar 8, 2024
b71f907
Update packages/cli/src/lib/implementation/only-plugins.utils.unit.te…
BioPhoton Mar 8, 2024
16a0f44
Update packages/core/src/lib/implementation/execute-plugin.ts
BioPhoton Mar 8, 2024
72a04c2
Update packages/utils/src/lib/log-results.ts
BioPhoton Mar 8, 2024
28717cf
test(core): fix tests
BioPhoton Mar 8, 2024
36306dc
test(core): fix tests
BioPhoton Mar 8, 2024
c243904
wip
BioPhoton Mar 8, 2024
46649cf
refactor: use log helper
BioPhoton Mar 8, 2024
a681f96
refactor: format
BioPhoton Mar 8, 2024
df57b73
refactor(utils): adjust setup scripts
BioPhoton Mar 8, 2024
ca70149
refactor: adjust setup scripts
BioPhoton Mar 8, 2024
158823e
Update packages/utils/src/lib/verbose-utils.unit.test.ts
BioPhoton Mar 8, 2024
c591331
refactor: update snapshots
BioPhoton Mar 8, 2024
ac41972
refactor: update snapshots
BioPhoton Mar 8, 2024
b0846c3
refactor: adjust setup scripts
BioPhoton Mar 8, 2024
fc14474
refactor: revert report log logic for detail section
BioPhoton Mar 8, 2024
e77c6b4
update snapshots
BioPhoton Mar 8, 2024
dec81c9
update snapshots
BioPhoton Mar 9, 2024
45ccd93
Update packages/utils/src/lib/verbose-utils.unit.test.ts
BioPhoton Mar 9, 2024
bec7758
refactor(coverage-plugin): use logger instead of console
BioPhoton Mar 9, 2024
cf72b75
refactor(coverage-plugin): format
BioPhoton Mar 9, 2024
a59846f
refactor: test values
BioPhoton Mar 11, 2024
6d84643
refactor: adjust tests
BioPhoton Mar 11, 2024
8449932
refactor: format
BioPhoton Mar 11, 2024
d5d4cf6
Update packages/utils/src/lib/reports/log-stdout-summary.integration.…
BioPhoton Mar 12, 2024
f4223b2
layout
BioPhoton Mar 12, 2024
92ba78a
adjust table
BioPhoton Mar 12, 2024
e62ae83
adjust table
BioPhoton Mar 12, 2024
4fcd62e
fix
BioPhoton Mar 12, 2024
48c3a63
fix
BioPhoton Mar 12, 2024
6cf446e
fix
BioPhoton Mar 12, 2024
339b7b2
Update packages/cli/src/lib/print-config/print-config-command.unit.te…
BioPhoton Mar 12, 2024
65a77e0
Update testing/test-setup/src/lib/cliui.mock.ts
BioPhoton Mar 12, 2024
b585d27
fix
BioPhoton Mar 12, 2024
dfda614
remove mock
BioPhoton Mar 12, 2024
a1b5619
fix
BioPhoton Mar 12, 2024
b162010
format
BioPhoton Mar 12, 2024
16868a2
fix
BioPhoton Mar 12, 2024
e811ed0
test: adjust matcher
BioPhoton Mar 12, 2024
cd82524
Merge branch 'main' into use-table-from-cliui
BioPhoton Mar 12, 2024
d2e0f1e
fix
BioPhoton Mar 12, 2024
a8a3a62
fix
BioPhoton Mar 12, 2024
58d65ac
Merge remote-tracking branch 'origin/git-test-tmp-folder' into use-ta…
BioPhoton Mar 12, 2024
fba81fc
fix
BioPhoton Mar 12, 2024
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
8 changes: 4 additions & 4 deletions code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const config: CoreConfig = {

plugins: [
await eslintPlugin(await eslintConfigFromNxProjects()),
await coveragePlugin({
/*await coveragePlugin({
coverageToolCommand: {
command: 'npx',
args: [
Expand All @@ -65,7 +65,7 @@ const config: CoreConfig = {
],
},
reports: await getNxCoveragePaths(['unit-test', 'integration-test']),
}),
}),*/
fileSizePlugin({
directory: './dist/examples/react-todos-app',
pattern: /\.js$/,
Expand Down Expand Up @@ -98,7 +98,7 @@ const config: CoreConfig = {
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
{
/* {
slug: 'code-coverage',
title: 'Code coverage',
refs: [
Expand All @@ -109,7 +109,7 @@ const config: CoreConfig = {
weight: 1,
},
],
},
},*/
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
{
slug: 'custom-checks',
title: 'Custom checks',
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@code-pushup/portal-client": "^0.6.1",
"@isaacs/cliui": "^8.0.2",
"@poppinss/cliui": "^6.3.0",
"@poppinss/cliui": "^6.4.0",
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
"@swc/helpers": "0.5.3",
"bundle-require": "^4.0.1",
"chalk": "^5.3.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@code-pushup/core": "*",
"yargs": "^17.7.2",
"chalk": "^5.3.0",
"@code-pushup/utils": "*",
"@poppinss/cliui": "^6.3.0"
"@code-pushup/utils": "*"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/lib/autorun/autorun-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
collectAndPersistReports,
upload,
} from '@code-pushup/core';
import { ui } from '@code-pushup/utils';
import { CLI_NAME } from '../constants';
import {
collectSuccessfulLog,
renderConfigureCategoriesHint,
renderIntegratePortalHint,
ui,
uploadSuccessfulLog,
} from '../implementation/logging';
import { yargsOnlyPluginsOptionsDefinition } from '../implementation/only-plugins.options';
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/lib/collect/collect-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import {
CollectAndPersistReportsOptions,
collectAndPersistReports,
} from '@code-pushup/core';
import { link } from '@code-pushup/utils';
import { link, ui } from '@code-pushup/utils';
import { CLI_NAME } from '../constants';
import {
collectSuccessfulLog,
renderConfigureCategoriesHint,
ui,
} from '../implementation/logging';
import { yargsOnlyPluginsOptionsDefinition } from '../implementation/only-plugins.options';

Expand Down
15 changes: 2 additions & 13 deletions packages/cli/src/lib/implementation/logging.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { cliui } from '@poppinss/cliui';
import chalk from 'chalk';
import { link } from '@code-pushup/utils';

export type CliUi = ReturnType<typeof cliui>;

// eslint-disable-next-line import/no-mutable-exports,functional/no-let
export let singletonUiInstance: CliUi | undefined;
export function ui(): CliUi {
if (singletonUiInstance === undefined) {
singletonUiInstance = cliui();
}
return singletonUiInstance;
}
import { link, ui } from '@code-pushup/utils';

export function renderConfigureCategoriesHint(): void {
ui().logger.info(
Expand All @@ -26,6 +14,7 @@ export function uploadSuccessfulLog(url: string): void {
ui().logger.success('Upload successful!');
ui().logger.success(link(url));
}

export function collectSuccessfulLog(): void {
ui().logger.success('Collecting report successful!');
}
Expand Down
8 changes: 0 additions & 8 deletions packages/cli/src/lib/implementation/logging.unit.test.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/cli/src/lib/implementation/only-plugins.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk';
import type { CategoryConfig, CoreConfig } from '@code-pushup/models';
import { ui } from '@code-pushup/utils';

export function filterPluginsBySlug(
plugins: CoreConfig['plugins'],
Expand Down Expand Up @@ -32,7 +33,7 @@ export function filterCategoryByPluginSlug(
const isNotSkipped = onlyPlugins.includes(ref.plugin);

if (!isNotSkipped && verbose) {
console.info(
ui().logger.info(
`${chalk.yellow('⚠')} Category "${
category.title
}" is ignored because it references audits from skipped plugin "${
Expand All @@ -58,7 +59,7 @@ export function validateOnlyPluginsOption(
: [];

if (missingPlugins.length > 0 && verbose) {
console.warn(
ui().logger.warning(
`${chalk.yellow(
'⚠',
)} The --onlyPlugin argument references plugins with "${missingPlugins.join(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect } from 'vitest';
import { CategoryConfig, CoreConfig } from '@code-pushup/models';
import { getLogMessages } from '@code-pushup/test-utils';
import { ui } from '@code-pushup/utils';
import {
filterCategoryByPluginSlug,
filterPluginsBySlug,
Expand Down Expand Up @@ -86,10 +88,11 @@ describe('filterCategoryByPluginSlug', () => {
verbose: true,
},
);
expect(console.info).toHaveBeenCalledWith(
expect.stringContaining('"category1" is ignored'),
const logs = getLogMessages(ui().logger);
expect(logs[0]).toEqual(
expect.stringContaining('Category "category1" is ignored'),
);
expect(console.info).toHaveBeenCalledWith(
expect(logs[0]).toEqual(
expect.stringContaining('skipped plugin "plugin2"'),
);
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
});
Expand All @@ -110,9 +113,10 @@ describe('validateOnlyPluginsOption', () => {
verbose: true,
},
);
expect(console.warn).toHaveBeenCalledWith(
const logs = getLogMessages(ui().logger);
expect(logs[0]).toEqual(
expect.stringContaining(
'plugins with "plugin3", "plugin4" slugs, but no such plugins are present',
'The --onlyPlugin argument references plugins with "plugin3", "plugin4" slugs',
),
);
});
Expand All @@ -125,6 +129,6 @@ describe('validateOnlyPluginsOption', () => {
verbose: true,
},
);
expect(console.warn).not.toHaveBeenCalled();
expect(getLogMessages(ui().logger)).toHaveLength(0);
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/lib/print-config/print-config-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandModule } from 'yargs';
import { ui } from '@code-pushup/utils';
import { filterKebabCaseKeys } from '../implementation/global.utils';
import { ui } from '../implementation/logging';
import { onlyPluginsOption } from '../implementation/only-plugins.options';

export function yargsConfigCommandObject() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeAll, describe, expect } from 'vitest';
import { describe, expect, vi } from 'vitest';
import { getLogMessages } from '@code-pushup/test-utils';
import { ui } from '@code-pushup/utils';
import { DEFAULT_CLI_CONFIGURATION } from '../../../mocks/constants';
import { ui } from '../implementation/logging';
import { yargsCli } from '../yargs-cli';
import { yargsConfigCommandObject } from './print-config-command';

Expand All @@ -15,11 +16,6 @@ vi.mock('@code-pushup/core', async () => {
});

describe('print-config-command', () => {
beforeAll(() => {
// initialize it in raw mode
ui().switchMode('raw');
});

it('should filter out meta arguments and kebab duplicates', async () => {
await yargsCli(
[
Expand All @@ -31,30 +27,13 @@ describe('print-config-command', () => {
{ ...DEFAULT_CLI_CONFIGURATION, commands: [yargsConfigCommandObject()] },
).parseAsync();

const log = ui().logger.getLogs()[0];

expect(log).toEqual(
expect.objectContaining({
message: expect.not.stringContaining('"$0":'),
}),
);

expect(log).toEqual(
expect.objectContaining({
message: expect.not.stringContaining('"_":'),
}),
);

expect(log).toEqual(
expect.objectContaining({
message: expect.stringContaining('"outputDir": "destinationDir"'),
}),
);
const log = getLogMessages(ui().logger)[0];
expect(log).toEqual(expect.not.stringContaining('"$0":'));
expect(log).toEqual(expect.not.stringContaining('"_":'));
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved

expect(log).toEqual(
expect.objectContaining({
message: expect.not.stringContaining('"output-dir":'),
}),
expect.stringContaining('"outputDir": "destinationDir"'),
);
expect(log).toEqual(expect.not.stringContaining('"output-dir":'));
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/lib/upload/upload-command.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import chalk from 'chalk';
import { ArgumentsCamelCase, CommandModule } from 'yargs';
import { UploadOptions, upload } from '@code-pushup/core';
import { ui } from '@code-pushup/utils';
import { CLI_NAME } from '../constants';
import {
renderIntegratePortalHint,
ui,
uploadSuccessfulLog,
} from '../implementation/logging';

Expand Down
1 change: 1 addition & 0 deletions packages/cli/vite.config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig({
include: ['src/**/*.unit.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['../../global-setup.ts'],
setupFiles: [
'../../testing/test-setup/src/lib/cliui.mock.ts',
'../../testing/test-setup/src/lib/fs.mock.ts',
'../../testing/test-setup/src/lib/git.mock.ts',
'../../testing/test-setup/src/lib/console.mock.ts',
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/lib/implementation/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ export async function executePlugins(

progressBar?.endProgress('Done running plugins');

const errorsCallback = ({ reason }: PromiseRejectedResult) => {
console.error(reason);
};
const errorsTransform = ({ reason }: PromiseRejectedResult) => String(reason);
const results = await Promise.allSettled(pluginsResult);

logMultipleResults(results, 'Plugins', undefined, errorsCallback);
logMultipleResults(results, 'Plugins', undefined, errorsTransform);

const { fulfilled, rejected } = groupByStatus(results);
if (rejected.length > 0) {
Expand Down
Loading