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

Init script for the reassure cli package #275

Closed
wants to merge 16 commits into from
Closed

Conversation

Xiltyn
Copy link
Collaborator

@Xiltyn Xiltyn commented Nov 29, 2022

Init script for the reassure cli package

Summary

More information and acceptance criteria found @ #222

Test plan

You can run the CLI init script using yarn reassure init command. Use the available logLevel cli argument to see different levels of logs verbose, default or silent.

Happenstance findings

chalk is locked at its max version 4. We cannot bump to 5 as we do not support esModules.
@mdjastrzebski I suggest creating an issue to actually migrate the codebase to esModules as this seems to be the way to go nowadays? Wdyt?

Demo video

reassure_init.mov

Updated styling for the ASCII art after the video was recorded

Screenshot 2022-11-29 at 19 33 28

@changeset-bot
Copy link

changeset-bot bot commented Nov 29, 2022

⚠️ No Changeset found

Latest commit: 70368b5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Nov 29, 2022

@mdjastrzebski @thymikee
Do you think it's a good idea to update the docs as a part of this PR or do we wanna close this one first and then we can do another one for the docs. Just gotta remember to not miss it in that case.

WDYT?

@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2022

Performance Comparison Report

Significant Changes To Render Duration

Name Render Duration Render Count
Async Component 285.9 ms → 297.8 ms (+11.9 ms, +4.2%) 7 → 7
Show details
Name Render Duration Render Count
Async Component Baseline
Mean: 285.9 ms
Stdev: 14.7 ms (5.1%)
Runs: 309 301 298 295 289 283 276 273 268 267

Current
Mean: 297.8 ms
Stdev: 9.4 ms (3.2%)
Runs: 308 305 304 303 301 301 297 295 287 277
Baseline
Mean: 7
Stdev: 0 (0.0%)
Runs: 7 7 7 7 7 7 7 7 7 7

Current
Mean: 7
Stdev: 0 (0.0%)
Runs: 7 7 7 7 7 7 7 7 7 7

Meaningless Changes To Render Duration

Show entries
Name Render Duration Render Count
Other Component 20 178.4 ms → 181.5 ms (+3.1 ms, +1.7%) 4 → 4
Other Component 10 175.5 ms → 176.2 ms (+0.7 ms, ±0.0%) 4 → 4
Other Component 10 legacy scenario 173.4 ms → 174.1 ms (+0.7 ms, ±0.0%) 4 → 4
Show details
Name Render Duration Render Count
Other Component 20 Baseline
Mean: 178.4 ms
Stdev: 5.9 ms (3.3%)
Runs: 192 186 185 183 183 182 181 179 179 178 178 178 177 177 174 174 173 172 169 168

Current
Mean: 181.5 ms
Stdev: 8.0 ms (4.4%)
Runs: 201 194 190 189 186 185 185 183 180 180 179 179 179 178 178 176 175 174 173 166
Baseline
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

Current
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Other Component 10 Baseline
Mean: 175.5 ms
Stdev: 3.9 ms (2.2%)
Runs: 181 179 178 178 177 175 174 173 172 168

Current
Mean: 176.2 ms
Stdev: 10.6 ms (6.0%)
Runs: 199 188 178 176 176 174 171 171 168 161
Baseline
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4

Current
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4
Other Component 10 legacy scenario Baseline
Mean: 173.4 ms
Stdev: 4.1 ms (2.3%)
Runs: 178 178 177 175 175 174 172 170 169 166

Current
Mean: 174.1 ms
Stdev: 5.5 ms (3.2%)
Runs: 183 181 178 175 174 173 173 171 168 165
Baseline
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4

Current
Mean: 4
Stdev: 0 (0.0%)
Runs: 4 4 4 4 4 4 4 4 4 4

Changes To Render Count

There are no entries

Added Scenarios

There are no entries

Removed Scenarios

There are no entries

