Skip to content

Commit e19e6bc

Browse files
✅ Moving tests from Mocha to Jest (#2257)
* ✅ Moving tests from Mocha to Jest * Getting coverage (disable cache in pipeline) * update README.md
1 parent 7d0cfd9 commit e19e6bc

File tree

63 files changed

+1584
-2882
lines changed

Some content is hidden

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

63 files changed

+1584
-2882
lines changed

.env.test

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ENV For tests

.github/workflows/build.yml

+11-38
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
with:
1515
node-version: 16
1616

17-
- name: Cache YARN dependencies
18-
uses: actions/cache@v3
19-
with:
20-
path: node_modules
21-
key: ${{ runner.OS }}-yarn-cache-${{ hashFiles('**/yarn.lock') }}
22-
restore-keys: |
23-
${{ runner.OS }}-yarn-cache-
17+
# - name: Cache YARN dependencies
18+
# uses: actions/cache@v3
19+
# with:
20+
# path: node_modules
21+
# key: ${{ runner.OS }}-yarn-cache-${{ hashFiles('**/yarn.lock', '**/package.json') }}
22+
# restore-keys: |
23+
# ${{ runner.OS }}-yarn-cache-
2424

2525
- name: Install
2626
run: yarn --no-progress --non-interactive --frozen-lockfile
@@ -31,39 +31,12 @@ jobs:
3131
- name: Prettier
3232
run: yarn format
3333

34-
# Disabled for now. Need to fix tests
35-
# - name: Test
36-
# run: CI=true yarn coverage
37-
3834
- name: Typecheck
3935
run: yarn typecheck
4036

41-
# test-e2e:
42-
# runs-on: ubuntu-latest
43-
# steps:
44-
# - uses: actions/checkout@v3
45-
#
46-
# - name: Cache YARN dependencies
47-
# uses: actions/cache@v3
48-
# with:
49-
# path: node_modules
50-
# key: ${{ runner.OS }}-yarn-cache-${{ hashFiles('**/yarn.lock') }}
51-
# restore-keys: |
52-
# ${{ runner.OS }}-yarn-cache-
53-
#
54-
# - name: Install
55-
# run: yarn --no-progress --non-interactive --frozen-lockfile
56-
#
57-
# - name: Run deps
58-
# run: |
59-
# cd ./scripts
60-
# docker-compose up -d
61-
# sleep 10
62-
#
63-
# - name: Test-e2e
64-
# run: yarn test:e2e
37+
- name: Test
38+
run: CI=true yarn test
6539

66-
# Few tips github actions
67-
# - name: Setup SSH debug session
68-
# uses: mxschmitt/action-tmate@v2
40+
- name: Upload coverage to Codecov
41+
uses: codecov/codecov-action@v2
6942

.mocharc.js

-50
This file was deleted.

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ yarn test:fix
248248

249249
<br>
250250

251+
## Unit tests :construction_worker:
252+
We are currently in the process of moving our tests from Mocha (with Chai, Enzyme, and Sinon) to Jest (with React Testing Library).
253+
We are also in the process of adding more tests to increase our coverage.
254+
We have some tests skipped for now, but we are working on fixing them.
255+
**We needed to disable caching in the `build` action. Testing with collecting coverage was failing with caching enabled.**
256+
Skipped tests (Marked with `TODO: [Mocha -> Jest] Rewrite in Jest compatible format.`):
257+
- [Batch Manager](helpers/api/BatchManager.test.ts)
258+
- [Manage Vault Validations](features/borrow/manage/tests/manageVaultValidations.test.ts)
259+
- [Earn Calculations](features/earn/calculations.test.ts)
260+
- [Manage Multiply Vault](features/multiply/manage/tests/manageMultiplyVault.test.ts)
261+
- [Manage Multiply Vault - Adjust Validations](features/multiply/manage/tests/manageMultiplyVaultAdjustPositionValidations.test.ts)
262+
- [Manage Multiply Vault - Other Action Validations](features/multiply/manage/tests/manageMultiplyVaultOtherActionsValidations.test.ts)
263+
- [Open Multiply Vault](features/multiply/open/tests/openMultiplyVault.test.ts)
264+
- [Maker Protocol Bonus Adapter](features/bonus/makerProtocolBonusAdapter.test.ts)
265+
- [Blockchain Utils](blockchain/utils.test.ts)
266+
- [Vault Math](blockchain/vault.maths.test.ts)
267+
251268
## License
252269

253270
Copyright (C) 2021 Oazo Apps Limited, Licensed under the Apache License, Version 2.0 (the
+7-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { getCollaterals, getCollateralTokens } from 'blockchain/addresses/addressesUtils'
22
import mainnet from 'blockchain/addresses/mainnet.json'
33
import { supportedIlks } from 'blockchain/tokens/mainnet'
4-
import { expect } from 'chai'
54

65
describe('adressesUtils', () => {
7-
it('should filter collaterals correctly', async function () {
6+
it('should filter collaterals correctly', async () => {
87
const actual = getCollaterals({ PIP_ETH: '', PIP_XYZ: '', XYZ_WBTC: '' }, supportedIlks)
9-
expect(actual).to.be.not.undefined
10-
expect(actual.length).to.be.equal(1)
11-
expect(actual[0]).to.be.equal('ETH')
8+
expect(actual).toBeDefined()
9+
expect(actual.length).toBe(1)
10+
expect(actual[0]).toBe('ETH')
1211
})
13-
it('should filter collateral tokens correctly', async function () {
12+
it('should filter collateral tokens correctly', async () => {
1413
const collaterals = getCollaterals(mainnet, supportedIlks)
1514
const tokens = getCollateralTokens(mainnet, supportedIlks)
16-
expect(Object.keys(tokens).length).to.be.equal(collaterals.length)
15+
expect(Object.keys(tokens).length).toBe(collaterals.length)
1716
Object.keys(tokens).forEach((element, idx) => {
18-
expect(element).to.be.equal(collaterals[idx])
17+
expect(element).toBe(collaterals[idx])
1918
})
2019
})
2120
})

blockchain/calls/proxyActions/proxyActionsResolver.test.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { MakerVaultType } from 'blockchain/calls/vaultResolver'
2-
import { expect } from 'chai'
32
import { getStateUnpacker } from 'helpers/testHelpers'
43

54
import { ProxyActionsAdapterType } from './adapters/ProxyActionsSmartContractAdapterInterface'
@@ -12,21 +11,21 @@ describe('proxyActionsAdapterResolver', () => {
1211

1312
const state = getStateUnpacker(adapter$)
1413

15-
expect(state().AdapterType).to.eq(ProxyActionsAdapterType.CROPJOIN)
14+
expect(state().AdapterType).toBe(ProxyActionsAdapterType.CROPJOIN)
1615
})
1716
it('returns default proxy actions for other ilks', () => {
1817
const adapter$ = proxyActionsAdapterResolver$({ ilk: 'ETH-A' })
1918

2019
const state = getStateUnpacker(adapter$)
2120

22-
expect(state().AdapterType).to.eq(ProxyActionsAdapterType.STANDARD)
21+
expect(state().AdapterType).toBe(ProxyActionsAdapterType.STANDARD)
2322
})
2423
it('throws when trying to open a charter vault', () => {
2524
const adapter$ = proxyActionsAdapterResolver$({ ilk: 'INST-ETH-A' })
2625

2726
const state = getStateUnpacker(adapter$)
2827

29-
expect(state).to.throw(
28+
expect(state).toThrow(
3029
'can not create a proxy actions adapter from an INST-ETH-A ilk - adapter is not tested for opening vaults',
3130
)
3231
})
@@ -38,21 +37,21 @@ describe('proxyActionsAdapterResolver', () => {
3837

3938
const state = getStateUnpacker(adapter$)
4039

41-
expect(state().AdapterType).to.eq(ProxyActionsAdapterType.CROPJOIN)
40+
expect(state().AdapterType).toBe(ProxyActionsAdapterType.CROPJOIN)
4241
})
4342
it('returns CHARTER proxy actions for CHARTER vault type', () => {
4443
const adapter$ = proxyActionsAdapterResolver$({ makerVaultType: MakerVaultType.CHARTER })
4544

4645
const state = getStateUnpacker(adapter$)
4746

48-
expect(state().AdapterType).to.eq(ProxyActionsAdapterType.CHARTER)
47+
expect(state().AdapterType).toBe(ProxyActionsAdapterType.CHARTER)
4948
})
5049
it('returns standard proxy actions in all other cases', () => {
5150
const adapter$ = proxyActionsAdapterResolver$({ makerVaultType: MakerVaultType.STANDARD })
5251

5352
const state = getStateUnpacker(adapter$)
5453

55-
expect(state().AdapterType).to.eq(ProxyActionsAdapterType.STANDARD)
54+
expect(state().AdapterType).toBe(ProxyActionsAdapterType.STANDARD)
5655
})
5756
})
5857
})

blockchain/calls/proxyActions/vaultActionsLogic.test.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { BigNumber } from 'bignumber.js'
22
import { TxMetaKind } from 'blockchain/calls/txMeta'
3-
import { expect } from 'chai'
43
import { mockContextConnected } from 'helpers/mocks/context.mock'
54
import { one } from 'helpers/zero'
6-
import { describe } from 'mocha'
75

86
import { MockProxyActionsSmartContractAdapter } from './adapters/mockProxyActionsSmartContractAdapter'
97
import { vaultActionsLogic } from './vaultActionsLogic'
@@ -52,8 +50,8 @@ describe('vaultActionsLogic', () => {
5250
const actualMethodName = JSON.parse(methodCalled).method
5351

5452
it(testName, () => {
55-
expect(actualMethodName).to.eq(expectedMethodName)
56-
expect(proxyActionAddress).to.eq('0x-mock-dss-proxy-action-address')
53+
expect(actualMethodName).toBe(expectedMethodName)
54+
expect(proxyActionAddress).toBe('0x-mock-dss-proxy-action-address')
5755
})
5856
}
5957

@@ -201,8 +199,8 @@ describe('vaultActionsLogic', () => {
201199
const actualMethodName = JSON.parse(methodCalled).method
202200

203201
it(testName, () => {
204-
expect(actualMethodName).to.eq(expectedMethodCalled)
205-
expect(proxyActionAddress).to.eq('0x-mock-dss-proxy-action-address')
202+
expect(actualMethodName).toBe(expectedMethodCalled)
203+
expect(proxyActionAddress).toBe('0x-mock-dss-proxy-action-address')
206204
})
207205
}
208206

@@ -298,8 +296,8 @@ describe('vaultActionsLogic', () => {
298296
const actualMethodName = JSON.parse(methodCalled).method
299297

300298
it(testName, () => {
301-
expect(actualMethodName).to.eq(expectedMethod)
302-
expect(proxyActionAddress).to.eq('0x-mock-dss-proxy-action-address')
299+
expect(actualMethodName).toBe(expectedMethod)
300+
expect(proxyActionAddress).toBe('0x-mock-dss-proxy-action-address')
303301
})
304302
}
305303

blockchain/collateral.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import BigNumber from 'bignumber.js'
2-
import { expect } from 'chai'
32
import { getStateUnpacker } from 'helpers/testHelpers'
43
import { Observable, of, throwError } from 'rxjs'
54

@@ -31,7 +30,7 @@ describe('getTotalValueLocked$', () => {
3130

3231
const state = getStateUnpacker(result)()
3332

34-
expect(state).to.eql({
33+
expect(state).toEqual({
3534
value: new BigNumber(6),
3635
})
3736
})

blockchain/ilks.test.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { expect } from 'chai'
21
import {
32
debtScalingFactor$,
43
DEFAULT_DEBT_SCALING_FACTOR,
@@ -14,18 +13,18 @@ describe('ilkData$', () => {
1413
it('should produce IlkData state', () => {
1514
const state = mockIlkData()
1615

17-
expect(state()).to.not.be.undefined
16+
expect(state()).toBeDefined()
1817
})
1918

2019
it('should account for accrued debt', () => {
2120
const state = mockIlkData()
2221

23-
expect(state().ilkDebt).to.deep.equal(defaultIlkDebt)
22+
expect(state().ilkDebt).toEqual(defaultIlkDebt)
2423
const expectedIlkDebtAvailable = defaultIlkDebt.times(2.5).minus(defaultIlkDebt)
25-
expect(state().ilkDebtAvailable).to.deep.equal(expectedIlkDebtAvailable)
24+
expect(state().ilkDebtAvailable).toEqual(expectedIlkDebtAvailable)
2625

2726
debtScalingFactor$.next(RANDOM_DEBT_SCALING_FACTOR)
28-
expect(state().ilkDebt.gt(defaultIlkDebt)).to.be.true
29-
expect(state().ilkDebtAvailable.lt(expectedIlkDebtAvailable)).to.be.true
27+
expect(state().ilkDebt.gt(defaultIlkDebt)).toBe(true)
28+
expect(state().ilkDebtAvailable.lt(expectedIlkDebtAvailable)).toBe(true)
3029
})
3130
})

blockchain/instiVault.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BigNumber } from 'bignumber.js'
2-
import { expect } from 'chai'
32
import { mockVault$ } from 'helpers/mocks/vaults.mock'
43
import { getStateUnpacker } from 'helpers/testHelpers'
54
import { zero } from 'helpers/zero'
@@ -30,8 +29,8 @@ describe('instiVault$', () => {
3029
charterPeace$.next(new BigNumber(6))
3130
charterUline$.next(new BigNumber(11))
3231

33-
expect(state().originationFeePercent.toString()).to.eq('2')
34-
expect(state().activeCollRatio.toString()).to.eq('6')
32+
expect(state().originationFeePercent.toString()).toBe('2')
33+
expect(state().activeCollRatio.toString()).toBe('6')
3534
})
3635

3736
it('takes the debt ceiling/available ilk debt from the charter contract', () => {
@@ -47,6 +46,6 @@ describe('instiVault$', () => {
4746
})
4847

4948
const state = getStateUnpacker(instiVault$)
50-
expect(state().daiYieldFromLockedCollateral.toString()).to.eq('800000000')
49+
expect(state().daiYieldFromLockedCollateral.toString()).toBe('800000000')
5150
})
5251
})

0 commit comments

Comments
 (0)