Skip to content

Commit

Permalink
Merge pull request #190 from AElfProject/feature/test-chain-util
Browse files Browse the repository at this point in the history
Feature/test chain util
  • Loading branch information
hzz780 authored Aug 22, 2024
2 parents 0e2969b + 4bf7d78 commit 7f6b201
Show file tree
Hide file tree
Showing 96 changed files with 11,914 additions and 48,642 deletions.
23 changes: 8 additions & 15 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,28 @@
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3,
"modules": false,
"targets": "> 1%, not dead"
"targets": "> 0.5%, last 2 versions, Firefox ESR, not dead"
}
]
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
],
"ignore": [
"dist/*.js"
],
"ignore": ["dist/*.js"],
"env": {
"test": {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3,
"modules": "auto"
}
]
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
],
"ignore": [
"dist/*.js"
]
"plugins": ["rewire"],
"ignore": ["dist/*.js"]
}
}
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ jest.browser.config.js
jest.node.config.js
examples
test
types
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"parser": "babel-eslint",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Unit Test Coverage

on:
push:
branches:
- feature/test-chain-util
pull_request:
branches:
- feature/test-chain-util

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: yarn install

- name: Run tests with coverage
run: yarn run test:coverage

- name: Generate coverage badge
uses: jaywcjlove/coverage-badges-cli@main
with:
source: coverage/coverage-summary.json
output: coverage/badges.svg

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./coverage
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ jobs:
with:
node-version: 16

- name: Install and Build
- name: Install, Test and Build
run: |
yarn install
yarn run test
yarn run build
- name: Publish to npm
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish
env:
CI: true
on:
push:
branches:
- feature/test-chain-util
tags:
- '!*'
jobs:
release:
name: Setup
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'

- name: Install dependencies
run: yarn install

- name: Publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
npm publish || (echo "pnpm publish failed" && exit 1)
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108 changes: 108 additions & 0 deletions .github/workflows/test-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Test Badge

permissions:
contents: write

on:
push:
branches:
- dev
- master
- feature/test-chain-util

env:
BRANCH_NAME: 'feature/badge-json'

jobs:
test:
name: Generate Test Badge
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 20
cache: yarn
- run: yarn install
- run: yarn run test:browser
- name: Install xmlstarlet
run: |
sudo apt-get update
sudo apt-get install -y xmlstarlet
- name: Extract test counts
run: |
echo "TESTS=$(xmlstarlet sel -t -v "testsuites/@tests" "jest-report.xml")" >> $GITHUB_ENV
echo "FAILURES=$(xmlstarlet sel -t -v "testsuites/@failures" "jest-report.xml")" >> $GITHUB_ENV
echo "ERRORS=$(xmlstarlet sel -t -v "testsuites/@errors" "jest-report.xml")" >> $GITHUB_ENV
- name: Set file name
run: echo "FILENAME=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-')-test-results.json" >> $GITHUB_ENV

- name: Prepare Content
uses: actions/github-script@v5
with:
github-token: ${{ secrets.COMMIT_TOKEN }}
script: |
const fs = require('fs');
const tests = "${{ env.TESTS }}";
const failures = "${{ env.FAILURES }}";
const errors = "${{ env.ERRORS }}";
const success = tests - failures;
const color = errors > 0 ? "red" : (failures > 0 ? "green" : "brightgreen");
const content = `{"schemaVersion":1,"label":"tests","message":"${tests} tests, ${success} success","color":"${color}"}`;
fs.writeFileSync("${{ env.FILENAME }}", content);
- name: Check if file exists
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fileExists = false;
try {
const { data } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: "${{ env.FILENAME }}",
ref: "${{ env.BRANCH_NAME }}",
});
fileExists = !!data;
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
core.exportVariable('FILE_EXISTS', fileExists);
- name: Create or update file
uses: actions/github-script@v5
with:
github-token: ${{ secrets.COMMIT_TOKEN }}
script: |
const fs = require('fs');
const path = require('path');
const filePath = path.join(process.env.GITHUB_WORKSPACE, "${{ env.FILENAME }}");
const fileContent = fs.readFileSync(filePath, 'utf8');
const params = {
owner: context.repo.owner,
repo: context.repo.repo,
path: "${{ env.FILENAME }}",
message: `Update ${{ env.FILENAME }}`,
content: Buffer.from(fileContent).toString('base64'),
branch: "${{ env.BRANCH_NAME }}"
};
if (${{ env.FILE_EXISTS }}) {
const { data } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: "${{ env.FILENAME }}",
ref: "${{ env.BRANCH_NAME }}"
});
params.sha = data.sha;
}
await github.rest.repos.createOrUpdateFileContents(params);
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Coverage Diff

on:
push:
branches:
- master
pull_request: {}

jobs:
test:
name: Coverage Diff
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
cache: yarn
- run: yarn install
- run: yarn run test:coverage
- name: Coverage Diff
uses: greatwizard/coverage-diff-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 9 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,13 @@ typings/

### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

**.node-xmlhttprequest-*
**.node-xmlhttprequest-*

# macOS DS_Store files
.DS_Store

.vscode
aelf.umd.js.LICENSE.txt

dist
3 changes: 3 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
HUSKY_GIT_PARAMS=$1 node scripts/verify-commit-msg.js
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn run pre-commit
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
42 changes: 0 additions & 42 deletions .vscode/launch.json

This file was deleted.

Loading

0 comments on commit 7f6b201

Please sign in to comment.