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

Updating Tests to latest Prettier tests #448

Merged
merged 10 commits into from
Mar 28, 2021
Merged

Updating Tests to latest Prettier tests #448

merged 10 commits into from
Mar 28, 2021

Conversation

Janther
Copy link
Contributor

@Janther Janther commented Mar 14, 2021

there are a few benefits of updating our testing framework.

  • the new snapshots give more details.
  • the FULL_TEST not only compares AST but also different EOL, BOM, and compares the file formatted twice (as described in Prettier's documentation) which led to the discovery with Assembly Labels adding an extra line if there is an existing one.

@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #448 (c894090) into master (9ef89c4) will not change coverage.
The diff coverage is n/a.

❗ Current head c894090 differs from pull request most recent head c9f50a3. Consider uploading reports for the commit c9f50a3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##            master      #448   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           92        92           
  Lines          770       770           
  Branches       147       147           
=========================================
  Hits           770       770           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ef89c4...c9f50a3. Read the comment docs.

@@ -1,13 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EnumDefinitions.sol 1`] = `
exports[`EnumDefinitions.sol - {"bracketSpacing":true} format 1`] = `
Copy link
Contributor Author

Choose a reason for hiding this comment

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

things like these are very nice when reviewing a snapshot with specific options

uint256 _e,
int256 _f,
bytes1 _g
uint _a,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changed because the order of the snapshots changed.

tests_config/run_spec.js Outdated Show resolved Hide resolved

// TODO: these test files need fix
const unstableTests = new Map(
['Assembly/Assembly.sol'].map((fixture) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Until we fix this Issue we won't compare this file formatted twice.

@mattiaerre
Copy link
Member

happy to approve this if you can fix the conflicts @Janther thanks

@Janther
Copy link
Contributor Author

Janther commented Mar 17, 2021

AFK right now but the conflict might only be with the lock file since the merge of the eslint update

@Janther Janther force-pushed the tests branch 2 times, most recently from 29acf09 to 44d0e74 Compare March 17, 2021 10:01
@mattiaerre
Copy link
Member

thanks @Janther this is a 104 files long PR, anything specific you'd like us to take a look at?

@Janther
Copy link
Contributor Author

Janther commented Mar 17, 2021

Every jsfmt.spec.js in the test folder had the parser included in the call to run_spec.
Also every snapshot changed slightly because the new snapshots include more info.
So just have a look at a few of these examples in the test folder.

The files in the test_config folder are taken from Prettier’s repo. Only the require_standalone.js and run_spec.js were altered.

  • require_standalone.js requires the standalone module instead of parsing it and executing it in a separate empty context .
  • run_spec.js has some variables and checks, that only dealt with specific languages and parsers supported directly by Prettier, removed.

Probably would suggest to only check these 2 files.

Finally there are some changes in the Jest config mainly taken from Prettier’s repo. And a few changes in the package.json scripts.

AST_COMPARE doesn't exist anymore, it was replaced by FULL_TEST which does much more now.
Running the tests won’t collect coverage unless we run them with the FULL_TEST flag. this way we won't get noisy feedback when we run a specific test like npm test tests/Assembly.

Finally you could have a look and play with the result.

@mattiaerre
Copy link
Member

thanks for the recap @Janther this is great

@mattiaerre
Copy link
Member

mattiaerre commented Mar 23, 2021

sorry @Janther I was finally able to take a look at this PR, added some comments thanks // cc @fvictorio

@@ -152,8 +152,9 @@ If you want a different configuration for your javascript and solidity files, yo
1. [Fork it](https://github.com/prettier-solidity/prettier-plugin-solidity/fork)
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request
4. All existing test and coverage must pass (`npm run test:all`), if coverage drops below 100% add missing tests.
Copy link
Member

Choose a reason for hiding this comment

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

not really clear, can you elaborate more on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what else can I write here. Perhaps I'm too close to the forest to see the trees. Maybe you can add something here?

Copy link
Member

Choose a reason for hiding this comment

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

this is my bad sorry, the desc is perfect

"test": "jest",
"test:all": "AST_COMPARE=true npm t -- --coverage"
"test:all": "FULL_TEST=1 jest"
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 use true instead of 1? thanks

Copy link
Contributor Author

@Janther Janther Mar 24, 2021

Choose a reason for hiding this comment

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

I used 1 as it is what's used in Prettier's scripts. It can be anything though as the variable is a string and the code just checks for a truthy value. It would also run full tests with FULL_TEST=false jest. Only FULL_TEST= jest will run normal tests as FULL_TEST would be considered a falsy value as it is an empty string, of course no FULL_TEST at all will also be a falsy value since in runtime will be undefined. I'm just pointing out that using true as a value could be misleading since Prettier's test doesn't really parse the flag as JSON and I wouldn't implement that step since I'd like to keep this code as close as possible to the original, that way we can follow Prettier's enhancements to the testing system easier.

Copy link
Member

Choose a reason for hiding this comment

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

alright, I'm ok to keep 1 then thanks for the explanation

jest.config.js Outdated
module.exports = {
collectCoverage: true,
collectCoverage: !!FULL_TEST,
Copy link
Member

Choose a reason for hiding this comment

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

related to my other comment below; not a huge fan of the !! operator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved


module.exports = {
formatWithCursor(input, options) {
const $$$options = {
Copy link
Member

Choose a reason for hiding this comment

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

$$$options can you tell me more about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a name to be different from options it came from the original file. That one instead of importing the code, it reads the files and treats it as a string to be evaluated by the vm. I didn't have much time to go through this process so there's some room for improvement here.

@@ -0,0 +1,7 @@
const runSpec = require('./run_spec.js');
Copy link
Member

Choose a reason for hiding this comment

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

interesting, it looks like from this file on GH is no longer formatting js? 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks normal in my screen.

Copy link
Member

@mattiaerre mattiaerre left a comment

Choose a reason for hiding this comment

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

thanks @Janther good job 🙏

@mattiaerre mattiaerre merged commit 7769cd6 into master Mar 28, 2021
@mattiaerre mattiaerre deleted the tests branch March 28, 2021 23:54
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.

2 participants