Skip to content

Commit afb73df

Browse files
committed
Add comprehensive testing guidelines for the project
- Create TESTING_GUIDELINES.md with detailed testing strategy - Define testing framework selection (Jest, React Testing Library) - Outline proposed directory structure for tests - Specify test types: unit, snapshot, integration, accessibility - Include example test and CI/CD integration considerations - Provide future publishing and testing requirements
1 parent 0832f95 commit afb73df

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

TESTING_GUIDELINES.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## Test Guideline for the Project
2+
3+
This document outlines the intended structure and best practices for testing in this project.
4+
These guidelines describe the target state for testing implementations.
5+
Future adjustments may be made based on project developments and recommendations provided by coworkers like Cursor AI.
6+
7+
Initiallly created with ChatGPT Canvas <https://chatgpt.com/canvas/shared/67c03719cadc8191bf72e015944a81e1>
8+
9+
### 1. **Testing Framework Selection**
10+
11+
- **Jest**: A widely used testing framework for JavaScript/React applications.
12+
- **React Testing Library**: Preferred for testing React components to ensure a user-centric approach.
13+
- **Vitest**: Considered for future adoption due to its speed and compatibility with Vite and TypeScript.
14+
15+
#### Transition Considerations
16+
17+
- Initially, Jest is expected to be used due to its deep integration with Create React App (CRA).
18+
- As the project moves towards Vite and TypeScript, Vitest may replace Jest to take advantage of its performance benefits and native support.
19+
20+
### 2. **Planned Directory Structure for Tests**
21+
22+
To maintain a clean separation between source code and tests, the following directory structure is proposed:
23+
24+
```
25+
project-root/
26+
├── src/
27+
│ ├── components/
28+
│ │ ├── ImageWithContent/
29+
│ │ │ ├── ImageWithContent.js
30+
│ │ │ ├── ImageWithContent.scss
31+
│ │ │ ├── index.js
32+
│ │ │ ├── README.md
33+
│ │ ├── LinkCard/
34+
│ │ │ ├── ...
35+
│ │ ├── ResponsiveImage/
36+
│ │ │ ├── ...
37+
│ ├── tests/
38+
│ │ ├── unit/
39+
│ │ │ ├── ImageWithContent.test.js
40+
│ │ ├── snapshot/
41+
│ │ │ ├── ImageWithContent.snapshot.test.js
42+
│ │ ├── integration/
43+
│ │ │ ├── ImageWithContent.integration.test.js
44+
│ │ ├── accessibility/
45+
│ │ │ ├── ImageWithContent.a11y.test.js
46+
├── package.json
47+
├── jest.config.js (if using Jest)
48+
├── vitest.config.ts (if using Vitest in the future)
49+
├── babel.config.js
50+
├── tsconfig.json (if using TypeScript)
51+
└── README.md
52+
```
53+
54+
### 3. **Planned Test Organization**
55+
56+
- All test types will be placed in a `tests/` directory to avoid cluttering source files.
57+
- Separate subdirectories will be created for different test types, ensuring clarity and maintainability.
58+
59+
### 4. **Types of Tests to Implement**
60+
61+
- **Unit Tests**: Verify the smallest functional parts of the application.
62+
- **Snapshot Tests**: Ensure the rendered output remains consistent over time.
63+
- **Integration Tests**: Confirm components work correctly with dependencies and external APIs.
64+
- **Accessibility Tests**: Use `jest-axe` to enforce accessibility best practices.
65+
66+
### 5. **Example Unit Test (Target Implementation)**
67+
68+
```tsx
69+
import { render, screen } from "@testing-library/react";
70+
import ImageWithContent from "../../src/components/ImageWithContent";
71+
72+
test("renders correctly", () => {
73+
render(<ImageWithContent title="Hello" />);
74+
expect(screen.getByText("Hello")).toBeInTheDocument();
75+
});
76+
```
77+
78+
### 6. **Mocking External Dependencies**
79+
80+
- `jest.fn()` will be used for simple mocks.
81+
- `msw` (Mock Service Worker) will be considered for API interactions.
82+
83+
### 7. **Planned CI/CD Integration**
84+
85+
To ensure code quality, tests will be executed automatically in CI/CD pipelines:
86+
87+
- GitHub Actions (or another CI tool) will run tests on push and pull requests.
88+
- A test script in `package.json` will facilitate local execution:
89+
90+
```json
91+
"scripts": {
92+
"test": "jest --coverage"
93+
}
94+
```
95+
96+
### 8. **Future Publishing Considerations**
97+
98+
Before publishing to npm or deploying, the following test requirements should be met:
99+
100+
- All tests must pass (`npm test` or `yarn test`).
101+
- A `prepublishOnly` hook in `package.json` will enforce test execution before publishing:
102+
103+
```json
104+
"prepublishOnly": "npm test"
105+
```
106+
107+
- TypeScript adoption will be ensured to improve maintainability and reliability.
108+
109+
By following this guideline, testing in the project will remain well-structured, scalable, and adaptable to future technology choices.
110+
111+
Adjustments to these guidelines may be made as the project evolves, and recommendations from Cursor AI will be considered for further improvements.

0 commit comments

Comments
 (0)