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
4 changes: 2 additions & 2 deletions e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Options:
s [string] [default: \\"code-pushup.config.js\\"]
--persist.outputDir Directory for the produced reports [string]
--persist.filename Filename for the produced reports. [string]
--persist.format Format of the report output. e.g. \`md\`, \`json\`, \`st
dout\` [array]
--persist.format Format of the report output. e.g. \`md\`, \`json\`
[array]
--upload.organization Organization slug from portal [string]
--upload.project Project slug from portal [string]
--upload.server URL to your portal server [string]
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _If you're looking for programmatic usage, then refer to the underlying [@code-p
export default {
persist: {
outputDir: '.code-pushup',
format: ['json', 'md', 'stdout'],
format: ['json', 'md'],
},
plugins: [
// ...
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/implementation/core-config-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function yargsCoreConfigOptionsDefinition(): Record<ArgNames, Options> {
type: 'string',
},
'persist.format': {
describe: 'Format of the report output. e.g. `md`, `json`, `stdout`',
describe: 'Format of the report output. e.g. `md`, `json`',
type: 'array',
},
// upload
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/lib/implementation/persist.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ describe('persistReport', () => {
expect(() => readReport('md')).toThrow('no such file or directory');
});

it('should log to console when format is stdout`', async () => {
const persist = persistConfig({ outputDir, format: ['stdout'] });
it('should log to console regardless of format`', async () => {
const persist = persistConfig({ outputDir, format: [] });

await persistReport(dummyReport, {
...dummyConfig,
Expand All @@ -109,7 +109,6 @@ describe('persistReport', () => {
const jsonReport: Report = readReport('json');
expect(jsonReport.packageName).toBe('@code-pushup/core');

expect(console.log).toHaveBeenCalledTimes(0);
expect(() => readReport('md')).toThrow('no such file or directory');
});

Expand All @@ -124,7 +123,6 @@ describe('persistReport', () => {
`${FOOTER_PREFIX} [Code PushUp](${README_LINK})`,
);

expect(console.log).toHaveBeenCalledTimes(0);
expect(() => readFileSync(reportPath('json'))).not.toThrow(
'no such file or directory',
);
Expand All @@ -133,7 +131,7 @@ describe('persistReport', () => {
it('should persist all formats`', async () => {
const persist = persistConfig({
outputDir,
format: ['json', 'md', 'stdout'],
format: ['json', 'md'],
});
await persistReport(dummyReport, {
...dummyConfig,
Expand All @@ -154,7 +152,7 @@ describe('persistReport', () => {
});

it('should persist some formats`', async () => {
const persist = persistConfig({ outputDir, format: ['md', 'stdout'] });
const persist = persistConfig({ outputDir, format: ['md'] });
await persistReport(dummyReport, {
...dummyConfig,
persist,
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/lib/implementation/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ export async function persistReport(
const { persist } = config;
const outputDir = persist.outputDir;
const filename = persist.filename;
const format =
persist.format && persist.format.length !== 0 ? persist.format : ['stdout'];
let scoredReport;
if (format.includes('stdout')) {
scoredReport = scoreReport(report);
console.log(reportToStdout(scoredReport));
}
const format = persist.format ?? [];

let scoredReport = scoreReport(report);
console.log(reportToStdout(scoredReport));

// collect physical format outputs
const results: { format: string; content: string }[] = [
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/lib/persist-config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { z } from 'zod';
import { fileNameSchema, filePathSchema } from './implementation/schemas';

export const formatSchema = z.enum(['json', 'stdout', 'md']);
export const formatSchema = z.enum(['json', 'md']);
export type Format = z.infer<typeof formatSchema>;

export const persistConfigSchema = z.object({
outputDir: filePathSchema('Artifacts folder'),
filename: fileNameSchema('Artifacts file name (without extension)').default(
'report',
),
format: z.array(formatSchema).default(['stdout']).optional(), // @TODO remove default or optional value and otherwise it will not set defaults.
format: z.array(formatSchema).default(['json']).optional(), // @TODO remove default or optional value and otherwise it will not set defaults.
});

export type PersistConfig = z.infer<typeof persistConfigSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CoreConfig } from '@code-pushup/models';
const config: CoreConfig = {
persist: {
outputDir: '.code-pushup',
format: ['json', 'md', 'stdout'],
format: ['json', 'md'],
},
plugins: [
// ...
Expand Down