diff --git a/.github/workflows/ci_react_frontend.yml b/.github/workflows/ci_react_frontend.yml new file mode 100644 index 0000000..b803ae0 --- /dev/null +++ b/.github/workflows/ci_react_frontend.yml @@ -0,0 +1,55 @@ +name: "React frontend CI" + +# events +on: + push: + branches: ["main"] + # paths + paths: + - 'frontend/**' + pull_request: + branches: ["main"] + # paths + paths: + - 'frontend/**' + +env: + node_version: 16.x +defaults: + run: + working-directory: ./frontend + +jobs: + build: #first job + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4.1.7 # action + + - name: Use Node.js ${{ env.node_version }} + uses: actions/setup-node@v4.0.3 + with: + node-version: ${{ env.node_version }} + cache: 'npm' + cache-dependency-path: './frontend/package-lock.json' + + - name: Run npm clean install + run: npm ci + + - run: npm run build --if-present + + test: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4.1.7 + + - name: Use Node.js ${{ env.node_version }} + uses: actions/setup-node@v4.0.3 + with: + node-version: ${{ env.node_version }} + cache: 'npm' + cache-dependency-path: './frontend/package-lock.json' + - name: "Run test on frontend" + run: npm ci + - run: npm test \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 2df742f..e06d41a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,7 +21,7 @@ "scripts": { "start": "PORT=8080 react-scripts start", "build": "react-scripts build", - "test": "react-scripts test", + "test": "react-scripts test --watchAll=false --coverage", "eject": "react-scripts eject" }, "eslintConfig": { @@ -41,5 +41,19 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "jest": { + "collectCoverageFrom": [ + "src/**/*.tsx" + ], + "coverageThreshold": { + "global": { + "lines": 85 + } + }, + "coverageReporters": [ + "html", + "text" + ] } }