Skip to content

Commit

Permalink
feat: ✨ πŸŽ‰ Add GitHub Actions workflow for running unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
singhAmandeep007 committed Nov 25, 2024
1 parent 7da05a5 commit de976ef
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# GitHub Actions
# https://docs.github.com/en/actions/using-workflows
name: Run Unit Tests
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
test:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Cache dependencies
uses: actions/cache@v4
# give it a name for checking the cache hit-or-not
id: cache-dependencies
with:
path: |
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: npm ci

- name: Run Tests
run: npm run test:unit:coverage
env:
CI: true

- name: Unit test report status
if: always()
uses: actions/github-script@v6
with:
script: |
const { job, conclusion } = context.payload;
const status = conclusion === 'success' ? 'βœ…' : '❌';
const message = `Tests ${conclusion} ${status}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
- name: Upload coverage report
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: reports/unit/coverage
retention-days: 5
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@
"build:msw": "msw init ./build --no-save",
"analyze": "source-map-explorer 'build/static/js/*.js'",
"TEST": "------------------------------------------------------------------------",
"test": "env-cmd -f ./.testing.env npm run test:unit",
"test:unit": "npm run tsc:check && node scripts/test.js --watchAll=false",
"test:unit:coverage": "npm run test:unit -- --coverage",
"test:start": "node scripts/test.js --watchAll=false",
"test:unit": "env-cmd -f ./.testing.env run-s tsc:check:src \"test:start -- {@}\" --",
"test:unit:coverage": "run-s \"test:unit -- --coverage\"",
"LINT": "------------------------------------------------------------------------",
"lint": "run-s format:write lint:check:script format:check tsc:check",
"lint:check:script": "eslint --config ./.eslintrc.js \"{src,cypress,playwright}/**/*.{js,jsx,ts,tsx}\" --report-unused-disable-directives --max-warnings 0",

"format:check": "prettier --check \"{src,cypress,playwright}/**/*.{js,jsx,ts,tsx,css,scss,html,md,json}\"",
"format:write": "prettier --write \"{src,cypress,playwright}/**/*.{js,jsx,ts,tsx,css,scss,html,md,json}\"",
"tsc:check": "run-s tsc:check:src tsc:check:cypress",
Expand All @@ -78,7 +77,7 @@
"commit:pre": "lint-staged",
"commit:init": "git-cz",
"commit:devmoji": "devmoji -e --lint",
"prepare": "husky || true",
"prepare": "husky",
"DEPLOY": "------------------------------------------------------------------------",
"deploy": "run-s deploy:build deploy:gh-pages",
"deploy:build": "env-cmd -f ./.production.env npm run build",
Expand Down

0 comments on commit de976ef

Please sign in to comment.