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

deps(testing) - consolidate testing frameworks across the project #819

Merged
merged 8 commits into from
Nov 11, 2023

Conversation

ctrlc03
Copy link
Collaborator

@ctrlc03 ctrlc03 commented Nov 8, 2023

This PR removes usage of JEST in favour of Mocha + Chai -> given we have multiple packages in this monorepo and both circuits and contracts tests use mocha (circom_tester and hardhat)

  • remove jest @types/jest
  • install mocha ts-mocha @types/mocha chai @types/chai
  • fix all tests
  • change test scripts
  • bonus: run all unit tests in one command from the root of the monorepo: npm run test from monorepo root will run all unit tests

@ctrlc03 ctrlc03 self-assigned this Nov 8, 2023
@ctrlc03 ctrlc03 linked an issue Nov 8, 2023 that may be closed by this pull request
5 tasks
@@ -8,9 +8,10 @@
"bootstrap": "lerna bootstrap",
"build": "lerna run build",
"lint": "eslint './**/**/*.ts'",
"lint-fix": "eslint './**/**/*.ts' --fix"
"lint-fix": "eslint './**/**/*.ts' --fix",
"test": "lerna run test --ignore maci-common --ignore maci-server --ignore maci-integrationtests --ignore maci-cli"
Copy link
Member

Choose a reason for hiding this comment

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

Why ignore maci-cli? Is that because you'll plan to refactor that as part of #794?

Copy link
Member

Choose a reason for hiding this comment

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

I also wonder how intuitive it is to ignore integration tests 🤔 but I think it makes sense

Copy link
Collaborator Author

@ctrlc03 ctrlc03 Nov 10, 2023

Choose a reason for hiding this comment

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

Basically here I'm trying to run only unit test, hence why cli and integration tests are ignored.
Running them in this command would involve first spawning a local hardhat node

Copy link
Member

Choose a reason for hiding this comment

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

Running them in this command would involve first spawning a local hardhat node

But doesn't running contract tests also spin up a hardhat node?

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 does, however because we run them using hardhat directly (hardhat test x.test.ts) there is no need to pre spawn a node, it just does it automatically and kills it once done

@@ -27,7 +27,7 @@ jobs:
id: check_changes
run: |
CHANGED_FILES=${{ steps.get-changed-files.outputs.all }}
if echo "$CHANGED_FILES" | grep -q "circuit" && ! echo "$CHANGED_FILES" | grep -q ".github/workflows/circuit-build.yml"; then
if echo "$CHANGED_FILES" | grep -q "\.circom"; then
Copy link
Member

Choose a reason for hiding this comment

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

What's this change about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yea sorry for not mentioning in the description! Basically this change is so that the e2e test only run when the actual circom files change, not any files in the circuits folder as it was until this commit. I was planning to introduce this with another PR but got carried away by not wanting to wait on circuits compilation for this PR

Copy link
Member

Choose a reason for hiding this comment

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

Awesome. Great catch.

README.md Outdated

```bash
cd crypto
npm run test
```

<!-- TODO: confirm if true -->
Copy link
Member

Choose a reason for hiding this comment

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

@ctrlc03 is this necessary? Seems I'm able to run the full suite e.g. of contracts tests without nonce errors...

Copy link
Member

Choose a reason for hiding this comment

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

First, start a Hardhat instance in a separate terminal:

cd contracts
npm run hardhat

Is this needed? I'm able to just run npm run test within contracts & it seems to automatically start up Hardhat

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea that's how it's supposed to work (hardhat does start itself) so yea feel free to remove. In general most of these README are outdated (wondering if it might better to address all in one PR?)

Copy link
Member

Choose a reason for hiding this comment

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

In general most of these README are outdated (wondering if it might better to address all in one PR?)

I'm alright with that, though generally I think best to update documentation at the same time as the code is updated (ideally in the same PR), because:

  • that tends to make it easier for PR creator, given the specific info & context is fresh in their mind
  • it also makes it easier for the reviewer, so they can easily understand what's changing
  • it avoids the issue of having this big chore for someone to pick up at the end of this refactoring effort. Not to mention if the chore drops as a priority, then everything is a mess 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noted! I'll make sure from now on all doc updates are included in the PR 🙂

README.md Show resolved Hide resolved
Copy link
Member

@samajammin samajammin left a comment

Choose a reason for hiding this comment

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

Looks great! A couple small comments/questions. I added a small update to the README, could please check my work? Feel free to expand on that testing section of the README to cover these changes / update anything that's outdated.

Copy link
Member

@samajammin samajammin left a comment

Choose a reason for hiding this comment

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

🚀

@samajammin samajammin merged commit 7a6946a into dev Nov 11, 2023
7 checks passed
@samajammin samajammin deleted the deps/mocha branch November 11, 2023 08:05
@baumstern
Copy link
Member

Great work!

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.

Consolidate testing libraries across the monorepo
3 participants