Skip to content

Commit 91f4ee8

Browse files
authored
Additional unit tests and coverage. (#661)
1 parent 2bfa96f commit 91f4ee8

35 files changed

+8285
-1057
lines changed

.github/actions/e2e-shared/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: "Shell to use"
1212
required: true
1313
default: "bash"
14+
mina-branch:
15+
description: "Mina repository branch in use"
16+
required: true
17+
default: "master"
1418
test-script:
1519
description: "Test script to run"
1620
required: false
@@ -51,7 +55,7 @@ runs:
5155
if: always()
5256
with:
5357
if-no-files-found: ignore
54-
name: mina-logs-${{ inputs.artifacts-prefix }}-node${{ inputs.node-version }}-${{ inputs.os-type }}
58+
name: mina-logs-${{ inputs.artifacts-prefix }}-${{ inputs.mina-branch }}-node${{ inputs.node-version }}-${{ inputs.os-type }}
5559
path: /tmp/*.log
5660
retention-days: 5
5761
- name: Upload E2E test artifacts
@@ -60,6 +64,6 @@ runs:
6064
if: always()
6165
with:
6266
if-no-files-found: ignore
63-
name: ${{ inputs.artifacts-prefix }}-report-node${{ inputs.node-version }}-${{ inputs.os-type }}
67+
name: ${{ inputs.artifacts-prefix }}-${{ inputs.mina-branch }}-report-node${{ inputs.node-version }}-${{ inputs.os-type }}
6468
path: reports/html-report/
6569
retention-days: 30

.github/workflows/nightly-e2e-ci-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
node-version: ${{ matrix.node }}
4646
os-type: ${{ matrix.os }}
4747
shell: bash
48+
mina-branch: 'compatible'
4849
against-master-real-network-on-linux:
4950
timeout-minutes: 185
5051
runs-on: ${{ matrix.os }}
@@ -81,6 +82,7 @@ jobs:
8182
node-version: ${{ matrix.node }}
8283
os-type: ${{ matrix.os }}
8384
shell: bash
85+
mina-branch: 'master'
8486
against-mocked-network-on-macos:
8587
timeout-minutes: 185
8688
runs-on: ${{ matrix.os }}
@@ -97,6 +99,7 @@ jobs:
9799
node-version: ${{ matrix.node }}
98100
os-type: ${{ matrix.os }}
99101
shell: bash
102+
mina-branch: 'mocked-macos'
100103
against-mocked-network-on-windows:
101104
timeout-minutes: 185
102105
runs-on: ${{ matrix.os }}
@@ -113,3 +116,4 @@ jobs:
113116
node-version: ${{ matrix.node }}
114117
os-type: ${{ matrix.os }}
115118
shell: powershell
119+
mina-branch: 'mocked-windows'

.github/workflows/publish.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# This workflow will publish the package to NPM when the following conditions are met:
3+
# - The workflow run was triggered by the successful completion of the 'Smoke E2E tests' workflow
4+
# - The target branch is 'origin/main'
5+
#
6+
7+
name: Publish to NPM
8+
on:
9+
workflow_run:
10+
workflows: ['Smoke E2E tests']
11+
types: [completed]
12+
jobs:
13+
publish:
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }} && github.ref == 'refs/heads/main'
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node: [20]
19+
steps:
20+
- name: Set up NodeJS
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node }}
24+
- name: Git checkout
25+
uses: actions/checkout@v4
26+
- name: NPM ci & build
27+
run: |
28+
npm ci
29+
npm run build --if-present
30+
- name: Publish to NPM if version has changed
31+
uses: JS-DevTools/npm-publish@v3
32+
with:
33+
token: ${{ secrets.NPM_TOKEN }}
34+
strategy: upgrade
35+
env:
36+
INPUT_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# Purpose:
23
# Automatically bumps the project's patch version bi-weekly on Tuesdays.
34
#
@@ -7,8 +8,9 @@
78
# - Bumps patch version using `npm version patch`, then creates a new branch 'release/x.x.x'.
89
# - Pushes changes and creates a PR to `main` using GitHub CLI.
910
# - Can also be triggered manually via `workflow_dispatch`.
10-
name: Version Bump
11+
#
1112

13+
name: Version Bump
1214
on:
1315
workflow_dispatch: # Allow to manually trigger the workflow
1416
schedule:

.github/workflows/smoke-e2e-ci-tests.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
#
2+
# This workflow will run the 'Smoke E2E tests' only when the 'Unit tests' workflow completes successfully.
3+
#
4+
15
name: Smoke E2E tests
26
on:
3-
push:
4-
pull_request:
7+
workflow_run:
8+
workflows: ['Unit tests']
9+
types: [completed]
510
workflow_dispatch: {}
611
jobs:
712
against-compatible-real-network-on-linux:
13+
if: ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch' }}
814
timeout-minutes: 30
915
runs-on: ${{ matrix.os }}
1016
strategy:
@@ -40,9 +46,11 @@ jobs:
4046
node-version: ${{ matrix.node }}
4147
os-type: ${{ matrix.os }}
4248
shell: bash
49+
mina-branch: 'compatible'
4350
test-script: 'npm run e2e:test:smoke'
4451
artifacts-prefix: 'smoke-e2e-tests'
4552
against-master-real-network-on-linux:
53+
if: ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch' }}
4654
timeout-minutes: 30
4755
runs-on: ${{ matrix.os }}
4856
strategy:
@@ -78,5 +86,6 @@ jobs:
7886
node-version: ${{ matrix.node }}
7987
os-type: ${{ matrix.os }}
8088
shell: bash
89+
mina-branch: 'master'
8190
test-script: 'npm run e2e:test:smoke'
8291
artifacts-prefix: 'smoke-e2e-tests'
Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#
2-
# ci.yml
3-
#
4-
# Run tests for all pushed commits and opened pull requests on Github.
2+
# This workflow will run common unit tests, and then run the Sudoku and TicTacToe examples unit tests if the common unit tests pass.
53
#
64

7-
name: CI
8-
on: [push, pull_request]
5+
name: Unit tests
6+
on:
7+
push: {}
8+
pull_request: {}
9+
workflow_dispatch: {}
910
jobs:
10-
ci:
11+
common:
1112
runs-on: ubuntu-latest
1213
timeout-minutes: 10
1314
strategy:
@@ -24,14 +25,25 @@ jobs:
2425
run: |
2526
npm ci
2627
npm run build --if-present
27-
npm run test
28+
npm run coverage
2829
cd templates/project-ts
2930
npm install || true
3031
npm run test
3132
env:
3233
CI: true
34+
- name: Upload coverage reports to Codecov
35+
uses: codecov/codecov-action@v4
36+
with:
37+
token: ${{ secrets.CODECOV_TOKEN }}
38+
files: ./coverage/lcov.info
39+
flags: unittests
40+
name: zkapp-cli
41+
verbose: true
42+
handle_no_reports_found: true
43+
fail_ci_if_error: false
3344
sudoku-example:
3445
runs-on: ubuntu-latest
46+
needs: [common]
3547
strategy:
3648
matrix:
3749
node: [18]
@@ -42,6 +54,10 @@ jobs:
4254
node-version: ${{ matrix.node }}
4355
- name: Git checkout
4456
uses: actions/checkout@v4
57+
- name: Configure Git
58+
run: |
59+
git config --global user.email "[email protected]"
60+
git config --global user.name "Unit Tests"
4561
- name: NPM ci, build, & test
4662
run: |
4763
npm ci
@@ -56,6 +72,7 @@ jobs:
5672
CI: true
5773
tictactoe-example:
5874
runs-on: ubuntu-latest
75+
needs: [common]
5976
strategy:
6077
matrix:
6178
node: [18]
@@ -66,6 +83,10 @@ jobs:
6683
node-version: ${{ matrix.node }}
6784
- name: Git checkout
6885
uses: actions/checkout@v4
86+
- name: Configure Git
87+
run: |
88+
git config --global user.email "[email protected]"
89+
git config --global user.name "Unit Tests"
6990
- name: NPM ci, build, & test
7091
run: |
7192
npm ci
@@ -78,28 +99,3 @@ jobs:
7899
npm run start
79100
env:
80101
CI: true
81-
publish:
82-
if: github.ref == 'refs/heads/main'
83-
runs-on: ubuntu-latest
84-
# TODO: Add successful e2e smoke testing to preconditions after the https://github.com/o1-labs/zkapp-cli/issues/615 is resolved
85-
needs: [ci, sudoku-example, tictactoe-example]
86-
strategy:
87-
matrix:
88-
node: [18]
89-
steps:
90-
- name: Set up NodeJS
91-
uses: actions/setup-node@v4
92-
with:
93-
node-version: ${{ matrix.node }}
94-
- name: Git checkout
95-
uses: actions/checkout@v4
96-
- name: NPM ci & build
97-
run: |
98-
npm ci
99-
npm run build --if-present
100-
- name: Publish to NPM if version has changed
101-
uses: JS-DevTools/npm-publish@v1
102-
with:
103-
token: ${{ secrets.NPM_TOKEN }}
104-
env:
105-
INPUT_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# zkApp CLI
22

3+
[![codecov](https://codecov.io/gh/o1-labs/zkapp-cli/graph/badge.svg?token=3ZKW76ISDB)](https://codecov.io/gh/o1-labs/zkapp-cli)
4+
35
The zkApp CLI allows you to scaffold, write, test, and deploy zkApps (zero knowledge apps) for [Mina Protocol](https://minaprotocol.com/) using recommended best practices.
46

57
Apps are written using [o1js](https://docs.minaprotocol.com/en/zkapps/o1js-reference), a TypeScript framework for writing zero knowledge proof-based smart contracts. o1js is automatically included when you create a project using the zkApp CLI.

jest.config.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
export default {
2-
testMatch: ['<rootDir>/src/**/*.test.js'],
2+
transform: {},
3+
testMatch: ['**/src/**/*.test.js'],
4+
collectCoverage: true,
5+
coverageDirectory: 'coverage',
6+
coverageReporters: ['json', 'lcov', 'text', 'clover'],
7+
collectCoverageFrom: [
8+
'**/src/lib/**/*.js',
9+
'!**/src/lib/ui/**',
10+
'!**/src/**/*.test.js',
11+
],
12+
coveragePathIgnorePatterns: ['/node_modules/'],
13+
coverageThreshold: {
14+
global: {
15+
branches: 90,
16+
functions: 90,
17+
lines: 90,
18+
statements: 90,
19+
},
20+
},
321
};

0 commit comments

Comments
 (0)