Skip to content

Commit

Permalink
Merge pull request #66 from vechain/chore/use-vitest
Browse files Browse the repository at this point in the history
chore(tests): use vitest framework
  • Loading branch information
darrenvechain authored Jan 20, 2025
2 parents 252dc85 + fea645a commit 073c280
Show file tree
Hide file tree
Showing 36 changed files with 958 additions and 4,219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ jobs:
list-suites: 'all'
list-tests: 'all'
fail-on-error: 'true'
reporter: 'jest-junit'
reporter: 'java-junit'
path: |
junit.xml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ yarn test
# Start a thor solo instance so your tests can run quickly
yarn docker:solo:up
# Run a single test / test suite
yarn test -t 'GET /accounts/{address}/storage'
yarn test test/thorest-api/accounts/get-account-storage.test.js
```

### Custom Docker Image
Expand All @@ -41,7 +41,7 @@ yarn test
yarn test -t <group/test>

yarn test -t "opcodes" # Example for the opcodes group (@group)
yarn test -t "should give the correct output for opcode: ADDRESS" # Example for that specific test (first parameter at it.e2eTest)
yarn test test/evm/individual-opcodes.test.js -t 'should give the correct output for opcode: ADDRESS' # Example for that specific test (first parameter at it.e2eTest)
```

### Custom solo url
Expand Down
6 changes: 0 additions & 6 deletions babel.config.js

This file was deleted.

28 changes: 11 additions & 17 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import pluginJest from 'eslint-plugin-jest'
import eslintConfigPrettier from 'eslint-config-prettier'
import jestExtended from 'eslint-plugin-jest-extended'
// import js from "@eslint/js";
import vitest from '@vitest/eslint-plugin'
import js from '@eslint/js'