Generated by 🚫 dangerJS against 70368b5

@Xiltyn Xiltyn changed the title feat: added init script for the CLI Init script for the reassure cli package Nov 29, 2022
@mdjastrzebski
Copy link
Member

@Xiltyn You can do the docs separately.

@mdjastrzebski
Copy link
Member

@Xiltyn re ESM: I recall that going full ESM for libraries is a bit more complicated, with some drawbscks for users. We could migrate only Reassure-CLI to ESM, but that is low priority, there are more interesting tasks to do if you have some time to spare :-)

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Nov 30, 2022

@mdjastrzebski Absolutely, it's not like I'm super into the migration necessarily, but it was suggested by @thymikee to me so I wanted to float that idea for the future. Wasn't aware of user-related drawbacks :) thx!

@thymikee
Copy link
Member

thymikee commented Dec 1, 2022

Migration to ESM is something to keep in mind and we should put it on our backlog somewhere. I'm a fan of scoping the tightly-coupled work together, so I'd personally include the docs along the feature. This is not a requirement however, and if it speeds up your work by splitting it up, please do :)

@thymikee
Copy link
Member

thymikee commented Dec 1, 2022

Btw, this needs a rebase

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Dec 1, 2022

Huh, that's true. I'll do the rebase. As for the docs, we'll do them separately as part of my next OSS day. Mainly because it's hard for me to fully commit to a given date atm and I don't wanna keep it on hold. Rebase should be quick, I'll do my best to have it done today eod.

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Dec 13, 2022

Rebased. Please review if you have a couple minutes so that we can finally merge it.

@mdjastrzebski @thymikee

Comment on lines 1 to 11
"use strict";

var _path = _interopRequireDefault(require("path"));
var _reassure = require("reassure");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable import/no-extraneous-dependencies */

(0, _reassure.dangerReassure)({
inputFilePath: _path.default.join(__dirname, './examples/native/.reassure/output.md')
});
//# sourceMappingURL=dangerfile.js.map
Copy link
Member

@thymikee thymikee Dec 13, 2022

Choose a reason for hiding this comment

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

I think this file shouldn't end up here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for spotting, you are correct. Pushed a fix removing this one.

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Dec 13, 2022

@Xiltyn You can do the docs separately.

Docs change added to this one since it's still open :)

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Dec 13, 2022

@mdjastrzebski @thymikee

I added an optional parameter to the init command --jsStandard which allows the user to choose if they want their dangerfile to be a JS or a TS file. It doesn't matter since it has no type annotations anyway so it can be either, we don't even need two templates for now.

I also set the templates to have no extension at all, which allows them to be ignored by babel and to not be compiled.

Ultimately, I think, it would be good to set a sort of a fake extension on the templates. For example dangerfile.ts.template or dangerfile_ts.template if the first one would somehow got picked up by babel, but I do not think it should. This would allow us to use any kind of templating for the future no matter the integration, language, or else. I do the same with the scripts file since bash's mv <A> <B> doesn't care and allows us to set extensions as we see them fit.

Wdyt?

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Dec 30, 2022

Rebased with main

```
├── <ROOT>
│ ├── .reassure
│ │ └── reassure-tests.sh
Copy link
Member

Choose a reason for hiding this comment

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

Why is reassure-tests.sh put under .reassure? reassure-tests.sh should be. top level.

├── <ROOT>
│ ├── .reassure
│ │ └── reassure-tests.sh
│ ├── dangerfile.ts (conditional)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
│ ├── dangerfile.ts (conditional)
│ ├── dangerfile.ts (append)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not an append, we cannot append automatically, this would have to be a separate feature as it would require us to separate bits of our dangerfile template into two pieces I think. Then we could properly append imports on top and our function on the bottom.

Unless it doesn't matter to us, but then we'll be polluting ppl's dangerfiles which I would deem a bad UX/DX

wdyt? @mdjastrzebski @thymikee

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the current solution make sense.

Suggested change
│ ├── dangerfile.ts (conditional)
│ ├── dangerfile.ts (or dangerfile.reassure.ts if dangerfile already present)

@@ -146,7 +172,7 @@ yarn install --force
yarn reassure
```

