Skip to content

Commit 294d01a

Browse files
authored
Creating workflow for running tests.
1 parent f0d652a commit 294d01a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Run Jest Tests on PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
jobs:
10+
test:
11+
name: Run Jest Tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
23+
- name: Install Dependencies
24+
run: npm install
25+
26+
- name: Run Jest Tests
27+
id: jest
28+
run: |
29+
npm test -- --json --outputFile=jest-results.json || echo "TESTS_FAILED=true" >> $GITHUB_ENV
30+
31+
- name: Read Jest Results
32+
id: results
33+
run: |
34+
if [ "$TESTS_FAILED" = "true" ]; then
35+
echo "TESTS_PASSED=false" >> $GITHUB_ENV
36+
echo "FAILED_TESTS<<EOF" >> $GITHUB_ENV
37+
jq -c '[.testResults[] | select(.status == "failed") | {name: .name}]' jest-results.json >> $GITHUB_ENV
38+
echo "EOF" >> $GITHUB_ENV
39+
else
40+
echo "TESTS_PASSED=true" >> $GITHUB_ENV
41+
echo "FAILED_TESTS=[]" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Post Comment on PR
45+
uses: mshick/add-pr-comment@v2
46+
with:
47+
message: |
48+
${{ env.TESTS_PASSED == 'true' && '✅ All Jest tests passed! This PR is ready to merge.' || '❌ Some Jest tests failed. Please check the logs and fix the issues before merging.' }}
49+
50+
**Failed Tests:**
51+
```json
52+
${{ env.FAILED_TESTS }}
53+
```
54+
repo-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)