From 6926642f49e1100c0040c76344e6721779897280 Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:22:19 -0400 Subject: [PATCH 01/10] Update github-actions-workflow.yml --- .github/workflows/github-actions-workflow.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/github-actions-workflow.yml b/.github/workflows/github-actions-workflow.yml index 6080484..180879d 100644 --- a/.github/workflows/github-actions-workflow.yml +++ b/.github/workflows/github-actions-workflow.yml @@ -37,11 +37,11 @@ jobs: npm install npm test - # - name: Publish code coverage - # uses: paambaati/codeclimate-action@v3.2.0 - # env: - # CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} - # with: - # coverageLocations: | - # ${{github.workspace}}/client/coverage/lcov.info:lcov - # ${{github.workspace}}/server/coverage/lcov.info:lcov \ No newline at end of file + - name: Publish code coverage + uses: paambaati/codeclimate-action@v3.2.0 + env: + CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} + with: + coverageLocations: | + ${{github.workspace}}/client/coverage/lcov.info:lcov + ${{github.workspace}}/server/coverage/lcov.info:lcov From e08f3b31f34e237ded5eaba7478f794644b5c3ba Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:23:32 -0400 Subject: [PATCH 02/10] Update github-actions-workflow.yml --- .github/workflows/github-actions-workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/github-actions-workflow.yml b/.github/workflows/github-actions-workflow.yml index 180879d..c731b48 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: From 0981c03553e9b9e82e5c14dc1ee2cd8de6039a7f Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:37:20 -0400 Subject: [PATCH 03/10] Update package.json --- client/package.json | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/client/package.json b/client/package.json index 49d967c..9a28616 100644 --- a/client/package.json +++ b/client/package.json @@ -41,5 +41,54 @@ "devDependencies": { "cross-env": "^7.0.3", "tailwindcss": "^3.4.4" + }, + "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" + ] } } From 94e22565e8692da9f218483bbf03abbbb8323868 Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:37:49 -0400 Subject: [PATCH 04/10] Update package.json --- backend/package.json | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/backend/package.json b/backend/package.json index 18aeb70..36487d5 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,5 +19,55 @@ "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" + ] } } +} From b41609a47af954cfb3568772c10330347f8ed79a Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:37:58 -0400 Subject: [PATCH 05/10] Update package.json --- backend/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 36487d5..c77dca3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -70,4 +70,3 @@ ] } } -} From 1a41f604f5ea6ecca16d65c8f64d9637167047ce Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:38:35 -0400 Subject: [PATCH 06/10] Update package.json --- client/package.json | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/client/package.json b/client/package.json index 9a28616..021105d 100644 --- a/client/package.json +++ b/client/package.json @@ -43,31 +43,17 @@ "tailwindcss": "^3.4.4" }, "jest": { - "testTimeout": 30000, - "roots": [ - "" - ], - "modulePaths": [ - "/routes" - ], - "moduleDirectories": [ - "node_modules", - "routes" - ], - "testEnvironment": "node", - "moduleFileExtensions": [ - "js", - "json", - "jsx", - "ts", - "tsx" + "transformIgnorePatterns": [ + "node_modules/(?!axios)" ], "collectCoverageFrom": [ - "**/routes/**/*.js", + "src/**/*.js", "!**/node_modules/**", - "**/config/*.js", - "**/marketing_system/**/*.js", - "**/models/*.js" + "!src/index.js", + "!src/reportWebVitals.js", + "!src/setupTests.js", + "!src/hooks/**", + "!src/context/**" ], "coverageReporters": [ [ From 9fef366192e3576b08600ba8d6806de9c2057511 Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:42:37 -0400 Subject: [PATCH 07/10] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From a293bbb49cddf2a2c03933a193a0fe1c9614e4b5 Mon Sep 17 00:00:00 2001 From: Jiale Shang Date: Tue, 23 Jul 2024 13:44:19 -0400 Subject: [PATCH 08/10] Update package.json --- client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 021105d..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" From 6ef933253f79bf9ec4fa6fb5243c7e76cb89977e Mon Sep 17 00:00:00 2001 From: shang8024 Date: Tue, 23 Jul 2024 16:36:40 -0400 Subject: [PATCH 09/10] update frontend test case --- .gitignore | 4 ++-- client/src/tests/app.test.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) 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/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 From b8cc6864d061a7471979ad3dff1c68aba3ca107a Mon Sep 17 00:00:00 2001 From: shang8024 Date: Tue, 23 Jul 2024 16:38:33 -0400 Subject: [PATCH 10/10] Update github-actions-workflow.yml --- .github/workflows/github-actions-workflow.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/github-actions-workflow.yml b/.github/workflows/github-actions-workflow.yml index c731b48..6d9b1b6 100644 --- a/.github/workflows/github-actions-workflow.yml +++ b/.github/workflows/github-actions-workflow.yml @@ -38,11 +38,11 @@ jobs: npm install npm test - - name: Publish code coverage - uses: paambaati/codeclimate-action@v3.2.0 - env: - CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} - with: - coverageLocations: | - ${{github.workspace}}/client/coverage/lcov.info:lcov - ${{github.workspace}}/server/coverage/lcov.info:lcov + # - name: Publish code coverage + # uses: paambaati/codeclimate-action@v3.2.0 + # env: + # CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} + # with: + # coverageLocations: | + # ${{github.workspace}}/client/coverage/lcov.info:lcov + # ${{github.workspace}}/server/coverage/lcov.info:lcov