Skip to content

Commit

Permalink
fix: use a hardhat jest environment (#20)
Browse files Browse the repository at this point in the history
* build: simplify workflows

* test: use hardhat jest env

* fix: method parity for library listener

* test: update hardhat jest env

* build: mv keys to dotenv
  • Loading branch information
zzmp authored May 31, 2022
1 parent 34b1211 commit 6dda04c
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 143 deletions.
24 changes: 0 additions & 24 deletions .github/actions/setup/action.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/build.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Semantic commit"
name: Conventional commit

on:
pull_request_target:
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/crowdin-download.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Crowdin download
name: Crowdin Download

on:
schedule:
Expand All @@ -10,11 +10,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 14
registry-url: https://registry.npmjs.org
cache: 'yarn'

- run: yarn install --frozen-lockfile --ignore-scripts

- run: "yarn i18n:extract"
- run: yarn i18n:extract

- uses: crowdin/github-action@1.4.8
with:
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/crowdin-upload.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Crowdin upload
name: Crowdin Upload

on:
push:
Expand All @@ -10,9 +10,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 14
registry-url: https://registry.npmjs.org
cache: 'yarn'

- run: yarn install --frozen-lockfile --ignore-scripts

- run: yarn i18n:extract

Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/e2e.yaml

This file was deleted.

12 changes: 9 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 14
registry-url: https://registry.npmjs.org
cache: 'yarn'

- run: yarn install --frozen-lockfile --ignore-scripts

- uses: wearerequired/lint-action@v2
with:
auto_fix: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }}
eslint: true
eslint_extensions: 'js,jsx,ts,tsx'
git_email: lint-action@uniswap.org
commit_message: "chore(lint): fix code style issues with ${linter}"
commit_message: "style(lint): lint action with ${linter}"
16 changes: 10 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 14
registry-url: https://registry.npmjs.org
cache: 'yarn'

- run: yarn lint
- run: yarn install --frozen-lockfile

- run: yarn test
if: success()

- run: yarn hardhat &
if: success()

- run: yarn test:e2e
if: success()
env:
JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}

- run: yarn release
if: success()
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Unit test"
name: Test

on:
push:
Expand All @@ -9,11 +9,21 @@ on:
- main

jobs:
unit-test:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: ./.github/actions/setup
- uses: actions/setup-node@v3
with:
node-version: 14
registry-url: https://registry.npmjs.org
cache: 'yarn'

- run: yarn install --frozen-lockfile

- run: yarn test

- run: yarn test:e2e
env:
JSON_RPC_PROVIDER: ${{ secrets.JSON_RPC_PROVIDER }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package-lock.json
# misc
.DS_Store
/.netlify
.env
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@

# Contributing

Thank you for your interest in contributing to the Uniswap widgets! 🦄

# Development

Before developing locally, be sure to install the project's dependencies.
Before developing locally, you'll need install the project's dependencies and create a `.env` file.

- `yarn install`

The `.env` file specifies third-party APIs for use in e2e testing and the cosmos viewer:
- `JSON_RPC_PROVIDER` must be specified for e2e tests to work.
- `INFURA_KEY` must be specified to use a network provider in the cosmos viewer.

1. `yarn install`
```
JSON_RPC_PROVIDER='<JSON_RPC_PROVIDER>`
INFURA_KEY='<INFURA_KEY>'
```

## Running widgets locally

Expand Down
13 changes: 7 additions & 6 deletions e2e/connect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/**
* @jest-environment hardhat/dist/jsdom
*/

import '@ethersproject/providers'
import 'jest-environment-hardhat'

import { JsonRpcProvider } from '@ethersproject/providers'
import { render, RenderResult, waitFor } from '@testing-library/react'
import { tokens } from '@uniswap/default-token-list'

import { SwapWidget } from '../src'

const JSON_RPC_ENDPOINT = 'http://127.0.0.1:8545/'
const provider = new JsonRpcProvider('http://127.0.0.1:8545/')

describe('connect', () => {
let component: RenderResult
let wallet: HTMLElement
Expand All @@ -27,7 +28,7 @@ describe('connect', () => {

describe('with jsonRpcEndpoint', () => {
it('prompts for wallet connection in the Wallet', async () => {
component.rerender(<SwapWidget tokenList={tokens} jsonRpcEndpoint={JSON_RPC_ENDPOINT} />)
component.rerender(<SwapWidget tokenList={tokens} jsonRpcEndpoint={hardhat.url} />)
expect(wallet.hidden).toBeTruthy()
expect(toolbar.textContent).toBe('Connecting…')

Expand All @@ -40,7 +41,7 @@ describe('connect', () => {

describe('with provider', () => {
it('does not prompt for wallet connection', async () => {
component.rerender(<SwapWidget tokenList={tokens} provider={provider} />)
component.rerender(<SwapWidget tokenList={tokens} provider={hardhat.provider} />)
expect(wallet.hidden).toBeTruthy()
expect(toolbar.textContent).toBe('Connecting…')

Expand Down
13 changes: 0 additions & 13 deletions hardhat.config.js

This file was deleted.

22 changes: 22 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '@nomiclabs/hardhat-ethers'

import * as dotenv from 'dotenv'

dotenv.config()

const mainnetFork = {
url: `${process.env.JSON_RPC_PROVIDER}`,
blockNumber: 14390000,
}

module.exports = {
networks: {
hardhat: {
chainId: 1,
forking: mainnetFork,
accounts: {
count: 1,
},
},
},
}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
setupFiles: ['<rootDir>/test/setup.ts'],
testEnvironment: 'jsdom',
moduleNameMapper: {
'.scss$': '<rootDir>/test/scssStub',
'.(png|svg)$': '<rootDir>/test/imageStub',
},
setupFiles: ['<rootDir>/test/setup.ts'],
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
"build": "tsc && rollup --config --failAfterWarnings",
"release": "semantic-release",
"lint": "eslint .",
"hardhat": "hardhat node",
"test": "jest --testPathIgnorePatterns=e2e",
"test:e2e": "jest --testPathPattern=e2e"
"test": "jest src",
"test:e2e": "jest e2e"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -118,6 +117,7 @@
"@lingui/core": "^3.9.0",
"@lingui/macro": "^3.9.0",
"@lingui/react": "^3.9.0",
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
Expand Down Expand Up @@ -148,6 +148,7 @@
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"@uniswap/default-token-list": "^3.2.0",
"jest-environment-hardhat": "^1.1.4",
"@uniswap/v2-core": "1.0.0",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"@uniswap/v3-core": "1.0.0",
Expand All @@ -160,6 +161,7 @@
"babel-plugin-macros": "^3.1.0",
"babel-plugin-module-resolver": "^4.1.0",
"babel-runtime": "^6.26.0",
"dotenv": "^16.0.1",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -169,7 +171,7 @@
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"hardhat": "^2.9.3",
"hardhat": "^2.9.6",
"html-webpack-plugin": "^5.5.0",
"inter-ui": "^3.13.1",
"jest": "^27.5.1",
Expand Down
Loading

1 comment on commit 6dda04c

@vercel
Copy link

@vercel vercel bot commented on 6dda04c May 31, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

widgets – ./

widgets-uniswap.vercel.app
widgets-git-main-uniswap.vercel.app
widgets-seven-tau.vercel.app

Please sign in to comment.