From de976ef57c1b9e26e4ff46bcbb498f1472f57d1b Mon Sep 17 00:00:00 2001 From: singhAmandeep007 Date: Mon, 25 Nov 2024 09:04:55 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20=F0=9F=8E=89=20Add=20GitHub?= =?UTF-8?q?=20Actions=20workflow=20for=20running=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 61 ++++++++++++++++++++++++++++++++++++++ package.json | 9 +++--- 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c7e506a --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/package.json b/package.json index 59f3642..b87babd 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",