export default [
// js.configs.recommended,
jestExtended.configs['flat/all'],
eslintConfigPrettier,
{
plugins: { jest: pluginJest },
plugins: { vitest },
languageOptions: {
globals: pluginJest.environments.globals.globals,
globals: {
...vitest.environments.env.globals,
node: true,
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2024,
},
},
files: ['**/*.spec.js', '**/*.test.js'],
files: ['src/**/*.js', 'test/**/*.js'],
ignores: [
'.yarn/*',
'*config.js',
Expand All @@ -28,16 +30,8 @@ export default [
'coverage/',
],
rules: {
indent: ['error', 2],
'jest/prefer-expect-assertions': 'warn',
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': ['error', { minArgs: 1, maxArgs: 2 }],
'jest-extended/prefer-to-be-true': 'warn',
'jest-extended/prefer-to-be-false': 'error',
...vitest.configs.recommended.rules, // you can also use vitest.configs.all.rules to enable all rules
'vitest/max-nested-describe': ['error', { max: 3 }], // you can also modify rules' behavior using option like this
},
},
eslintConfigPrettier,
]
2 changes: 0 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { HardhatUserConfig } from 'hardhat/types'
import '@typechain/hardhat'
import '@nomicfoundation/hardhat-ethers'
import '@nomicfoundation/hardhat-chai-matchers'
import '@nomicfoundation/hardhat-toolbox'

const config: HardhatUserConfig = {
solidity: {
Expand Down
45 changes: 0 additions & 45 deletions jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion network/config/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ thor \
--api-addr="0.0.0.0:8669" \
--api-cors="*" \
--api-allowed-tracers="all" \
--verbosity=9 \
--verbosity=4 \
--bootnode "enode://e32e5960781ce0b43d8c2952eeea4b95e286b1bb5f8c1f0c9f09983ba7141d2fdd7dfbec798aefb30dcd8c3b9b7cda8e9a94396a0192bfa54ab285c2cec515ab@$BOOTNODE_IP:55555" \
--api-enable-deprecated
33 changes: 4 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,78 +12,53 @@
"docker:restart": "yarn docker:down && yarn docker:up",
"docker:solo:up": "docker compose -f network/docker-compose-solo.yaml up -d --wait",
"docker:solo:down": "docker compose -f network/docker-compose-solo.yaml down",
"test": "yarn jest --forceExit",
"test": "yarn vitest run",
"generate:openapi": "yarn openapi-typescript -o ./src/open-api-types.ts",
"generate:accounts": "ts-node scripts/generate-genesis-accounts.ts",
"format": "prettier . --write",
"lint": "eslint . ",
"prepare": "husky"
},
"devDependencies": {
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@eslint/js": "^9.16.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/babel__core": "^7",
"@types/jest": "^29.5.14",
"@types/node": ">=16.0.0",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@vitest/eslint-plugin": "^1.1.25",
"@vitest/ui": "3.0.1",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-jest-extended": "^2.4.0",
"eslint-plugin-prettier": "^5.2.1",
"ethers": "^6.13.4",
"hardhat": "^2.14.0",
"hardhat-gas-reporter": "^1.0.8",
"hardhat-jest": "^1.0.8",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jest-expect-message": "^1.1.3",
"jest-html-reporters": "^3.1.7",
"jest-json-result": "^1.0.0",
"jest-junit": "^16.0.0",
"node-dir": "^0.1.17",
"openapi-typescript": "^7.4.4",
"prettier": "^3.4.2",
"prettier-eslint": "^16.3.0",
"solidity-coverage": "^0.8.14",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.7.2",
"yarn": "^1.22.22"
},
"dependencies": {
"@babel/core": "^7.26.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
"@nomicfoundation/hardhat-ethers": "^3.0.8",
"@nomicfoundation/hardhat-ignition": "^0.15.8",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.8",
"@nomicfoundation/hardhat-network-helpers": "^1.0.12",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.12",
"@nomicfoundation/ignition-core": "^0.15.8",
"@openzeppelin/contracts": "^5.1.0",
"@types/chai": "^4.3.16",
"@types/proper-lockfile": "^4.1.4",
"@vechain/sdk-core": "1.0.0-rc.5",
"@vechain/sdk-logging": "1.0.0-rc.5",
"@vechain/sdk-network": "1.0.0-rc.5",
"async-mutex": "^0.5.0",
"axios": "^1.7.9",
"bignumber.js": "^9.1.2",
"chai": "4.2.0",
"dotenv": "^16.4.7",
"hardhat-ethers": "^1.0.1",
"jest-docblock": "^29.7.0",
"jest-extended": "^4.0.2",
"jest-runner": "^29.7.0",
"jest-runner-groups": "^2.2.0",
"prettier-plugin-solidity": "^1.4.1",
"proper-lockfile": "^4.1.2",
"vitest": "^3.0.1",
"web3": "4.16.0",
"ws": "^8.18.0"
}
Expand Down
2 changes: 1 addition & 1 deletion test/evm/eth-opcodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ describe('EVM Opcodes', () => {
await pollReceipt(id)
const tx = await wait()

expect(tx?.reverted).toBeTrue()
expect(tx?.reverted).toBeTruthy()
})
})
8 changes: 4 additions & 4 deletions test/evm/evm-methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('EVM methods', () => {
it.e2eTest('should be able to get "msg.value"', 'all', async () => {
const msgValue = await evmMethods.transact.getMsgValue({ value: 100 })
const receipt = await msgValue.wait(3, 15)
expect(receipt.reverted).toBeFalse()
expect(receipt.reverted).toBeFalsy()
})

it.e2eTest('should be able to get "tx.gasprice"', 'all', async () => {
Expand Down Expand Up @@ -162,10 +162,10 @@ describe('EVM methods', () => {

it.e2eTest('should require condition to be true', 'all', async () => {
const res = await evmMethods.read.requireCondition(true, 'Error')
expect(res).toEqual([])
expect(res).toEqual([undefined])
})

it.e2eTest('should require condition to be true', 'all', async () => {
it.e2eTest('should require condition to be false', 'all', async () => {
const { clause } = await evmMethods.clause.requireCondition(
false,
'Error',
Expand All @@ -180,7 +180,7 @@ describe('EVM methods', () => {

it.e2eTest('should assert condition to be true', 'all', async () => {
const res = await evmMethods.read.assertCondition(true, 'Error')
expect(res).toEqual([])
expect(res).toEqual([undefined])
})

it.e2eTest('should call external function', 'all', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/evm/individual-opcodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('Individual OpCodes', () => {

expect(
debugged.structLogs.some((log) => log.op === name),
).toBeTrue()
).toBeTruthy()
expect(debugged.returnValue).toBe(expected)
},
)
Expand All @@ -440,7 +440,7 @@ describe('Individual OpCodes', () => {

expect(
debugged.structLogs.some((log) => log.op === 'BALANCE'),
).toBeTrue()
).toBeTruthy()
expect(balance).toBeGreaterThan(0)
},
)
Expand Down Expand Up @@ -603,7 +603,7 @@ describe('Individual OpCodes', () => {

const receipt = await pollReceipt(tx.id ?? '')

expect(receipt.reverted).toBeTrue()
expect(receipt.reverted).toBeTruthy()

// 0x5f is the PUSH0 opcode
const simulation = await Client.raw.executeAccountBatch({
Expand Down Expand Up @@ -633,7 +633,7 @@ describe('Individual OpCodes', () => {
caller,
})

expect(simulation.body?.[0]?.vmError).toBeEmpty()
expect(simulation.body?.[0]?.vmError.length).toBe(0)
},
)
})
1 change: 0 additions & 1 deletion test/globalSetup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Client } from '../src/thor-client'
import 'jest-expect-message'
import 'dotenv/config'
import { testEnv, validateEnv } from '../src/test-env'
import { transferDetails } from '../src/constants'
Expand Down
6 changes: 3 additions & 3 deletions test/setupAfterEnv.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Client } from '../src/thor-client'
import 'dotenv/config'
import { testEnv } from '../src/test-env'
import { test, it } from 'vitest'

it.e2eTest = (title, tags, testFunc) => {
if (tags === 'all' || tags.includes(testEnv.type)) {
// eslint-disable-next-line vitest/valid-title,vitest/expect-expect
test(title, testFunc)
} else {
// eslint-disable-next-line vitest/valid-title
test.skip(title, testFunc)
}
}

jest.retryTimes(3, { logErrorsBeforeRetry: true })

afterAll(async () => {
Client.raw.closeAllSubscriptions()
jest.clearAllTimers()
Client.sdk.destroy()
})
Loading

0 comments on commit 073c280

Please sign in to comment.