Skip to content

Commit e88476b

Browse files
authored
Add unit testing (#28)
* Init ava unit testing * πŸ‘· Run unit tests in CI * Add CI status badge to README * Add c8 code coverage * Fix prebuilding of test files * Fix c8 coverage and cleanup config * πŸ‘· Add coverage to CI
1 parent 2fc1655 commit e88476b

15 files changed

Lines changed: 3125 additions & 569 deletions

β€Ž.c8rcβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"reporter": [
3+
"json",
4+
"text-summary"
5+
],
6+
"extension": [
7+
".ts"
8+
],
9+
"sourceMap": true,
10+
"exclude-after-remap": true
11+
}

β€Ž.github/workflows/test.ymlβ€Ž

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
on: [ push ]
3+
4+
jobs:
5+
unit:
6+
name: Unit tests
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
if: github.event.pull_request.draft == false
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- run: npm i
15+
16+
- name: Prebuild files
17+
run: npm run test:prebuild
18+
19+
- name: Run ava unit tests
20+
run: npm run test:ava
21+
22+
coverage:
23+
name: Code coverage
24+
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: true
27+
if: github.event.pull_request.draft == false
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- run: npm i
32+
33+
- name: Prebuild files
34+
run: npm run test:prebuild
35+
36+
- name: Run c8 coverage
37+
run: |
38+
echo "LINE_COVERAGE=$(npm run coverage:test:ava | grep -E '^\s*Lines\s*:\s*[0-9]+(\.[0-9]+)?%' | awk '{print $3}' | tr -d '%')" >> $GITHUB_ENV
39+
40+
- name: Update coverage badge
41+
uses: schneegans/dynamic-badges-action@v1.7.0
42+
with:
43+
auth: ${{ secrets.GIST_SECRET }}
44+
gistID: 615b7906cd71effb447c4b08673d2cb6
45+
filename: latch-coverage.json
46+
label: Coverage
47+
message: ${{ env.LINE_COVERAGE }}
48+
valColorRange: ${{ env.LINE_COVERAGE }}
49+
maxColorRange: 100
50+
minColorRange: 0
51+

β€Ž.gitignoreβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ lib/*.js
3939
test/*.js
4040
*.map
4141

42+
# Project specific
4243
WABT
4344
core/
4445

4546
dist/
4647

48+
# IDE folders
4749
.idea
50+
51+
# built ava test files
52+
out
53+
54+
# c8 Coverage
55+
coverage

β€ŽREADME.mdβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
</p>
77

88
<a href="https://doi.org/10.1016/j.scico.2024.103157"><img src="https://img.shields.io/badge/DOI-10.1016%2Fj.scico.2024.103157-blue.svg"></a>
9+
<a href="https://github.com/TOPLLab/latch/actions/workflows/test.yml"><img src="https://github.com/TOPLLab/latch/actions/workflows/test.yml/badge.svg"></a>
10+
<a href="https://github.com/TOPLLab/latch/actions/workflows/test.yml"><img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/tolauwae/615b7906cd71effb447c4b08673d2cb6/raw/latch-coverage.json"></a>
911

1012
<b>
1113
<a href="https://topllab.github.io/WARDuino/guide/latch.html">Documentation</a>
@@ -22,7 +24,7 @@ git clone git@github.com:TOPLLab/latch.git
2224
cd latch
2325
npm install
2426
npm run build
25-
npm run test
27+
npm run tests
2628
```
2729

2830
## About

0 commit comments

Comments
Β (0)