Skip to content

Commit

Permalink
switch back to vitest (#159)
Browse files Browse the repository at this point in the history
* switch back to vitest

* update endpoints
  • Loading branch information
ermalkaleci authored Jan 28, 2024
1 parent 397012a commit 908eaae
Show file tree
Hide file tree
Showing 39 changed files with 11,891 additions and 1,645 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: { project: 'tsconfig.json' },
plugins: ['@typescript-eslint', 'import', 'sort-imports-es6-autofix'],
extends: [
'eslint:recommended',
Expand All @@ -26,7 +27,7 @@ module.exports = {
},
settings: {
'import/resolver': {
'typescript-bun': {
typescript: {
project: 'tsconfig.json',
},
},
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@ jobs:
fail-fast: false
matrix:
tests: [xcm-transfer, acala, bridge-sdk]
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: oven-sh/setup-bun@v1
- name: setup node
uses: actions/setup-node@v4
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun update-env
- run: bun test tests/${{ matrix.tests }}
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn update-env
- run: yarn test tests/${{ matrix.tests }}
- uses: ravsamhq/notify-slack-action@v2
if: ${{ failure() }}
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

32 changes: 19 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
DB_PATH: ./db.sqlite
FORCE_COLOR: 1

jobs:
lint:
Expand All @@ -17,28 +16,35 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: oven-sh/setup-bun@v1
- name: Use Node.js
uses: actions/setup-node@v4
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun lint
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn lint
tests:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
tests: [xcm-transfer, acala, bridge-sdk]
runs-on: [self-hosted]
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 18
- uses: oven-sh/setup-bun@v1
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v4
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun update-env
- run: bun test tests/${{ matrix.tests }}
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn update-env
- run: yarn test tests/${{ matrix.tests }}
18 changes: 13 additions & 5 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: oven-sh/setup-bun@v1
- name: setup node
uses: actions/setup-node@v4
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun update-env
- run: bun test --update-snapshots
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn update-env
- run: yarn test -u
- name: Commit and Create PR
uses: actions/github-script@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

bun lint-staged
yarn lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.yarn
*.yml
*.md
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Tests are powered by [Chopsticks](http://github.com/AcalaNetwork/chopsticks) to
## Running tests

All tests:
`bun test`
`yarn test`

Run one test only:
`bun test ./tests/xcm-transfer/kusama-relay.test.ts`
`yarn test ./tests/xcm-transfer/kusama-relay.test.ts`

Or you can just use a keywork since it is using vitest and use regex to find tests:
`bun test xcm`
`yarn test xcm`

## Check compatibility with upcoming runtime

Expand All @@ -23,11 +23,11 @@ If there are expected breaking change, you can add a new network with the new ru

## Contributing

This repo is using [bun test](https://bun.sh/docs/cli/test) as the test runner. Most of the tests are written as [snapshot tests](https://bun.sh/guides/test/snapshot). The test will run and save the result as snapshot in a `.snap` file, and next time when the test runs again, it will compare the result with the snapshot. This eliminates the need to write assertions and make the test more readable.
This repo is using [vitest](https://vitest.dev) as the test runner. Most of the tests are written as [snapshot tests](https://vitest.dev/guide/snapshot.html#snapshot). The test will run and save the result as snapshot in a `.snap` file, and next time when the test runs again, it will compare the result with the snapshot. This eliminates the need to write assertions and make the test more readable.

There is [periodic check](https://github.com/AcalaNetwork/e2e-tests/actions/workflows/check.yml) Github Action to run the tests against latest mainnet block to detect compatibility issues with live networks.

It is recommended use `bun update-env` to update the `.env` file with latest block number before running the tests. This ensures tests are always running against the same blocks so that block data can be cached and reused to speed up test running time. Once you have a working test, update the blocks number again and rerun the tests to ensure the tests are block number indpendent. Use `redact` and event filters to make the snapshot be consistent regardless the block number.
It is recommended use `yarn update-env` to update the `.env` file with latest block number before running the tests. This ensures tests are always running against the same blocks so that block data can be cached and reused to speed up test running time. Once you have a working test, update the blocks number again and rerun the tests to ensure the tests are block number indpendent. Use `redact` and event filters to make the snapshot be consistent regardless the block number.

### Files

Expand Down Expand Up @@ -125,7 +125,7 @@ DB_PATH=./db.sqlite

Use specific block number for tests and db cache can signficantly improve test running speed.

Run `bun update-env` to update .env file with latest block number.
Run `yarn update-env` to update .env file with latest block number.

To debug failing tests on CI, find the block number config from CI log and put them in .env to run the test with the same block height.

Expand Down
Binary file removed bun.lockb
Binary file not shown.
22 changes: 2 additions & 20 deletions helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from 'bun:test'
import { expect } from 'vitest'

import { withExpect } from '@acala-network/chopsticks-testing'

const { check, checkEvents, checkHrmp, checkSystemEvents, checkUmp } = withExpect((x: any) => ({
toMatchSnapshot(msg?: string): void {
expect(x).toMatchSnapshot(msg as any) // as any required to workaround https://github.com/oven-sh/bun/issues/7786
expect(x).toMatchSnapshot(msg)
},
toMatch(value: any, _msg?: string): void {
expect(x).toMatch(value)
Expand All @@ -17,21 +17,3 @@ const { check, checkEvents, checkHrmp, checkSystemEvents, checkUmp } = withExpec
export { check, checkEvents, checkHrmp, checkSystemEvents, checkUmp }

export * from '@acala-network/chopsticks-testing'

const defaultTimeout = process.env.CI ? 180000 : 240000

export const jest = (filename: string) => {
const { beforeEach, afterEach, afterAll, expect, describe, it } = (Bun as any).jest(filename) // workaround https://github.com/oven-sh/bun/issues/7873

const newIt = (name: string, fn: any, timeout = defaultTimeout) => {
it(
name,
async () => {
await fn()
},
timeout,
)
}

return { beforeEach, afterEach, afterAll, expect, describe, it: newIt }
}
8 changes: 6 additions & 2 deletions networks/acala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ export type Vars = {
export default {
polkadot: {
name: 'acala' as const,
endpoint: 'wss://acala-rpc.aca-api.network',
endpoint: ['wss://acala-rpc.aca-api.network', 'wss://acala-rpc.dwellir.com'],
relayToken: 'DOT',
relayLiquidToken: 'LDOT',
stableToken: 'AUSD',
},
kusama: {
name: 'karura' as const,
endpoint: 'wss://karura-rpc.aca-api.network',
endpoint: [
'wss://karura-rpc.aca-api.network',
'wss://rpc-karura.luckyfriday.io',
'wss://karura.api.onfinality.io/public-ws',
],
relayToken: 'KSM',
relayLiquidToken: 'LKSM',
stableToken: 'KUSD',
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"lint": "tsc --noEmit && eslint . --ext .js,.ts && prettier --check .",
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
"prepare": "husky install",
"test": "LOG_LEVEL=error bun test",
"test": "LOG_LEVEL=error vitest",
"test:ui": "LOG_LEVEL=error vitest --ui",
"update-env": "tsx scripts/update-env.ts"
},
"resolutions": {
Expand All @@ -18,19 +19,23 @@
"@acala-network/sdk-core": "^4.1.9-10",
"@polkadot/api": "^10.11.2",
"@polkawallet/bridge": "^0.1.5-19",
"@swc/core": "^1.3.106",
"axios": "^1.6.6",
"dotenv": "^16.3.1",
"lodash": "^4.17.21",
"typescript": "^5.3.2"
"typescript": "^5.3.3",
"unplugin-swc": "^1.4.4",
"vitest": "^1.2.1"
},
"devDependencies": {
"@types/lodash": "^4",
"@types/node": "^20.9.4",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"bun-types": "latest",
"@vitest/ui": "^1.2.1",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript-bun": "^0.0.58",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"husky": "^8.0.3",
Expand All @@ -46,5 +51,6 @@
"lint-staged": {
"*.ts": "eslint --cache --fix",
"*.{ts,css}": "prettier --write"
}
},
"packageManager": "[email protected]"
}
22 changes: 11 additions & 11 deletions tests/acala/__snapshots__/aggregated-dex.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Bun Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`karura aggregatedDex' swapWithExactSupply: events 1`] = `
exports[`acala aggregatedDex' > swapWithExactSupply > events 1`] = `
[
{
"data": {
Expand All @@ -11,24 +11,24 @@ exports[`karura aggregatedDex' swapWithExactSupply: events 1`] = `
],
"path": [
{
"Token": "KSM",
"Token": "ACA",
},
{
"ForeignAsset": "(number)",
"Token": "AUSD",
},
{
"Token": "KUSD",
"Token": "LDOT",
},
],
"trader": "rPizfonc8MPuEsMxufAytHjpRW7a2YrXWHKibaJXe9ZtjKx",
"trader": "23y3WetbNi6rDMgHmyRDjgpb7PnhgPotuPPawxruTMLYTLzG",
},
"method": "Swap",
"section": "dex",
},
]
`;

exports[`acala aggregatedDex' swapWithExactSupply: events 1`] = `
exports[`karura aggregatedDex' > swapWithExactSupply > events 1`] = `
[
{
"data": {
Expand All @@ -39,16 +39,16 @@ exports[`acala aggregatedDex' swapWithExactSupply: events 1`] = `
],
"path": [
{
"Token": "ACA",
"Token": "KSM",
},
{
"Token": "AUSD",
"ForeignAsset": "(number)",
},
{
"Token": "LDOT",
"Token": "KUSD",
},
],
"trader": "23y3WetbNi6rDMgHmyRDjgpb7PnhgPotuPPawxruTMLYTLzG",
"trader": "rPizfonc8MPuEsMxufAytHjpRW7a2YrXWHKibaJXe9ZtjKx",
},
"method": "Swap",
"section": "dex",
Expand Down
Loading

0 comments on commit 908eaae

Please sign in to comment.