source: node_modules/recharts/DEVELOPING.md@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 6.8 KB
Line 
1This is a development guide.
2If you want to know the guidelines we follow then read [CONTRIBUTING.md](CONTRIBUTING.md).
3
4# Setup development environment
5
6```sh
7git clone https://github.com/recharts/recharts.git
8cd recharts
9npm install # the right Node version can be found in .nvmrc file
10```
11
12# Linting and types
13
14You may also want to enable ESLint and Prettier configuration in your favourite IDE.
15
16```sh
17$ npm run lint
18$ npm run check-types
19```
20
21## Import restrictions
22
23The project enforces that all imports from `recharts` must use the public API entry point. Imports from internal paths like `recharts/types/*` or `recharts/src/*` are not allowed and will fail the linter.
24
25**Good:**
26
27```typescript
28import { TooltipIndex, DataKey, BarRectangleItem } from 'recharts';
29```
30
31**Bad:**
32
33```typescript
34import { TooltipIndex } from 'recharts/types/state/tooltipSlice'; // ❌ Will fail lint
35import { DataKey } from 'recharts/src/util/types'; // ❌ Will fail lint
36```
37
38This ensures that consumers of the library only depend on stable, public APIs.
39
40# Automated testing
41
42## Running unit tests
43
44Most unit tests are in the `test` directory, some others are in `www/test`.
45
46Run all tests:
47
48```sh
49$ npm run test
50```
51
52Run a specific test file:
53
54```sh
55$ npm run test -- path/to/TestFile.spec.tsx
56```
57
58## Running mutation tests
59
60Mutation tests may take several hours to complete.
61You may want to first open `./stryker.config.mjs` and set the `mutate` property to a specific file or directory
62that you want to test. That may take 5-10 minutes to run.
63
64Mutation tests do not run in CI.
65
66```sh
67$ npm run test-mutation
68```
69
70## Storybook
71
72To run the Storybook UI:
73
74```sh
75$ npm run storybook
76```
77
78and then browse to http://localhost:6006.
79
80While the storybook is running:
81
82```sh
83$ npm run test-storybook
84```
85
86## Run visual regression tests (using playwright)
87
88### Prerequisites
89
90Playwright tests are running inside Docker. You will need to have Docker installed and running.
91See https://docs.docker.com/get-started/get-docker/. You do not need Docker account or login.
92
93You only need to do this once.
94
95### Build the Docker image
96
97This takes two or three minutes to complete.
98You will need to re-build every time you make a change to dependencies in `package.json`.
99
100```sh
101$ npm run test-vr:prepare
102```
103
104### Run the tests
105
106Now, the usual loop. Write a new test, run it, fix it, repeat.
107
108```sh
109$ npm run test-vr
110```
111
112Alternatively, the UI playwright mode is available as well:
113
114```sh
115$ npm run test-vr:ui
116```
117
118If you want to record new snapshots or update the old ones, you can run:
119
120```sh
121$ npm run test-vr:update
122```
123
124You will see new files created in the `test-vr/__snapshots__` directory, please commit them to the repository!
125
126### See VR test results
127
128Open http://localhost:9323 in your browser to see the results of the tests.
129The CLI will tell you to run a "show-report" which is not necessary because there is already a Docker container running
130in the background and serving the report. Just open the URL in your browser.
131
132# Manual testing
133
134## recharts.github.io local run
135
136To manually test Recharts in a real application environment, you can use the `www` directory which contains the source code
137for the Recharts documentation website https://recharts.github.io.
138
139You can add a new example and commit it too!
140
141To run the website locally in dev mode with hot-reloading:
142
143```sh
144$ cd www
145$ npm run start
146```
147
148When running locally, the website pulls the Recharts library from the local filesystem.
149
150When you make changes to the Recharts source code, you need to re-build it for the changes to be reflected in the website:
151
152```sh
153$ cd ..
154$ npm run build
155$ cd www
156```
157
158In production build, the website pulls recharts from npm registry.
159
160## Storybook
161
162You can also use Storybook for manual testing of individual components.
163
164```sh
165$ npm run storybook
166```
167
168When adding new stories, mind that all stories here are also used for automated visual regression tests,
169using Chromatic cloud infrastructure.
170
171Chromatic are very generous and free for open source projects,
172however we already have so many stories that we hit the limit for open source plan in some months.
173
174For this reason, try to keep storybook for high fidelity examples, the ones you want to see published on the website
175and in storybook UI. For low fidelity tests, use unit tests or VR tests instead.
176
177## Playwright UI mode
178
179You can also use Playwright in UI mode for manual testing. This opens a browser window where you can see the tests running,
180and you can see before & after.
181
182```sh
183$ npm run test-vr:ui
184```
185
186# Releases
187
188[Releases](https://github.com/recharts/recharts/releases) are automated via GH Actions - when a new release is created
189in GH, CI will trigger that:
190
1911. Runs a build
1922. Runs tests
1933. Runs `npm publish`
194
195Version increments and tagging are not automated at this time.
196
197## Release testing
198
199Until we can automate more, it should be preferred to test as close to the results of `npm publish` as we possibly can.
200This ensures we don't publish unintended breaking changes. One way to do that is using `yalc` - `npm i -g yalc`.
201
2021. Make your changes in recharts
2032. `yalc publish` in recharts
2043. `yalc add recharts` in your test package (ex: in a vite or webpack reach app with recharts installed, imported, and
205 your recent changes used)
2064. `npm install`
2075. Test a local run, a build, etc.
208
209# Folder structure
210
211Source code:
212
213- `src` - source code for Recharts library
214- `test` - unit tests
215- `test-vr` - visual regression tests (using Playwright)
216- `www` - source code for Recharts documentation website recharts.github.io
217- `storybook` - Storybook stories for Recharts components, and Storybook config+scaffolding
218- `scripts` - helper scripts for development and releases
219- `.husky` and `.github` - git hooks and GitHub Actions workflows for CI
220
221Autogenerated code:
222
223Running `npm run build` generates the following folders:
224
225- `lib` - compiled output of Recharts library in CJS format - published to npm
226- `es6` - compiled output of Recharts library in ESM format - published to npm
227- `umd` - compiled output of Recharts library in UMD format - published to npm
228- `types` - generated TypeScript declaration files - published to npm
229- `build` - output of `tsc` build - we don't use this for anything at all I think
230
231Running `npm run test-coverage` generates:
232
233- `coverage` - code coverage report
234
235Running `npm run test-mutation` generates:
236
237- `reports` - mutation testing report
238
239Running `npm run omnidoc` generates:
240
241- all `www/src/docs/api/*API.tsx` files - these are later used to generate API reference pages on the website on URL `/docs/api/*`
242- all `storybook/stories/API/arg-types/*Args.ts` files - these are later used by Storybook to show props tables for components, and to generate
243 controls for props in Storybook UI
244
245If you want to modify any of the autogenerated code, you need to modify the JSDoc comments and/or TypeScript definitions in the appropriate source files in `src` folder,
Note: See TracBrowser for help on using the repository browser.