Skip to content

Commit 9c6167b

Browse files
committedNov 29, 2024
run tests with coverage
1 parent d72ea5b commit 9c6167b

File tree

4 files changed

+321
-18
lines changed

4 files changed

+321
-18
lines changed
 

‎.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ jobs:
3434
echo "NODE_ENV=test" >> packages/core/.env.test
3535
3636
- name: Run tests
37-
run: cd packages/core && pnpm test
37+
run: cd packages/core && pnpm test:coverage
3838

3939
- name: Build packages
4040
run: pnpm run build
4141

4242
- name: Upload coverage reports to Codecov
4343
uses: codecov/codecov-action@v5
4444
with:
45-
token: ${{ secrets.CODECOV_TOKEN }}
45+
token: ${{ secrets.CODECOV_TOKEN }}

‎packages/core/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dev": "tsup --format esm --dts --watch",
1313
"build:docs": "cd docs && pnpm run build",
1414
"test": "vitest run",
15+
"test:coverage": "vitest run --coverage",
1516
"test:watch": "vitest"
1617
},
1718
"author": "",
@@ -34,6 +35,7 @@
3435
"@types/wav-encoder": "1.3.3",
3536
"@typescript-eslint/eslint-plugin": "8.12.2",
3637
"@typescript-eslint/parser": "8.12.2",
38+
"@vitest/coverage-v8": "2.1.5",
3739
"dotenv": "16.4.5",
3840
"eslint": "9.13.0",
3941
"eslint-config-prettier": "9.1.0",

‎pnpm-lock.yaml

+306-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/test.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ for package in "${PACKAGES[@]}"; do
3434
cd "$package_path" || continue
3535

3636
if [ -f "package.json" ]; then
37-
# Run tests if available
38-
if npm run | grep -q " test"; then
37+
# Run tests with coverage if TEST_COVERAGE is set and test:coverage script exists
38+
if [[ -n "$TEST_COVERAGE" ]] && npm run | grep -q " test:coverage"; then
39+
echo -e "\033[1mRunning coverage tests for package: $package\033[0m"
40+
if npm run test:coverage; then
41+
echo -e "\033[1;32mSuccessfully tested $package with coverage\033[0m\n"
42+
else
43+
echo -e "\033[1;31mCoverage tests failed for $package\033[0m"
44+
fi
45+
# Otherwise, run regular tests if available
46+
elif npm run | grep -q " test"; then
3947
echo -e "\033[1mRunning tests for package: $package\033[0m"
4048
if npm run test; then
4149
echo -e "\033[1;32mSuccessfully tested $package\033[0m\n"
@@ -52,4 +60,4 @@ for package in "${PACKAGES[@]}"; do
5260
cd - > /dev/null || exit
5361
done
5462

55-
echo -e "\033[1mTest process completed.😎\033[0m"
63+
echo -e "\033[1mTest process completed.😎\033[0m"

0 commit comments

Comments
 (0)
Please sign in to comment.