Skip to content

Commit c84b5aa

Browse files
committed
feat: automatically run unit tests on new PRs (#27)
1 parent e3c668f commit c84b5aa

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

.github/workflows/unit-tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Run Tests and Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test-and-coverage:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Checkout the code
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
# Set up Node.js
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
cache: 'npm'
24+
25+
# Install dependencies
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
# Run tests with coverage
30+
- name: Run Jest tests with coverage
31+
run: |
32+
npm run test:coverage -- --collectCoverageFrom="./src/**" --coverageReporters=text --coverageReporters=json-summary | tee ./coverage.txt && exit ${PIPESTATUS[0]}
33+
34+
- name: Jest Coverage Comment
35+
uses: MishaKav/jest-coverage-comment@v1
36+
with:
37+
coverage-summary-path: ./coverage/coverage-summary.json
38+
coverage-title: Coverage
39+
coverage-path: ./coverage.txt

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
'!./src/types/**',
99
'!./src/**/*.snap',
1010
],
11-
coverageReporters: ['json', 'html', 'text-summary'],
11+
coverageReporters: ['json-summary', 'html', 'text-summary'],
1212
setupFilesAfterEnv: ['./src/tests/jest.setup.ts', './src/tests/test-utils.tsx'],
1313
moduleNameMapper: {
1414
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':

package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"react-native-web": "~0.19.13",
6464
"react-redux": "^9.1.2",
6565
"redux-persist": "^6.0.0",
66-
"tamagui": "^1.116.14"
66+
"tamagui": "^1.116.14",
67+
"timezone-mock": "^1.3.6"
6768
},
6869
"devDependencies": {
6970
"@babel/core": "^7.25.2",

src/utils/date.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import timezoneMock from 'timezone-mock'
12
import { currentMinutes, formatDateTime, formatTime, getCountdown, getPeriod } from './date'
23

34
const MOCKED_TIMESTAMP = 1729506116962
45

56
describe('Date utils', () => {
67
beforeAll(() => {
8+
timezoneMock.register('Etc/GMT-2')
79
jest.spyOn(Date, 'now').mockImplementation(() => MOCKED_TIMESTAMP)
810
})
911

0 commit comments

Comments
 (0)