Skip to content

Commit

Permalink
Add unit testing (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tolauwae authored Dec 6, 2024
1 parent 2fc1655 commit e88476b
Show file tree
Hide file tree
Showing 15 changed files with 3,125 additions and 569 deletions.
11 changes: 11 additions & 0 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"reporter": [
"json",
"text-summary"
],
"extension": [
".ts"
],
"sourceMap": true,
"exclude-after-remap": true
}
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Tests
on: [ push ]

jobs:
unit:
name: Unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4

- run: npm i

- name: Prebuild files
run: npm run test:prebuild

- name: Run ava unit tests
run: npm run test:ava

coverage:
name: Code coverage
runs-on: ubuntu-latest
strategy:
fail-fast: true
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4

- run: npm i

- name: Prebuild files
run: npm run test:prebuild

- name: Run c8 coverage
run: |
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
- name: Update coverage badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 615b7906cd71effb447c4b08673d2cb6
filename: latch-coverage.json
label: Coverage
message: ${{ env.LINE_COVERAGE }}
valColorRange: ${{ env.LINE_COVERAGE }}
maxColorRange: 100
minColorRange: 0

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ lib/*.js
test/*.js
*.map

# Project specific
WABT
core/

dist/

# IDE folders
.idea

# built ava test files
out

# c8 Coverage
coverage
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</p>

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

<b>
<a href="https://topllab.github.io/WARDuino/guide/latch.html">Documentation</a>
Expand All @@ -22,7 +24,7 @@ git clone [email protected]:TOPLLab/latch.git
cd latch
npm install
npm run build
npm run test
npm run tests
```

## About
Expand Down
Loading

0 comments on commit e88476b

Please sign in to comment.