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
2 changes: 1 addition & 1 deletion examples/cli-e2e/mocks/code-pushup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lighthousePlugin from '../../../dist/packages/plugin-lighthouse';

export default {
persist: { outputPath: 'tmp/cli-config-out.json' },
persist: { outputDir: 'tmp/cli-config-out.json' },
categories: [],
plugins: [
// TODO: uncomment once runner is implemented
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-e2e/mocks/code-pushup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lighthousePlugin from '../../../dist/packages/plugin-lighthouse';

export default {
persist: { outputPath: 'tmp/cli-config-out.json' },
persist: { outputDir: 'tmp/cli-config-out.json' },
categories: [],
plugins: [
// TODO: uncomment once runner is implemented
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-e2e/mocks/code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lighthousePlugin from '../../../dist/packages/plugin-lighthouse';

export default {
persist: { outputPath: 'tmp/cli-config-out.json' },
persist: { outputDir: 'tmp/cli-config-out.json' },
categories: [],
plugins: [
// TODO: uncomment once runner is implemented
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const outputPath = 'tmp';
const outputDir = 'tmp';

export default {
upload: {
Expand All @@ -7,7 +7,7 @@ export default {
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
},
persist: { outputPath },
persist: { outputDir },
plugins: [
{
slug: 'dummy-plugin',
Expand Down Expand Up @@ -41,7 +41,7 @@ export default {
command: 'node',
args: [
'-e',
`require('fs').writeFileSync('${outputPath}/dummy-plugin-output.json', '${JSON.stringify(
`require('fs').writeFileSync('${outputDir}/dummy-plugin-output.json', '${JSON.stringify(
[
{
title: 'Dummy Audit 1',
Expand All @@ -64,7 +64,7 @@ export default {
],
)}')`,
],
outputPath: `${outputPath}/dummy-plugin-output.json`,
outputFile: `${outputDir}/dummy-plugin-output.json`,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/collect/command-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('collect-command-object', () => {
}),
];
const parsedArgv = await cli(args).parseAsync();
expect(parsedArgv.persist.outputPath).toBe('tmp');
expect(parsedArgv.persist.outputDir).toBe('tmp');
expect(parsedArgv.persist?.format).toEqual(['md']);
});
});
6 changes: 3 additions & 3 deletions packages/cli/src/lib/implementation/config-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ describe('applyConfigMiddleware', () => {
const configPathMjs = configPath('mjs');
const config = await configMiddleware({ configPath: configPathMjs });
expect(config.upload.project).toContain('mjs');
expect(config.persist.outputPath).toContain('tmp');
expect(config.persist.outputDir).toContain('tmp');
});

it('should load valid .cjs config', async () => {
const configPathCjs = configPath('cjs');
const config = await configMiddleware({ configPath: configPathCjs });
expect(config.upload.project).toContain('cjs');
expect(config.persist.outputPath).toContain('tmp');
expect(config.persist.outputDir).toContain('tmp');
});

it('should load valid .js config', async () => {
const configPathJs = configPath('js');
const config = await configMiddleware({ configPath: configPathJs });
expect(config.upload.project).toContain('js');
expect(config.persist.outputPath).toContain('tmp');
expect(config.persist.outputDir).toContain('tmp');
});

it('should throw with invalid configPath', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/implementation/config-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function readCoreConfigFromCliArgs(args: ArgsCliObj): CommandBase {
case 'apiKey':
parsedProcessArgs.upload[k] = args[k];
break;
case 'outputPath':
case 'outputDir':
case 'format':
parsedProcessArgs.persist[k] = args[k];
break;
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/config.mock.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const outputPath = 'tmp';
const outputDir = 'tmp';
module.exports = {
upload: {
organization: 'code-pushup',
project: 'cli-cjs',
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
},
persist: { outputPath },
persist: { outputDir },
plugins: [
{
audits: [
Expand All @@ -22,7 +22,7 @@ module.exports = {
command: 'node',
args: [
'-e',
`require('fs').writeFileSync('${outputPath}/out.json', '${JSON.stringify(
`require('fs').writeFileSync('${outputDir}/out.json', '${JSON.stringify(
[
{
title: 'dummy-title',
Expand All @@ -33,7 +33,7 @@ module.exports = {
],
)}')`,
],
outputPath: `${outputPath}/out.json`,
outputFile: `${outputDir}/out.json`,
},
groups: [],
slug: 'command-object-plugin',
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/config.mock.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const outputPath = 'tmp';
const outputDir = 'tmp';
export default {
upload: {
organization: 'code-pushup',
project: 'cli-js',
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
},
persist: { outputPath },
persist: { outputDir },
plugins: [
{
audits: [
Expand All @@ -22,7 +22,7 @@ export default {
command: 'node',
args: [
'-e',
`require('fs').writeFileSync('${outputPath}/out.json', '${JSON.stringify(
`require('fs').writeFileSync('${outputDir}/out.json', '${JSON.stringify(
[
{
title: 'dummy-title',
Expand All @@ -33,7 +33,7 @@ export default {
],
)}')`,
],
outputPath: `${outputPath}/out.json`,
outputFile: `${outputDir}/out.json`,
},
groups: [],
slug: 'command-object-plugin',
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/config.mock.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const outputPath = 'tmp';
const outputDir = 'tmp';
export default {
upload: {
organization: 'code-pushup',
project: 'cli-mjs',
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
},
persist: { outputPath },
persist: { outputDir },
plugins: [
{
audits: [
Expand All @@ -22,7 +22,7 @@ export default {
command: 'node',
args: [
'-e',
`require('fs').writeFileSync('${outputPath}/out.json', '${JSON.stringify(
`require('fs').writeFileSync('${outputDir}/out.json', '${JSON.stringify(
[
{
title: 'dummy-title',
Expand All @@ -33,7 +33,7 @@ export default {
],
)}')`,
],
outputPath: `${outputPath}/out.json`,
outputFile: `${outputDir}/out.json`,
},
groups: [],
slug: 'command-object-plugin',
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/config.mock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const outputPath = 'tmp';
const outputDir = 'tmp';
export default {
upload: {
organization: 'code-pushup',
project: 'cli',
apiKey: 'dummy-api-key',
server: 'https://example.com/api',
},
persist: { outputPath },
persist: { outputDir },
plugins: [
{
audits: [
Expand All @@ -22,7 +22,7 @@ export default {
command: 'node',
args: [
'-e',
`require('fs').writeFileSync('${outputPath}/out.json', '${JSON.stringify(
`require('fs').writeFileSync('${outputDir}/out.json', '${JSON.stringify(
[
{
title: 'dummy-title',
Expand All @@ -33,7 +33,7 @@ export default {
],
)}')`,
],
outputPath: `${outputPath}/out.json`,
outputFile: `${outputDir}/out.json`,
},
groups: [],
slug: 'command-object-plugin',
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/lib/commands/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ vi.mock('fs/promises', async () => {
return memfs.fs.promises;
});

const outputPath = MEMFS_VOLUME;
const reportPath = (path = outputPath, format: 'json' | 'md' = 'json') =>
const outputDir = MEMFS_VOLUME;
const reportPath = (path = outputDir, format: 'json' | 'md' = 'json') =>
join(path, 'report.' + format);

describe('uploadToPortal', () => {
Expand All @@ -59,7 +59,7 @@ describe('uploadToPortal', () => {
server: 'https://example.com/api',
}),
persist: mockPersistConfig({
outputPath,
outputDir,
}),
};
const result = (await upload(cfg)) as unknown as { data: ReportFragment };
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export async function upload(
}

const { apiKey, server, organization, project } = options.upload;
const { outputPath } = options.persist;
const { outputDir } = options.persist;
const report = reportSchema.parse(
JSON.parse(readFileSync(join(outputPath, 'report.json')).toString()),
JSON.parse(readFileSync(join(outputDir, 'report.json')).toString()),
);

const data = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/implementation/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function executePlugin(
try {
const processOutputPath = join(
process.cwd(),
pluginConfig.runner.outputPath,
pluginConfig.runner.outputFile,
);
// read process output from file system and parse it
const auditOutputs = auditOutputsSchema.parse(
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/lib/implementation/persist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ vi.mock('fs/promises', async () => {
return memfs.fs.promises;
});

const outputPath = MEMFS_VOLUME;
const outputDir = MEMFS_VOLUME;
const reportPath = (format: 'json' | 'md') =>
join(outputPath, 'report.' + format);
join(outputDir, 'report.' + format);
const readReport = (format: 'json' | 'md') => {
const reportContent = readFileSync(reportPath(format)).toString();
if (format === 'json') {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('persistReport', () => {
it('should log to console when format is stdout`', async () => {
await persistReport(dummyReport, {
...config,
persist: mockPersistConfig({ outputPath, format: ['stdout'] }),
persist: mockPersistConfig({ outputDir, format: ['stdout'] }),
});
expect(logs.find(log => log.match(/Code Pushup Report/))).toBeTruthy();

Expand All @@ -81,7 +81,7 @@ describe('persistReport', () => {
it('should persist json format`', async () => {
await persistReport(dummyReport, {
...config,
persist: mockPersistConfig({ outputPath, format: ['json'] }),
persist: mockPersistConfig({ outputDir, format: ['json'] }),
});
const jsonReport: Report = readReport('json');
expect(jsonReport.plugins?.[0]?.slug).toBe('plg-0');
Expand All @@ -94,7 +94,7 @@ describe('persistReport', () => {
it('should persist md format`', async () => {
await persistReport(dummyReport, {
...config,
persist: mockPersistConfig({ outputPath, format: ['md'] }),
persist: mockPersistConfig({ outputDir, format: ['md'] }),
});
const mdReport = readFileSync(reportPath('md')).toString();
expect(mdReport).toContain('# Code Pushup Report');
Expand All @@ -109,7 +109,7 @@ describe('persistReport', () => {
await persistReport(dummyReport, {
...config,
persist: mockPersistConfig({
outputPath,
outputDir,
format: ['json', 'md', 'stdout'],
}),
});
Expand All @@ -127,7 +127,7 @@ describe('persistReport', () => {
it('should persist some formats`', async () => {
await persistReport(dummyReport, {
...config,
persist: mockPersistConfig({ outputPath, format: ['md', 'stdout'] }),
persist: mockPersistConfig({ outputDir, format: ['md', 'stdout'] }),
});

expect(() => readFileSync(reportPath('json'))).not.toThrow(
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/lib/implementation/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { CoreConfig, Report } from '@code-pushup/models';
import { formatBytes, reportToMd, reportToStdout } from '@code-pushup/utils';

export class PersistDirError extends Error {
constructor(outputPath: string) {
super(`outPath: ${outputPath} is no directory.`);
constructor(outputDir: string) {
super(`outPath: ${outputDir} is no directory.`);
}
}

Expand All @@ -24,7 +24,7 @@ export async function persistReport(
config: CoreConfig,
): Promise<PersistResult> {
const { persist } = config;
const outputPath = persist.outputPath;
const outputDir = persist.outputDir;
let { format } = persist;
format = format && format.length !== 0 ? format : ['stdout'];

Expand All @@ -42,19 +42,19 @@ export async function persistReport(
results.push({ format: 'md', content: reportToMd(report) });
}

if (!existsSync(outputPath)) {
if (!existsSync(outputDir)) {
try {
mkdirSync(outputPath, { recursive: true });
mkdirSync(outputDir, { recursive: true });
} catch (e) {
console.warn(e);
throw new PersistDirError(outputPath);
throw new PersistDirError(outputDir);
}
}

// write relevant format outputs to file system
return Promise.allSettled(
results.map(({ format, content }) => {
const reportPath = join(outputPath, `report.${format}`);
const reportPath = join(outputDir, `report.${format}`);

return (
writeFile(reportPath, content)
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/lib/persist-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('persistConfigSchema', () => {
expect(() => persistConfigSchema.parse(cfg)).not.toThrow();
});

it('should throw if outputPath is invalid', () => {
const cfg = mockPersistConfig({ outputPath: ' ' });
it('should throw if outputDir is invalid', () => {
const cfg = mockPersistConfig({ outputDir: ' ' });

expect(() => persistConfigSchema.parse(cfg)).toThrow(`path is invalid`);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/lib/persist-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const formatSchema = z.enum(['json', 'stdout', 'md']);
export type Format = z.infer<typeof formatSchema>;

export const persistConfigSchema = z.object({
outputPath: filePathSchema('Artifacts folder'),
outputDir: filePathSchema('Artifacts folder'),
format: z.array(formatSchema).default(['stdout']).optional(),
});

Expand Down
Loading