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

CI cypress tests patch [WIP] #1190

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7911581
Update txn deadline for deposit and swap flows to 1000 min
nguyenaiden Jul 19, 2022
74e4dca
Upgrade cypress to 10.3.0
nguyenaiden Jul 21, 2022
c93b339
Added waits in deposit and swap
nguyenaiden Jul 21, 2022
0e43490
use wait in addition to wait for react
nguyenaiden Jul 21, 2022
460aac0
Update command timeout to 60s
nguyenaiden Jul 21, 2022
17d8006
Added wait after deposit
nguyenaiden Jul 21, 2022
e5f801d
moved wait into before token input
nguyenaiden Jul 21, 2022
20f46f3
Increase wait time so react state triggers rerender
nguyenaiden Jul 21, 2022
8f2949d
Remove npm ci on cypress step. Already done in previous step
nguyenaiden Jul 21, 2022
d17d4a6
Readded npm ci
nguyenaiden Jul 21, 2022
b49601c
Upgrade cypress-react-selector
nguyenaiden Jul 22, 2022
27d7d83
use chrome instead of electron
nguyenaiden Jul 24, 2022
4d95fe9
Isolate test
nguyenaiden Jul 24, 2022
adf9c33
Added wait before retrieving tokenValue
nguyenaiden Jul 24, 2022
7fce252
reduced timeout and attempt to identify which valueToken is not findable
nguyenaiden Jul 24, 2022
2ac9439
Add userShareData to deposit page to rerender when data changes
nguyenaiden Jul 24, 2022
b158e8b
Increase timeout cypress to 100s
nguyenaiden Jul 24, 2022
afebb37
Revert timeout to 40s
nguyenaiden Jul 24, 2022
add5124
Use macos in workflow
nguyenaiden Jul 25, 2022
045f89c
Use ubuntu 22.04
nguyenaiden Jul 25, 2022
f617c6f
Separate cypress steps into start and run
nguyenaiden Jul 25, 2022
799da79
Use cypress github action
nguyenaiden Jul 25, 2022
4c82ecb
Removed chokidar polling
nguyenaiden Jul 25, 2022
e4598bb
removed server starts
nguyenaiden Jul 25, 2022
2bf3a75
Added start to cypress flow
nguyenaiden Jul 25, 2022
e80bcac
Added env config for cypress actions
nguyenaiden Jul 25, 2022
dd184a1
separate start app step and wait on localhost3000
nguyenaiden Jul 25, 2022
6789e65
Add & to start
nguyenaiden Jul 25, 2022
39ec85a
Put commands in the same container
nguyenaiden Jul 25, 2022
ed5c15c
Separate all steps and placed under same container
nguyenaiden Jul 25, 2022
79b8cea
Combined start and test
nguyenaiden Jul 25, 2022
9651484
Removed container from npm ci
nguyenaiden Jul 25, 2022
c5958db
Use run
nguyenaiden Jul 25, 2022
0b24482
Don't use rserved word
nguyenaiden Jul 25, 2022
2e184f6
Use reserved word
nguyenaiden Jul 25, 2022
6c218f2
Add wait on for webserver
nguyenaiden Jul 25, 2022
a09351b
add to requestteimout
nguyenaiden Jul 25, 2022
d29f7b1
wait on 8545 as well
nguyenaiden Jul 25, 2022
77c0ca7
Update timeouts
nguyenaiden Jul 25, 2022
dc3d3e8
Fixed comma
nguyenaiden Jul 25, 2022
25cf593
response timeout 100000
nguyenaiden Jul 25, 2022
48847ca
Added healthcheck for contracts repo on ci
nguyenaiden Jul 25, 2022
0d196a4
Use config file
nguyenaiden Jul 25, 2022
fb53bc5
Added extra timeouts to config
nguyenaiden Jul 25, 2022
1f0701e
Update intervals for healthcheck
nguyenaiden Jul 26, 2022
e307510
Use coverage
nguyenaiden Jul 26, 2022
f8524d5
Add wait to the tokenInput
nguyenaiden Jul 26, 2022
de1a7b2
Enabled video
nguyenaiden Jul 27, 2022
d95f4b0
use Video
nguyenaiden Jul 27, 2022
db047bc
use data-test-id for Deposit
nguyenaiden Jul 27, 2022
6936c5b
Only run test once after it fails
nguyenaiden Jul 27, 2022
3b043a8
Add waits between inputs
nguyenaiden Jul 27, 2022
ac2443b
Added wait for react
nguyenaiden Jul 27, 2022
9760d11
Add click before input
nguyenaiden Jul 27, 2022
97765f3
Removed increase time
nguyenaiden Jul 27, 2022
f854ba8
Increase timeout
nguyenaiden Jul 27, 2022
f2027bd
Add increase time back in
nguyenaiden Jul 27, 2022
a1106cc
Increased load time to 100s
nguyenaiden Jul 27, 2022
e812576
Added wait for react before every test
nguyenaiden Jul 27, 2022
01fa422
Remove async function signature of increase time
nguyenaiden Jul 27, 2022
71f3c83
Added clear input before typing
nguyenaiden Jul 27, 2022
d97ea56
run test in specific order
nguyenaiden Jul 27, 2022
e6b2dda
put in waits after input
nguyenaiden Jul 27, 2022
8c41711
Add more waits after inputs
nguyenaiden Jul 27, 2022
72857b9
Modified reload to not clear local storage
nguyenaiden Jul 27, 2022
533a322
Remove clear on readonly
nguyenaiden Jul 28, 2022
2487984
update swap test to click choose multiple times
nguyenaiden Aug 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"no-invalid-this": 0,
"no-unused-vars": "off",
"sort-imports": "error"
}
},
"ignorePatterns": ["cypress.config.js"]
}
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -32,7 +32,7 @@ jobs:
# name: build-artifact
# path: ./build-artifact.zip
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -45,7 +45,7 @@ jobs:
- run: npm run lint