## CI integration
### Integration

As a final setup step you need to configure your CI to run the performance testing script and output the result.
For presenting output at the moment we integrate with Danger JS, which supports all major CI tools.
Copy link
Member

Choose a reason for hiding this comment

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

Can we redact that, so that it mentions dangerfile.reassure.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can reiterate so that it's there as well, but i's been mentioned already above in the same encompassing section.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I re-edited that section in order to include clearer instructions about it

};

console.log(`\n❇️ Running performance tests:`);
console.log(` - ${measurementType}: ${formatMetadata(metadata)}\n`);
warn(`❇️ Running performance tests:`);
Copy link
Member

Choose a reason for hiding this comment

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

Why warn? It seems like this should be regular log.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as the next comment but in this case I think that you are in fact correct. I will ammend

return;
}

if (options.baseline) {
console.log("Hint: You can now run 'reassure' to measure & compare performance against modified code.\n");
warn("Hint: You can now run 'reassure' to measure & compare performance against modified code.\n");
Copy link
Member

Choose a reason for hiding this comment

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

Why warn?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Visibility and styling. log will be shown only in --verbose and warn shows always unless you run with --silent. I thought that;s a more important log than most general procedural logs.

await mkdirSync(RESULTS_DIRECTORY);

logger.log('Copying the reassure-tests.sh template file');
await copyFileSync(`${__dirname}/../templates/reassure-tests`, `./reassure-tests.sh`);
Copy link
Member

@thymikee thymikee Mar 10, 2023

Choose a reason for hiding this comment

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

doesn't need await right? same as other *Sync methods, can you remove all unnecessary occurrences?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I took the the other way around. Thanks for pointing it out!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I definitely did take it the wrong way around. It was fixed in this commit

@mdjastrzebski
Copy link
Member

I'll try to review it in the upcoming days.


#### `.gitignore`

If .gitignore file is present and no mentions of `reassure` appear within it, the script will append the `.reassure/` directory to its end.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If .gitignore file is present and no mentions of `reassure` appear within it, the script will append the `.reassure/` directory to its end.
If `.gitignore` file is present and no mentions of `reassure` appear within it, the script will append the `.reassure/` directory to its end.


If .gitignore file is present and no mentions of `reassure` appear within it, the script will append the `.reassure/` directory to its end.

#### `reassure-tests.sh`
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this file will be generated by Reassure init. We could keep this section brief, mention the purpupose of that file and that it will be generated by Reassure init, while having more details in the github docs. @Xiltyn wdyt?

@Xiltyn
Copy link
Collaborator Author

Xiltyn commented Mar 20, 2023 via email

Copy link
Member

@mdjastrzebski mdjastrzebski left a comment

Choose a reason for hiding this comment

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

The PR adds many valuable features (e.g. init), however I have concerns about some proposed solutions:

  1. Redefining the default behavior of reassure that now runs interactive prompter. Imo we should keep the most used option of running test in the spirt of jest being the command to run tests. Changes here will break the user scripts (incl. the default ones that use yarn reassure.
  2. Interactive prompter seems fine for init script, but feels weird for other commands. Imo I would leave it only for init OR if you find it useful then make it optional for other commands, e.g. behind --interactive option.
  3. ASCII art looks nice for init command, but pollutes the log for measure and other commands. I would suggest displaying it only for init OR for --interactive mode if we go that way. That should also lead to removing of --no-ascii-art option as no longer needed.
  4. --subroutine options is hard to understand even with CLI description text. Is this really needed?
  5. Logger uses reassure: prefix, which we agreed with @thymikee in feat: logger #343 that necessarily pollutes the logs.

@Xiltyn @thymikee Pls weight in on the above points and also if we should allow interactive mode for commands other that init.

],
}
```
> **Note**: Your performance test will run much longer than regular integration tests. It's because we run each test scenario multiple times (by default 10), and we repeat that for two branches of your code. Hence, each test will run 20 times by default. That's unless you increase that number even higher.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> **Note**: Your performance test will run much longer than regular integration tests. It's because we run each test scenario multiple times (by default 10), and we repeat that for two branches of your code. Hence, each test will run 20 times by default. That's unless you increase that number even higher.
> **Note**: Your performance test will run significantly longer than regular integration tests. It's because we run each test scenario multiple times (by default 10), and we repeat that for two branches of your code. Hence, each test will run 20 times by default. That's unless you increase that number even higher.

├── <ROOT>
│ ├── .reassure
│ │ └── reassure-tests.sh
│ ├── dangerfile.ts (conditional)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the current solution make sense.

Suggested change
│ ├── dangerfile.ts (conditional)
│ ├── dangerfile.ts (or dangerfile.reassure.ts if dangerfile already present)

docusaurus/docs/installation.md Show resolved Hide resolved
You can also check our example [Dangerfile](https://github.com/callstack/reassure/blob/main/dangerfile.ts).
#### Creating a new `dangerfile`

If you do not have a dangerfile yet, you can use the one generated by the `reassure init` script without making any additional changes.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If you do not have a dangerfile yet, you can use the one generated by the `reassure init` script without making any additional changes.
If you do not have a `dangerfile` yet, you can use the one generated by the `reassure init` script without making any additional changes.

await measure({ ...options, baseline: false, compare: true });
hello(options);

await measure({ baseline: true, isSubRoutine: true });
Copy link
Member

Choose a reason for hiding this comment

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

  1. Why are options no-longer passed to measure?
  2. isSubRoutine name is not hard to understand without context.

})
.option('testMatch', {
},
testMatch: {
Copy link
Member

Choose a reason for hiding this comment

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

Seems we are getting into two conflicting option naming styles: --testMatch vs --commit-hash. @Xiltyn any thoughts on that.

@@ -23,6 +22,7 @@ interface MeasureOptions extends CommonOptions {

export async function run(options: MeasureOptions) {
configureLoggerOptions(options);
hello(options);
Copy link
Member

Choose a reason for hiding this comment

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

IMO we should not runt hello or bye by default for any other commend beside init as they will be annoying to the user.

bye();
}

export const command: CommandModule<{}, {}> = {
Copy link
Member

Choose a reason for hiding this comment

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

I am against having the interactive mode by default. It will break the simplicity of running yarn reassure for testing. I would reserve prompting for the init command as this the command that users will primarily do by hand. Otherwise, we could leave it as optional --interactive mode, but IMO the default stay the same.

const colorVerbose = chalk.hex(colors.verbose);
const colorVerbose = chalk.hex(colors.default);

const prefix: string = colorBrand('reassure: ');
Copy link
Member

Choose a reason for hiding this comment

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

We agreed with @thymikee that prefix is not really useful and pollutes the logs.

/** No logs */
silent?: boolean;
/** No Ascii art */
'no-ascii-art'?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

IMO I would drop this option, and display ascii art only either only for CLI init OR only for interactive prompts if we go that option.

@mdjastrzebski
Copy link
Member

Based on today's conversation with @Xiltyn, we agreed to split this PR into smaller, orthogonal ones that handle separate PRs (reassure init) and issues for discussion of scope (logger prefix, perhaps interactive mode, etc).

@mdjastrzebski mdjastrzebski mentioned this pull request Mar 24, 2023
3 tasks
@mdjastrzebski
Copy link
Member

Closing in favour of #381 which contains just the init code extracted from this PR.

@mdjastrzebski mdjastrzebski deleted the feature/cli-init-script branch February 20, 2024 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants