Skip to content

Commit 2d4ce42

Browse files
authored
test: Update vitest and add timeout workflow (#8975)
1 parent a530e8a commit 2d4ce42

File tree

99 files changed

+1135
-3249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1135
-3249
lines changed

.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"env": {
33
"es6": true,
4-
"browser": true,
5-
"jest": true
4+
"browser": true
65
},
76
"plugins": ["lodash", "address"],
87
"extends": ["@pancakeswap/eslint-config-pancake", "plugin:react/jsx-runtime"],

.github/workflows/format.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
jobs:
77
code:
88
runs-on: ubuntu-latest
9+
timeout-minutes: 4
910

1011
steps:
1112
- name: Checkout code

.github/workflows/lint.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
jobs:
1010
eslint:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 4
1213

1314
steps:
1415
- name: Checkout code

.github/workflows/testConfig.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ name: Test Config
33
on:
44
pull_request:
55
paths:
6-
- "apps/web/src/config/**"
7-
- "packages/pools/src/**"
8-
- "packages/farms/constants/**"
9-
- "packages/tokens/src/**"
6+
- 'apps/web/src/config/**'
7+
- 'packages/pools/src/**'
8+
- 'packages/farms/constants/**'
9+
- 'packages/tokens/src/**'
1010
push:
1111
branches:
1212
- develop
1313

1414
jobs:
1515
test:
1616
runs-on: ubuntu-latest
17+
timeout-minutes: 4
1718

1819
strategy:
1920
fail-fast: true
@@ -33,7 +34,7 @@ jobs:
3334
- name: Set up node@18
3435
uses: actions/setup-node@v3
3536
with:
36-
cache: "pnpm"
37+
cache: 'pnpm'
3738
node-version: 18.18.2
3839

3940
- name: Get pnpm store directory

.github/workflows/tsCheck.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
jobs:
77
ts-check:
88
name: Typescript Error Check
9+
timeout-minutes: 8
910
runs-on: ubuntu-latest
1011
permissions: write-all
1112
if: github.event.pull_request.head.repo.full_name == github.repository
@@ -19,7 +20,7 @@ jobs:
1920
- name: Set up node@18
2021
uses: actions/setup-node@v3
2122
with:
22-
cache: "pnpm"
23+
cache: 'pnpm'
2324
node-version: 18.18.2
2425

2526
- name: Get pnpm store directory
@@ -66,7 +67,7 @@ jobs:
6667
uses: chefjackson/[email protected]
6768
if: steps.files.outputs.changed == 'true'
6869
env:
69-
NODE_OPTIONS: "--max_old_space_size=4096"
70+
NODE_OPTIONS: '--max_old_space_size=4096'
7071
with:
7172
repo-token: ${{ secrets.GITHUB_TOKEN }}
7273
use-check: true

.github/workflows/unitTests.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
jobs:
1010
unit-tests:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 4
1213

1314
strategy:
1415
fail-fast: true
@@ -28,7 +29,7 @@ jobs:
2829
- name: Set up node@18
2930
uses: actions/setup-node@v3
3031
with:
31-
cache: "pnpm"
32+
cache: 'pnpm'
3233
node-version: 18.18.2
3334

3435
- name: Get pnpm store directory

apps/aptos/.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"env": {
33
"es6": true,
4-
"browser": true,
5-
"jest": true
4+
"browser": true
65
},
76
"plugins": ["lodash"],
87
"extends": ["plugin:@next/next/recommended"],

apps/aptos/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@vanilla-extract/vite-plugin": "^3.8.0",
53-
"@vitejs/plugin-react": "4.0.0",
53+
"@vitejs/plugin-react": "4.2.1",
5454
"vite-tsconfig-paths": "^4.0.3",
5555
"@types/lodash": "^4.14.168",
5656
"@next/bundle-analyzer": "13.0.7",
@@ -59,6 +59,7 @@
5959
"@types/react": "^18.2.21",
6060
"@types/react-dom": "^18.0.6",
6161
"eslint": "^8.32.0",
62+
"happy-dom": "^13.3.8",
6263
"@pancakeswap/tsconfig": "workspace:*",
6364
"@pancakeswap/next-config": "workspace:*"
6465
}

apps/aptos/vitest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { defineConfig } from 'vitest/config'
21
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'
32
import react from '@vitejs/plugin-react'
43
import tsconfigPaths from 'vite-tsconfig-paths'
4+
import { defineConfig } from 'vitest/config'
55

66
export default defineConfig({
77
// @ts-ignore
88
plugins: [tsconfigPaths(), react(), vanillaExtractPlugin()],
99
test: {
10-
environment: 'jsdom',
10+
environment: 'happy-dom',
1111
globals: true,
1212
},
1313
})

apps/blog/.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"env": {
33
"es6": true,
4-
"browser": true,
5-
"jest": true
4+
"browser": true
65
},
76
"plugins": ["lodash"],
87
"extends": ["plugin:@next/next/recommended"],

apps/bridge/.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"env": {
33
"es6": true,
4-
"browser": true,
5-
"jest": true
4+
"browser": true
65
},
76
"plugins": ["lodash"],
87
"extends": ["plugin:@next/next/recommended"],

apps/web/.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"env": {
33
"es6": true,
4-
"browser": true,
5-
"jest": true
4+
"browser": true
65
},
76
"extends": ["plugin:@next/next/recommended"],
87
"rules": {

apps/web/package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
"zod": "^3.22.3"
129129
},
130130
"devDependencies": {
131-
"@angleprotocol/sdk": "^3.0.121",
132131
"@next/eslint-plugin-next": "13.4.2",
133132
"@pancakeswap/next-config": "workspace:*",
134133
"@pancakeswap/tsconfig": "workspace:*",
@@ -138,7 +137,6 @@
138137
"@testing-library/react-hooks": "^8.0.1",
139138
"@types/canvas-confetti": "^1.4.2",
140139
"@types/d3": "^7.4.0",
141-
"@types/jest": "^26.0.23",
142140
"@types/js-cookie": "^3.0.2",
143141
"@types/lodash": "^4.14.178",
144142
"@types/node": "^13.13.5",
@@ -152,12 +150,13 @@
152150
"@types/simplemde": "^1.11.7",
153151
"@types/styled-system": "^5.1.17",
154152
"@types/uuid": "^8.0.0",
155-
"@vanilla-extract/vite-plugin": "^3.8.0",
156-
"@vitejs/plugin-react": "4.0.0",
153+
"@vanilla-extract/vite-plugin": "^4.0.2",
154+
"@vitejs/plugin-react": "4.2.1",
157155
"@walletconnect/notify-client": "0.14.6",
158156
"eslint": "^8.32.0",
159157
"eslint-plugin-cypress": "^2.12.1",
160158
"eslint-plugin-lodash": "^7.4.0",
159+
"happy-dom": "^13.3.8",
161160
"lint-staged": "^12.3.4",
162161
"postcss-scss": "^4.0.3",
163162
"postcss-syntax": "^0.36.2",
@@ -171,7 +170,6 @@
171170
"stylelint-config-standard": "^25.0.0",
172171
"stylelint-config-styled-components": "^0.1.1",
173172
"tilg": "^0.1.1",
174-
"typechain": "^6.1.0",
175173
"vite-tsconfig-paths": "^4.0.3"
176174
}
177175
}

apps/web/src/hooks/useRefreshEffect.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { useQuery, useQueryClient } from '@tanstack/react-query'
2+
import { waitFor } from '@testing-library/react'
13
import { act, renderHook } from '@testing-library/react-hooks'
24
import { FAST_INTERVAL, SLOW_INTERVAL } from 'config/constants'
35
import { useState } from 'react'
4-
import { waitFor } from '@testing-library/react'
5-
import { useQuery, useQueryClient } from '@tanstack/react-query'
66
import { createWagmiWrapper } from 'testUtils'
7-
import { vi, describe, test } from 'vitest'
7+
import { describe, expect, test, vi } from 'vitest'
88
import { useFastRefreshEffect, useSlowRefreshEffect } from './useRefreshEffect'
99

