Skip to content

Commit

Permalink
chore: unit-tests github-action yml파일 추가 및 package.json에 관련 스크립트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
inchanS committed Apr 25, 2024
1 parent a60f850 commit 67bf5d4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Unit Tests

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Create ./env/.env.test file
run: |
mkdir -p ./env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> ./env/.env.test
- name: Install dependencies
run: npm install

- name: Build the project
run: npm run build

- name: Run unit tests
run: npm run test:unit-coverage

# The following Steps has been modified based on the following Github-Action.
# https://github.com/marketplace/actions/coverage-badge
- name: Get Values
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
id: get-values
shell: bash
run: |
COV=$(node -p 't=require(`./coverage/coverage-summary.json`).total,Math.min(...`lines|statements|functions|branches`.split(`|`).map(k=>t[k].pct))')
echo "coverage=$COV" >> $GITHUB_OUTPUT
- name: Checkout gh-pages
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
uses: actions/checkout@v3
with:
ref: gh-pages

- name: Create Badges
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
shell: bash
run: |
npm i -g badgen-cli
export COV=${{ steps.get-values.outputs.coverage }}
COLOR=$(node -p '+process.env.COV >= 90 ? `green` : +process.env.COV >= 60 ? `orange` : `red`')
mkdir -p badges
badgen -j "Unit Coverage" -s $COV% -c $COLOR > badges/unitcoverage.svg
- name: Deploy Badges
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Update badges [skip ci]"
branch: gh-pages
skip_fetch: true
skip_checkout: true

- name: Checkout Back
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"inspect": "NODE_ENV=develop concurrently \"npx tsc --watch\" \"node --inspect dist/main.js\"",
"test:integration-coverage": "NODE_ENV=test jest --runInBand --detectOpenHandles --forceExit --coverage --coverageReporters=json-summary --selectProjects integration",
"test:integration": "NODE_ENV=test jest --runInBand --detectOpenHandles --forceExit --selectProjects integration",
"test:unit-coverage": "NODE_ENV=test jest --runInBand --detectOpenHandles --forceExit --coverage --coverageReporters=json-summary --selectProjects unit",
"test:unit": "NODE_ENV=test jest --runInBand --detectOpenHandles --forceExit --selectProjects unit"
},
"repository": {
Expand Down

0 comments on commit 67bf5d4

Please sign in to comment.