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

Bun tests #151

Merged
merged 9 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
vitest.config.ts
.eslintrc.js
node_modules/
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -24,11 +23,10 @@ module.exports = {
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-floating-promises': ['error'],
},
settings: {
'import/resolver': {
typescript: {
'typescript-bun': {
project: 'tsconfig.json',
},
},
Expand Down
18 changes: 5 additions & 13 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: setup node
uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v1
with:
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 }}
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun update-env
- run: bun test tests/${{ matrix.tests }}
- uses: ravsamhq/notify-slack-action@v2
if: ${{ failure() }}
with:
Expand Down
30 changes: 10 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,25 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Use Node.js
uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v1
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn lint
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun lint
tests:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
tests: [xcm-transfer, acala, bridge-sdk]
runs-on: [self-hosted, linux]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v1
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn update-env
- run: yarn test tests/${{ matrix.tests }}
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun update-env
- run: bun test tests/${{ matrix.tests }}
18 changes: 5 additions & 13 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: setup node
uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v1
with:
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
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun update-env
- run: bun test --update-snapshots
- 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"

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

This file was deleted.

7 changes: 0 additions & 7 deletions .yarnrc.yml

This file was deleted.

15 changes: 7 additions & 8 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:
`yarn test`
`bun test`

Run one test only:
`yarn test ./tests/xcm-transfer/kusama-relay.test.ts`
`bun 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:
`yarn test xcm`
`bun 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 [vitest](https://vitest.dev) as the test runner. Most of the tests are written as [snapshot tests](https://vitest.dev/guide/snapshot.html). 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 [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.

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 `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.
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.

### Files

Expand All @@ -38,8 +38,7 @@ It is recommended use `yarn update-env` to update the `.env` file with latest bl
### Debugging Tips

- Move the failed test to [playground.test.ts](./tests/xcm-transfer/playground.test.ts) to only run the failed test.
- Use `yarn vitest` instead of `yarn test` to display logs.
- Add `-u` to automatically update snapshots and use git diff tool to compare the changes.
- Add `--update-snapshots` to automatically update snapshots and use git diff tool to compare the changes.
- For failed CI tests, check the block numbers from the `update-env` steps in the logs to local `.env` file to be able to run the tests with the same block height.
- Remove the system events filter to see all the events in snapshots.
- e.g. Replace `checkSystemEvents(toChain, 'parachainSystem', 'dmpQueue')` to `checkSystemEvents(toChain)`
Expand Down Expand Up @@ -126,7 +125,7 @@ DB_PATH=./db.sqlite

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

Run `yarn update-env` to update .env file with latest block number.
Run `bun 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 added bun.lockb
Binary file not shown.
Loading