1010
describe('useRefreshEffect', () => {

apps/web/src/hooks/useVaultApy.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { renderHook } from '@testing-library/react-hooks'
22
import BigNumber from 'bignumber.js'
33
import { createSWRWrapper } from 'testUtils'
4-
import { vi } from 'vitest'
4+
import { describe, expect, it, vi } from 'vitest'
55
import * as PoolHooks from '../state/pools/hooks'
66
import { useVaultApy } from './useVaultApy'
77

apps/web/src/state/transactions/updater.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { shouldCheck } from './updater'
1+
import { describe, expect, it } from 'vitest'
22
import { TransactionDetails } from './reducer'
3+
import { shouldCheck } from './updater'
34

45
describe('transactions updater', () => {
56
const trxDetailInFetchedTransactions: TransactionDetails = {

apps/web/src/testUtils.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
/* eslint-disable guard-for-in */
33
/* eslint-disable no-restricted-syntax */
44
/* eslint-disable import/no-unresolved */
5+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
56
import { render as rtlRender } from '@testing-library/react'
7+
import Provider from 'Providers'
8+
import { Provider as JotaiProvider } from 'jotai'
9+
import { useHydrateAtoms } from 'jotai/utils'
610
import noop from 'lodash/noop'
711
import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime'
812
import { NextRouter } from 'next/router'
9-
import Provider from 'Providers'
10-
import { Provider as JotaiProvider } from 'jotai'
1113
import { initializeStore, makeStore } from 'state'
1214
import { SWRConfig } from 'swr'
15+
import { wagmiConfig } from 'utils/wagmi'
1316
import { vi } from 'vitest'
1417
import { WagmiConfig } from 'wagmi'
15-
import { useHydrateAtoms } from 'jotai/utils'
16-
import { wagmiConfig } from 'utils/wagmi'
17-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
1818

1919
const mockRouter: NextRouter = {
2020
basePath: '',
@@ -83,7 +83,7 @@ export const createReduxWrapper =
8383
)
8484

8585
export const createSWRWrapper =
86-
(fallbackData = undefined) =>
86+
(fallbackData: any = undefined) =>
8787
({ children }) =>
8888
(
8989
<WagmiConfig config={wagmiConfig}>

apps/web/src/utils/wagmi.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { getWagmiConnector } from '@binance/w3w-wagmi-connector'
2+
import { CyberWalletConnector, isCyberWallet } from '@cyberlab/cyber-app-sdk'
13
import { ChainId } from '@pancakeswap/chains'
24
import { BinanceWalletConnector } from '@pancakeswap/wagmi/connectors/binanceWallet'
35
import { BloctoConnector } from '@pancakeswap/wagmi/connectors/blocto'
46
import { TrustWalletConnector } from '@pancakeswap/wagmi/connectors/trustWallet'
5-
import { CyberWalletConnector, isCyberWallet } from '@cyberlab/cyber-app-sdk'
6-
import { getWagmiConnector } from '@binance/w3w-wagmi-connector'
77
import memoize from 'lodash/memoize'
88
import { createConfig, createStorage } from 'wagmi'
99
import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet'
@@ -33,7 +33,9 @@ export const coinbaseConnector = new CoinbaseWalletConnector({
3333
export const walletConnectConnector = new WalletConnectConnector({
3434
chains,
3535
options: {
36-
showQrModal: true,
36+
// ignore the error in test environment
37+
// Error: To use QR modal, please install @walletconnect/modal package
38+
showQrModal: process.env.NODE_ENV !== 'test',
3739
projectId: 'e542ff314e26ff34de2d4fba98db70bb',
3840
},
3941
})

apps/web/src/views/Swap/index.test.tsx

-13
This file was deleted.

apps/web/vitest.config.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { defineConfig } from 'vitest/config'
21
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'
32
import react from '@vitejs/plugin-react'
4-
import tsconfigPaths from 'vite-tsconfig-paths'
53
import { resolve } from 'path'
4+
import tsconfigPaths from 'vite-tsconfig-paths'
5+
import { defineConfig } from 'vitest/config'
66

77
const r = (p: string) => resolve(__dirname, p)
88

@@ -21,9 +21,8 @@ export default defineConfig({
2121
},
2222
test: {
2323
setupFiles: ['./vitest.setup.js'],
24-
environment: 'jsdom',
24+
environment: 'happy-dom',
2525
globals: true,
26-
dangerouslyIgnoreUnhandledErrors: true, // wallet connect v2
2726
exclude: ['src/config/__tests__', 'node_modules'],
2827
},
2928
})

apps/web/vitest.setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// Used for __tests__/testing-library.js
44
// Learn more: https://github.com/testing-library/jest-dom
5-
import { vi } from 'vitest'
65
import '@testing-library/jest-dom/extend-expect'
6+
import { vi } from 'vitest'
77

88
global.setImmediate = vi.useRealTimers
99

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"eslint-plugin-address": "^0.0.2",
5555
"eslint-plugin-lodash": "^7.4.0",
5656
"husky": "^7.0.0",
57-
"jest": "^27.4.5",
5857
"lint-staged": "^12.3.4",
5958
"prettier": "^2.8.3",
6059
"serve": "^12.0.0",
@@ -68,7 +67,7 @@
6867
"tsx": "^3.12.6",
6968
"turbo": "1.10.2",
7069
"typescript": "5.2.2",
71-
"vitest": "^0.30.1",
70+
"vitest": "^1.2.2",
7271
"wrangler": "2.20.2"
7372
},
7473
"volta": {

packages/aptos-swap-sdk/jest.config.js

-18
This file was deleted.

packages/aptos-swap-sdk/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
"aptos": "1.x"
3939
},
4040
"devDependencies": {
41-
"@swc/core": "^1.2.215",
42-
"@swc/jest": "^0.2.21",
4341
"@types/big.js": "^4.0.5",
44-
"@types/jest": "^24.0.25",
4542
"tsup": "^6.7.0"
4643
},
4744
"engines": {

0 commit comments

Comments
 (0)