|
| 1 | +# Testing |
| 2 | + |
| 3 | +### Preparation |
| 4 | + |
| 5 | +1. React Testing Library versions 13+ require React v18. If your project uses an older version of React, be sure to install version 12 |
| 6 | +``` |
| 7 | +npm install --save-dev @testing-library/react@12 |
| 8 | +
|
| 9 | +``` |
| 10 | +2. install additional packages |
| 11 | +``` |
| 12 | +npm install -g jest |
| 13 | +npm i @jest/types |
| 14 | +npm i ts-jest |
| 15 | +npm i jest-environment-jsdom |
| 16 | +npm i --save-dev @types/jest |
| 17 | +npm i @types/node |
| 18 | +``` |
| 19 | +3. create jest.config.js |
| 20 | +``` |
| 21 | +module.exports = { |
| 22 | + verbose: true, |
| 23 | + setupFilesAfterEnv: ['./jest_setup/windowMock.js'], |
| 24 | + testEnvironment: "jsdom", |
| 25 | + preset: 'ts-jest/presets/js-with-ts', |
| 26 | + moduleNameMapper: { |
| 27 | + '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': |
| 28 | + '<rootDir>/jest_setup/fileMock.js', |
| 29 | + '\\.(css|less|scss)$': '<rootDir>/jest_setup/styleMock.js', |
| 30 | + }, |
| 31 | + collectCoverage: true, |
| 32 | + types: ["jest","node"], |
| 33 | +}; |
| 34 | +``` |
| 35 | +4. make sure jest_setup folder is at root directory of Chronos with styleMock.js and windowMock.js |
| 36 | + |
| 37 | + styleMock.js |
| 38 | + ``` |
| 39 | + module.exports = {}; |
| 40 | + ``` |
| 41 | + windowMock.js |
| 42 | + ``` |
| 43 | + // Mock window environment |
| 44 | + window.require = require; |
| 45 | +
|
| 46 | + // Mock import statements for Plotly |
| 47 | + window.URL.createObjectURL = () => {}; |
| 48 | +
|
| 49 | + // Mock get context |
| 50 | + HTMLCanvasElement.prototype.getContext = () => {}; |
| 51 | + ``` |
| 52 | +5. update database info inside test_settings.json |
| 53 | + |
| 54 | +6. use `npm run test` to run jest tests |
| 55 | + |
| 56 | +### Contributing |
| 57 | + |
| 58 | +Chronos hopes to inspire an active community of both users and developers. For questions, comments, or contributions, please submit a pull request. |
| 59 | + |
| 60 | +### People |
| 61 | +[Snow X. Bai](https://github.com/xueapp) |
| 62 | +[Taylor Zhang](https://github.com/taylrzhang) |
| 63 | +[Tim Lee](https://github.com/timlee12) |
| 64 | +[Roberto Meloni](https://github.com/RobertoRueMeloni) |
0 commit comments