test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -60,7 +60,7 @@ jobs:
CI: true

coverage:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -79,10 +79,15 @@ jobs:
coverage-cypress:
env:
REACT_APP_NOTIFY_DAPP_ID: ${{ secrets.REACT_APP_NOTIFY_DAPP_ID }}
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
services:
saddle-contract:
image: saddlefinance/contracts:latest
options: >-
--health-cmd "node -e 'const fetch=require(\"node-fetch\");(function main(){const body={method:\"eth_blockNumber\",params:[],id:1,jsonrpc:\"2.0\"};fetch(\"http://localhost:8545\",{method:\"POST\",body:JSON.stringify(body),headers:{\"Content-Type\":\"application/json\"}}).then((res)=>res.json()).then((json)=>{const block=parseInt(json.result||\"0x0\",16);if(block>0){process.exit(0)}throw new Error()}).catch(()=>process.exit(1))})();'"
--health-interval 30s
--health-timeout 10s
--health-retries 10
ports:
- 8545:8545
steps:
Expand All @@ -106,8 +111,6 @@ jobs:
- run: 'git config --global --replace-all url."https://github.com/".insteadOf ssh://[email protected]/'
- run: npm ci
- run: npm run cy:coverage
env:
CHOKIDAR_USEPOLLING: 1
- run: npx nyc report --reporter=text
- uses: codecov/codecov-action@v1
with:
Expand All @@ -116,4 +119,4 @@ jobs:
if: failure()
with:
name: E2E Failures
path: cypress/screenshots/
path: cypress/videos/
28 changes: 28 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { defineConfig } = require("cypress");
const setupNodeEvents = require('./cypress/plugins/index.js')

