Skip to content

Commit 1c22dfa

Browse files
committed
feat(cli): use default report paths if --before/--after missing in compare command
1 parent 4692287 commit 1c22dfa

File tree

12 files changed

+80
-62
lines changed

12 files changed

+80
-62
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ testem.log
4444
Thumbs.db
4545

4646
# generated Code PushUp reports
47-
**/.code-pushup
47+
/.code-pushup
4848

4949
# Nx workspace cache
5050
.nx

e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/target-report.json renamed to e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/report-after.json

File renamed without changes.

e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/target-report.md renamed to e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/report-after.md

File renamed without changes.

e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/source-report.json renamed to e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/report-before.json

File renamed without changes.

e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/source-report.md renamed to e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/report-before.md

File renamed without changes.

e2e/cli-e2e/tests/compare.e2e.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ describe('CLI compare', () => {
3939
it('should compare report.json files and create report-diff.json and report-diff.md', async () => {
4040
await executeProcess({
4141
command: 'npx',
42-
args: [
43-
'@code-pushup/cli',
44-
'compare',
45-
`--before=${path.join('.code-pushup', 'source-report.json')}`,
46-
`--after=${path.join('.code-pushup', 'target-report.json')}`,
47-
],
42+
args: ['@code-pushup/cli', 'compare'],
4843
cwd: existingDir,
4944
});
5045

packages/cli/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Refer to the [Common Command Options](#common-command-options) for the list of a
279279
| **`--from`** | `string` | n/a | Hash to start in history |
280280
| **`--to`** | `string` | n/a | Hash to end in history |
281281

282-
### `compare` command
282+
#### `compare` command
283283

284284
Usage:
285285
`code-pushup compare --before SOURCE_PATH --after TARGET_PATH [options]`
@@ -289,11 +289,13 @@ Compare 2 reports and produce a report diff file.
289289

290290
In addition to the [Common Command Options](#common-command-options), the following options are recognized by the `compare` command:
291291

292-
| Option | Required | Type | Description |
293-
| -------------- | :------: | -------- | ----------------------------------- |
294-
| **`--before`** | yes | `string` | Path to source `report.json`. |
295-
| **`--after`** | yes | `string` | Path to target `report.json`. |
296-
| **`--label`** | no | `string` | Label for diff (e.g. project name). |
292+
| Option | Type | Default | Description |
293+
| -------------- | -------- | -------------------------------------- | ----------------------------------- |
294+
| **`--before`** | `string` | `.code-pushup/report-before.json` [^1] | Path to source `report.json`. |
295+
| **`--after`** | `string` | `.code-pushup/report-after.json` [^1] | Path to target `report.json`. |
296+
| **`--label`** | `string` | n/a | Label for diff (e.g. project name). |
297+
298+
[^1]: Uses `persist` config to determine report paths, so default file paths are actually `${persist.outputDir}/${persist.filename}-before.json` and `${persist.outputDir}/${persist.filename}-after.json`.
297299

298300
#### `print-config` command
299301

@@ -309,7 +311,7 @@ In addition to the [Common Command Options](#common-command-options), the follow
309311
| -------------- | :------: | -------- | -------------------------------------------------------- |
310312
| **`--output`** | no | `string` | Path to output file to print config (default is stdout). |
311313

312-
### `merge-diffs` command
314+
#### `merge-diffs` command
313315

314316
Usage:
315317
`code-pushup merge-diffs --files PATH_1 PATH_2 ... [options]`
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import type { Diff } from '@code-pushup/utils';
2-
3-
export type CompareOptions = Diff<string> & { label?: string };
1+
export type CompareOptions = {
2+
before?: string;
3+
after?: string;
4+
label?: string;
5+
};

packages/cli/src/lib/implementation/compare.options.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export function yargsCompareOptionsDefinition(): Record<
99
before: {
1010
describe: 'Path to source report.json',
1111
type: 'string',
12-
demandOption: true,
1312
},
1413
after: {
1514
describe: 'Path to target report.json',
1615
type: 'string',
17-
demandOption: true,
1816
},
1917
label: {
2018
describe: 'Label for diff (e.g. project name)',

packages/cli/src/lib/yargs-cli.int.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,6 @@ describe('yargsCli', () => {
160160
expect(parsedArgv.after).toBe('target-report.json');
161161
});
162162

163-
it('should error if required compare option is missing', () => {
164-
expect(() =>
165-
yargsCli<GeneralCliOptions & CompareOptions>([], {
166-
options: { ...options, ...yargsCompareOptionsDefinition() },
167-
noExitProcess: true,
168-
}).parse(),
169-
).toThrow('Missing required arguments: before, after');
170-
});
171-
172163
it('should parse merge-diffs options', async () => {
173164
const parsedArgv = await yargsCli<GeneralCliOptions & MergeDiffsOptions>(
174165
[

0 commit comments

Comments
 (0)