Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/github-actions-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
Expand Down Expand Up @@ -44,4 +45,4 @@ jobs:
# with:
# coverageLocations: |
# ${{github.workspace}}/client/coverage/lcov.info:lcov
# ${{github.workspace}}/server/coverage/lcov.info:lcov
# ${{github.workspace}}/server/coverage/lcov.info:lcov
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
backend/node_modules
backend/coverage
backend/dist
frontend/node_modules
frontend/coverage
client/node_modules
client/coverage
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# ci-cd-example
[![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
49 changes: 49 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,54 @@
"pg": "^8.12.0",
"redis": "^4.6.15",
"supertest": "^7.0.0"
},
"jest": {
"testTimeout": 30000,
"roots": [
"<rootDir>"
],
"modulePaths": [
"<rootDir>/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"
]
}
}
37 changes: 36 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
]
}
}
17 changes: 16 additions & 1 deletion client/src/tests/app.test.js
Original file line number Diff line number Diff line change
@@ -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(<App />);
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(<App />);
await waitFor(() => {
const product1 = screen.getByText('Product 1');
expect(product1).toBeInTheDocument();
});
});