Skip to content

Commit 2c3a71f

Browse files
run unit testing using Github Action
1 parent 2466937 commit 2c3a71f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.github/workflows/unit-test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Unit Tests
2+
on:
3+
push:
4+
paths:
5+
- 'src/**'
6+
- '!**.md'
7+
env:
8+
NPM_REGISTRY_URL: npm.pkg.github.com
9+
NPM_TOKEN: ${{ secrets.NODE_PACKAGE_REGISTRY_READ_TOKEN }}
10+
11+
jobs:
12+
run-tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: "actions/checkout@v4"
16+
- uses: "actions/setup-node@v4"
17+
with:
18+
node-version: "20"
19+
- name: run tests
20+
run: |
21+
SRCS_HAVE_TEST_FOLDER="$(find src -type d -regex 'src/[^/]*/test')"
22+
if [[ -z SRCS_HAVE_TEST_FOLDER ]]; then
23+
echo "no test folder detected in the src folder."
24+
exit 0
25+
fi
26+
for SRC_HAS_TEST_FOLDER in $SRCS_HAVE_TEST_FOLDER
27+
do
28+
pushd "${SRC_HAS_TEST_FOLDER%/test}"
29+
if jq '.scripts | has("test")' package.json; then
30+
npm clean-install
31+
npm run test
32+
popd
33+
fi
34+
done

0 commit comments

Comments
 (0)