Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.

chore(ts-tests): refactor ts-tests/* to follow pnpm and turbo workspace design #86

Merged
merged 2 commits into from
Sep 13, 2022

Conversation

fuxingloh
Copy link
Contributor

@fuxingloh fuxingloh commented Sep 13, 2022

What this PR does / why we need it:

Move ts-tests/* to utilize pnpm and turbo mono-repo workspace design. With this, we managed to keep configs (eslint, prettier, babel jest) DRY. The PR "workspace-ize" ts-tests but ultimately many more PR is required to break this package into multiple smaller mono repo packages.

Follow-up PRs required to address these:


What's new?

As suggested in #66 (comment) I've added hardhat compile turbo workflow.

@birthdayresearch/sticky-turbo-jest is a turbo-aware jest-preset; it automatically run dependsOn script before running jest. By taking advantage of content-aware hashing from turborepo. dependsOn only runs if the pipeline inputs has changed.

When you run your test with @birthdayresearch/sticky-turbo-jest preset, it uses displayName from your jest config to figure out which pipeline to use. It will automatically pinpoint the corresponding dependsOn and run all the scripts specified within.

TLDR, when you run a dependent test, it automatically recompiles your contract with hardhat when it detects changes in your contracts/*.sol file. If it has the cached version, it will simply "output" the result instead of rebuilding it.

https://sticky.birthday.dev/packages/sticky-turbo-jest

package.json:

  "scripts": {
    "compile": "hardhat compile",
    "test": "jest"
  },
  "jest": {
    "displayName": "test",
    "preset": "@birthdayresearch/sticky-turbo-jest"
  },

turbo.json:

    "compile": {
      "inputs": ["contracts/**"],
      "outputs": ["artifacts", "cache"]
    },
    "test": {
      "inputs": ["src/**", "**/*.unit.ts", "tests-e2e/**"],
      "dependsOn": ["^build", "compile"]
    },

Which issue(s) does this PR fixes?:

Fixes part of #79

@netlify
Copy link

netlify bot commented Sep 13, 2022

Deploy Preview for metachain ready!

Name Link
🔨 Latest commit 571b0c3
🔍 Latest deploy log https://app.netlify.com/sites/metachain/deploys/632005f1d3a4150008156c24
😎 Deploy Preview https://deploy-preview-86--metachain.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@fuxingloh fuxingloh temporarily deployed to Release Docker September 13, 2022 04:24 Inactive
@fuxingloh

This comment was marked as resolved.

@fuxingloh fuxingloh marked this pull request as ready for review September 13, 2022 04:35
@github-actions
Copy link

Docker image for defich/metachain is ready!

Built with commit 93ee74a

  • docker pull ghcr.io/defich/metachain:93ee74a490bd21d230d1a0a89670f9ef9aec1b19
  • docker pull ghcr.io/defich/metachain:pr-86

@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Merging #86 (571b0c3) into main (a21ab26) will increase coverage by 2.80%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##            main     #86      +/-   ##
========================================
+ Coverage   3.79%   6.60%   +2.80%     
========================================
  Files         10      13       +3     
  Lines       1711    1771      +60     
  Branches       0      11      +11     
========================================
+ Hits          65     117      +52     
- Misses      1646    1653       +7     
- Partials       0       1       +1     
Impacted Files Coverage Δ
ts-tests/src/containers/index.ts 100.00% <ø> (ø)
ts-tests/src/utils/constant.ts 100.00% <ø> (ø)
ts-tests/src/containers/MetaDContainer.ts 82.60% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link

@weiyuan95 weiyuan95 left a comment

Choose a reason for hiding this comment

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

LGTM. Just FYI that Hardhat also has cache-aware contract recompiling, but it plays nice with Turbo though, so no worries.

@fuxingloh fuxingloh merged commit adec5dc into main Sep 13, 2022
@fuxingloh fuxingloh deleted the fuxingloh/workspace-ts-tests branch September 13, 2022 06:58
canonbrother pushed a commit that referenced this pull request Sep 28, 2022
…pace design (#86)

#### What this PR does / why we need it:

Move `ts-tests/*` to utilize pnpm and turbo mono-repo workspace design.
With this, we managed to keep configs (eslint, prettier, babel jest)
DRY. The PR "workspace-ize" `ts-tests` but ultimately many more PR is
required to break this package into multiple smaller mono repo packages.

Follow-up PRs required to address these:

- [ ] ESLINT will be added back once we move to "testsuite", also part
of #79
- [ ] #78 

---

**What's new?**

As suggested in
#66 (comment) I've
added hardhat compile turbo workflow.

`@birthdayresearch/sticky-turbo-jest` is a turbo-aware `jest-preset`; it
automatically run `dependsOn` script before running jest. By taking
advantage of content-aware hashing from turborepo. `dependsOn` only runs
if the pipeline `inputs` has changed.

When you run your test with `@birthdayresearch/sticky-turbo-jest`
preset, it uses `displayName` from your jest config to figure out which
`pipeline` to use. It will automatically pinpoint the corresponding
`dependsOn` and run all the scripts specified within.

> TLDR, when you run a dependent test, it automatically recompiles your
contract with hardhat when it detects changes in your `contracts/*.sol`
file. If it has the cached version, it will simply "output" the result
instead of rebuilding it.

https://sticky.birthday.dev/packages/sticky-turbo-jest

`package.json`:
```json
  "scripts": {
    "compile": "hardhat compile",
    "test": "jest"
  },
  "jest": {
    "displayName": "test",
    "preset": "@birthdayresearch/sticky-turbo-jest"
  },
```

`turbo.json`:
```json
    "compile": {
      "inputs": ["contracts/**"],
      "outputs": ["artifacts", "cache"]
    },
    "test": {
      "inputs": ["src/**", "**/*.unit.ts", "tests-e2e/**"],
      "dependsOn": ["^build", "compile"]
    },
```

#### Which issue(s) does this PR fixes?:

<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

Fixes part of #79
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants