diff --git a/.github/workflows/github-actions-workflow.yml b/.github/workflows/github-actions-workflow.yml index 6080484..6d9b1b6 100644 --- a/.github/workflows/github-actions-workflow.yml +++ b/.github/workflows/github-actions-workflow.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - main + workflow_dispatch: jobs: test: @@ -44,4 +45,4 @@ jobs: # with: # coverageLocations: | # ${{github.workspace}}/client/coverage/lcov.info:lcov - # ${{github.workspace}}/server/coverage/lcov.info:lcov \ No newline at end of file + # ${{github.workspace}}/server/coverage/lcov.info:lcov diff --git a/.gitignore b/.gitignore index 594065b..d6e7508 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ backend/node_modules backend/coverage backend/dist -frontend/node_modules -frontend/coverage +client/node_modules +client/coverage diff --git a/README.md b/README.md index 6ea3e5c..9c01321 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# ci-cd-example \ No newline at end of file +[![Maintainability](https://api.codeclimate.com/v1/badges/d58a218b1149d0351e34/maintainability)](https://codeclimate.com/github/shang8024/ci-cd-example/maintainability) +[![Test Coverage](https://api.codeclimate.com/v1/badges/d58a218b1149d0351e34/test_coverage)](https://codeclimate.com/github/shang8024/ci-cd-example/test_coverage) +# ci-cd-example diff --git a/backend/package.json b/backend/package.json index 18aeb70..c77dca3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,5 +19,54 @@ "pg": "^8.12.0", "redis": "^4.6.15", "supertest": "^7.0.0" + }, + "jest": { + "testTimeout": 30000, + "roots": [ + "" + ], + "modulePaths": [ + "/routes" + ], + "moduleDirectories": [ + "node_modules", + "routes" + ], + "testEnvironment": "node", + "moduleFileExtensions": [ + "js", + "json", + "jsx", + "ts", + "tsx" + ], + "collectCoverageFrom": [ + "**/routes/**/*.js", + "!**/node_modules/**", + "**/config/*.js", + "**/marketing_system/**/*.js", + "**/models/*.js" + ], + "coverageReporters": [ + [ + "lcov", + { + "projectRoot": ".." + } + ], + [ + "text", + { + "skipFull": true + } + ], + "text-summary" + ] + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] } } diff --git a/client/package.json b/client/package.json index 49d967c..a7f8934 100644 --- a/client/package.json +++ b/client/package.json @@ -15,7 +15,7 @@ "scripts": { "start": "cross-env REACT_APP_BACKEND=localhost react-scripts start", "build": "react-scripts build", - "test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!axios)/\"", + "test": "react-scripts test --coverage --watchAll=false --transformIgnorePatterns \"node_modules/(?!axios)/\"", "eject": "react-scripts eject", "tutorial": "npm install && npm start", "docker": "cross-env REACT_APP_BACKEND=localhost react-scripts start" @@ -41,5 +41,40 @@ "devDependencies": { "cross-env": "^7.0.3", "tailwindcss": "^3.4.4" + }, + "jest": { + "transformIgnorePatterns": [ + "node_modules/(?!axios)" + ], + "collectCoverageFrom": [ + "src/**/*.js", + "!**/node_modules/**", + "!src/index.js", + "!src/reportWebVitals.js", + "!src/setupTests.js", + "!src/hooks/**", + "!src/context/**" + ], + "coverageReporters": [ + [ + "lcov", + { + "projectRoot": ".." + } + ], + [ + "text", + { + "skipFull": true + } + ], + "text-summary" + ] + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] } } diff --git a/client/src/tests/app.test.js b/client/src/tests/app.test.js index fae7851..1a7adf3 100644 --- a/client/src/tests/app.test.js +++ b/client/src/tests/app.test.js @@ -1,9 +1,24 @@ import React from 'react'; import App from '../App'; -import { render,screen } from '@testing-library/react'; +import { render,screen, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; test('loads and displays titles', () => { render(); expect(screen.getByText(/Docker tutorial/i)).toBeInTheDocument(); }); + +test('render product list', async () => { + globalThis.fetch = jest.fn(() => + Promise.resolve({ + json: () => Promise.resolve({data:[ + {name: 'Product 1', description: 'Description 1', price: 100}, + ]}), + }) + ); + render(); + await waitFor(() => { + const product1 = screen.getByText('Product 1'); + expect(product1).toBeInTheDocument(); + }); +}); \ No newline at end of file