module.exports = defineConfig({
"env": {
"NETWORK_ID": 31337,
"PROVIDER_HOST": "http://localhost:8545/",
"PRIVATE_TEST_WALLET_PK": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"PRIVATE_TEST_WALLET_ADDRESS": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"cypress-react-selector": {
"root": "#root"
}
},
"e2e": {
setupNodeEvents,
"supportFile": "cypress/support/commands.ts",
// "specPattern": "cypress/integration/*.test.ts",
"specPattern": "cypress/integration/e2e-suite.ts",
"baseUrl": "http://localhost:3000",
"pageLoadTimeout": 100000,
"responseTimeout": 100000,
"defaultCommandTimeout": 40000,
"requestTimeout": 40000,
"video": true,
"viewportWidth": 1440,
"viewportHeight": 1080
}
})
17 changes: 0 additions & 17 deletions cypress.json

This file was deleted.

5 changes: 2 additions & 3 deletions cypress/integration/accountDetail.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
context("Account detail test", () => {
beforeEach(() => {
cy.visit(`/#/`)
cy.waitForReact()
cy.wait(2000)
cy.reload()
cy.visit(`/#/`).waitForReact(2000)
})

it("renders account detail after click account avatar", () => {
Expand Down
1 change: 0 additions & 1 deletion cypress/integration/advancedOption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ context("Advanced option test", () => {
.within(() => {
cy.get("button").contains("Withdraw").click()
})
cy.wait(10000)

cy.get("[data-testid=advOptionContainer]")
.should("exist")
Expand Down
92 changes: 58 additions & 34 deletions cypress/integration/deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ const STABLECOIN_POOL_V2_NAME = "USDv2"
const SUSD_METAPOOL_V3_NAME = "sUSD-USDv2_v3"
const pools = [STABLECOIN_POOL_V2_NAME, SUSD_METAPOOL_V3_NAME] // order is important basepool must have balance prior to metapool

async function increaseTime() {
context("Deposit Flow", () => {
beforeEach(() => {
cy.reload()
cy.visit(`/#/pools`)
cy.waitForReact()
})

for (let i = 0; i < pools.length; i++) {
testPoolDeposit(pools[i])
}
})

function increaseTime() {
const provider = getDefaultProvider(
Cypress.env("PROVIDER_HOST"),
) as JsonRpcProvider
Expand All @@ -18,43 +30,55 @@ async function increaseTime() {
.then(resolve)
})
}
context("Deposit Flow", () => {
beforeEach(() => {
cy.visit(`/#/pools`)
cy.wait(2000)
})

function testPoolDeposit(poolName: string) {
function testPoolDeposit(poolName: string) {
it(`successfully completes a deposit of all ${poolName} assets`, () => {
if (poolName === SUSD_METAPOOL_V3_NAME) {
void increaseTime()
}
it(`successfully completes a deposit of all ${poolName} assets`, () => {
cy.contains(new RegExp("^" + poolName + "$"))
.parents("[data-testid=poolOverview]")
.within(() => {
cy.get("button").contains("Deposit").click()
})
if (poolName === SUSD_METAPOOL_V3_NAME) {
cy.get("[data-testid=deposit-wrapped-checkbox]").click()
}
cy.get("#tokenInput input").then(($inputs) => {
cy.wrap($inputs).each(($input) => {
cy.wrap($input).type("100")
})

cy.contains(poolName)
.parents("[data-testid=poolOverview]")
.within(() => {
cy.wait(2000)
cy.get("button").contains("Deposit").click()
})
cy.get("[data-testid=tokenValue]")
.first()
.then(($value) => {
const prevVal = $value.text()
cy.get("button").contains("Deposit").first().click()
cy.get("button").contains("Confirm Deposit").click()
cy.get(".Toastify").contains(`Deposit on ${poolName} complete`)
cy.get("[data-testid=tokenValue]")
.first()
.should("not.have.text", prevVal)

cy.wait(2000)

cy.get("[data-testid=advOptionContainer]")
.click()
.then(() => {
cy.get("[data-testid=txnDeadlineInputGroup]").within(() => {
cy.get("input").then(($input) => {
cy.wrap($input).clear().type("1000")
})
})
})
}
})

pools.forEach(testPoolDeposit)
})
cy.wait(2000)

cy.get("#tokenInput input")
.then(($inputs) => {
cy.wrap($inputs).each((_, $index) => {
cy.get(`[data-testid=token-input-${$index}]`)
.click()
.clear()
.type("100")
})
})
.wait(2000)
cy.scrollTo("top").wait(2000)
cy.get("[data-testid=tokenValue]")
.first()
.then(($value) => {
const prevVal = $value.text()
cy.get("button").contains("Deposit").first().click()
cy.get("button").contains("Confirm Deposit").click()
cy.get(".Toastify").contains(`Deposit on ${poolName} complete`)
cy.get("[data-testid=tokenValue]")
.first()
.should("not.have.text", prevVal)
})
})
}
8 changes: 8 additions & 0 deletions cypress/integration/e2e-suite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "./accountDetail.test.ts"
import "./advancedOption.test.ts"
import "./risk.test.ts"
import "./topMenu.test.ts"
import "./veSdl.test.ts"
import "./deposit.test.ts"
import "./swap.test.ts"
import "./withdrawal.test.ts"
19 changes: 16 additions & 3 deletions cypress/integration/swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ context("Swap Flow", () => {
function testAssetSwap(poolName: string, poolTokenSymbols: string[]) {
describe(`Swapping within ${poolName}`, () => {
before(() => {
cy.visit(`/#/`)
cy.waitForReact()
cy.reload()
cy.visit(`/#`).waitForReact()
cy.wait(2000)
})

it("starts in a neutral state", () => {
cy.get('[data-testid="swapTokenInputFrom"]')
.eq(0)
Expand All @@ -16,13 +17,19 @@ context("Swap Flow", () => {
.should("include.text", "Choose")
})
it("shows all of the pool's tokens and balances in dropdown", () => {
cy.get("[data-testid=poolsNavLink]").click()
cy.get("[data-testid=swapNavLink]").click()
cy.get('[data-testid="swapTokenInputFrom"]')
.eq(0)
.contains("Choose")
.as("dropdownButton")
.click() // show
.wait(2000)
.click()
.wait(2000)
.click()
poolTokenSymbols.forEach((tokenSymbol) => {
cy.react("ListItem", { options: { timeout: 3000 } }).should("exist") // wait for listitem to appear
cy.react("ListItem", { options: { timeout: 10000 } }).should("exist") // wait for listitem to appear
cy.get('[data-testid="dropdownContainer"]')
.contains(tokenSymbol, { matchCase: false })
.should("exist")
Expand Down Expand Up @@ -62,6 +69,12 @@ context("Swap Flow", () => {
.should("not.have.text", "≈$0.0")
})
it("allows users to select only tokens in the same pool", () => {
cy.get('[data-testid="swapTokenInputFrom"]')
.contains(poolTokenSymbols[0], { matchCase: false })
.click()
.get('[data-testid="dropdownContainer"]')
.contains(poolTokenSymbols[0], { matchCase: false })
.click()
cy.get('[data-testid="swapTokenInputTo"]')
.contains("Choose")
.as("dropdownButton")
Expand Down
6 changes: 4 additions & 2 deletions cypress/integration/veSdl.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("veSDL test", () => {
beforeEach(() => {
cy.visit(`/#/vesdl`)
cy.wait(2000)
cy.reload()
cy.visit(`/#/vesdl`).waitForReact(2000)
})
it("veSDL test", () => {
cy.getBySelId("lockVeSdlBtn").should("be.disabled")
Expand All @@ -15,7 +15,9 @@ context("veSDL test", () => {

cy.getBySelId("veSdlUnlockData")
.find("input")
.clear()
.type("07/28/2022", { force: true })
.wait(2000)
.should("have.value", "07/28/2022")
})
})
Loading