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

fix(cli): fix json format handling #360

Merged
merged 18 commits into from
Dec 19, 2023
Merged

fix(cli): fix json format handling #360

merged 18 commits into from
Dec 19, 2023

Conversation

BioPhoton
Copy link
Collaborator

@BioPhoton BioPhoton commented Dec 12, 2023

I added more infos to the issue: #316 also #358 should go before

This PR includes:

  • adopting model
  • adjusting tests

Overview of the target architecture can be found here: https://github.com/code-pushup/cli/wiki/Research:-Module-architecture-and-responsibilities

closes #316

@BioPhoton BioPhoton self-assigned this Dec 12, 2023
@BioPhoton BioPhoton marked this pull request as ready for review December 12, 2023 19:08
Copy link
Collaborator

@Tlacenka Tlacenka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the changes being made to the tests. They often reintroduce the bad practices again or test logic in the wrong place (cli and core are after test refactor). I provided context in the comments below.

packages/cli/src/lib/collect/collect-command.unit.test.ts Outdated Show resolved Hide resolved
Comment on lines +20 to +34
const cli = (options = {}) =>
yargsCli(
objectToCliArgs({
_: 'autorun',
verbose: true,
config: '/test/code-pushup.config.ts',
'persist.outputDir': '/test',
...options,
}),
{
...DEFAULT_CLI_CONFIGURATION,
commands: [yargsAutorunCommandObject()],
},
);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed on purpose for better readability of the tests. By having explicit values present, it is clear which arguments are passed to the test without having to scroll up and look at additional function definitions.

Suggested change
const cli = (options = {}) =>
yargsCli(
objectToCliArgs({
_: 'autorun',
verbose: true,
config: '/test/code-pushup.config.ts',
'persist.outputDir': '/test',
...options,
}),
{
...DEFAULT_CLI_CONFIGURATION,
commands: [yargsAutorunCommandObject()],
},
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are always the same

Copy link
Collaborator

@matejchalk matejchalk Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a huge issue, but a recurring problem, so maybe it helps to explain the motivation better.

In general, it's better when a test contains all the context you need to know regarding what inputs are provided. Extracting setup code goes against this principle. There's a balance to be struck, of course, e.g. when the setup is long and often repeated in different tests, then extracting it may be the better option.

The old version of this test is more understandable for me, because within the it-block I see everything I need to understand it - e.g. "Why do the assertions expect /test/code-pushup.config.ts? Ah yes, because that's what argument was passed in, I see that a few lines above.". But with the new version, the relevant inputs and outputs aren't colocated, so I have to scroll up to understand the whole picture.

In fact, the new cli function is only used in this one test, so there's no advantage with regards to reducing duplication. And I also don't understand why persist.filename is specified here, but e.g. persist.outputDir or config aren't, they seem to be just as relevant to the assertions.

packages/cli/src/lib/autorun/autorun-command.unit.test.ts Outdated Show resolved Hide resolved
BioPhoton and others added 7 commits December 14, 2023 15:49
Co-authored-by: Kateřina Pilátová <katerina.pilatova@flowup.cz>
Co-authored-by: Kateřina Pilátová <katerina.pilatova@flowup.cz>
Co-authored-by: Kateřina Pilátová <katerina.pilatova@flowup.cz>
Co-authored-by: Kateřina Pilátová <katerina.pilatova@flowup.cz>
@BioPhoton BioPhoton merged commit bc9f101 into main Dec 19, 2023
18 checks passed
@BioPhoton BioPhoton deleted the fix-format-inconsistency branch December 19, 2023 14:27
@@ -78,8 +78,7 @@ describe('CLI collect', () => {
expect(stderr).toBe('');

expect(stdout).toContain('Code PushUp Report');
expect(stdout).toContain('Generated reports');
expect(stdout).toContain('report.json');
expect(stdout).not.toContain('Generated reports');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test scenario runs with --persist.format=stdout, that should be removed (no longer a valid option). And then I believe the assertions should stay the same, because JSON should be generated by default.

Comment on lines +32 to +34
format: [
...new Set([...options.persist.format, 'json']),
] as AutorunOptions['persist']['format'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
format: [
...new Set([...options.persist.format, 'json']),
] as AutorunOptions['persist']['format'],
format: [
...new Set([...options.persist.format, 'json'] satisfies Format[]),
],

or:

Suggested change
format: [
...new Set([...options.persist.format, 'json']),
] as AutorunOptions['persist']['format'],
format: [...new Set([...options.persist.format, 'json' as const])],

Comment on lines +20 to +34
const cli = (options = {}) =>
yargsCli(
objectToCliArgs({
_: 'autorun',
verbose: true,
config: '/test/code-pushup.config.ts',
'persist.outputDir': '/test',
...options,
}),
{
...DEFAULT_CLI_CONFIGURATION,
commands: [yargsAutorunCommandObject()],
},
);

Copy link
Collaborator

@matejchalk matejchalk Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a huge issue, but a recurring problem, so maybe it helps to explain the motivation better.

In general, it's better when a test contains all the context you need to know regarding what inputs are provided. Extracting setup code goes against this principle. There's a balance to be struck, of course, e.g. when the setup is long and often repeated in different tests, then extracting it may be the better option.

The old version of this test is more understandable for me, because within the it-block I see everything I need to understand it - e.g. "Why do the assertions expect /test/code-pushup.config.ts? Ah yes, because that's what argument was passed in, I see that a few lines above.". But with the new version, the relevant inputs and outputs aren't colocated, so I have to scroll up to understand the whole picture.

In fact, the new cli function is only used in this one test, so there's no advantage with regards to reducing duplication. And I also don't understand why persist.filename is specified here, but e.g. persist.outputDir or config aren't, they seem to be just as relevant to the assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inconsistency in formats
4 participants