Skip to content

Commit bddbcfd

Browse files
committed
Created README file for test folder with clear instruction on required packages and test enviroment setup and testing instruction
1 parent 80e3b4a commit bddbcfd

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

__tests__/Readme.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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. use `npm run test` to run jest tests
53+
54+
### Contributing
55+
56+
Chronos hopes to inspire an active community of both users and developers. For questions, comments, or contributions, please submit a pull request.
57+
58+
### People
59+
[Snow X. Bai](https://github.com/xueapp)
60+
[Taylor Zhang](https://github.com/taylrzhang)
61+
[Tim Lee](https://github.com/timlee12)
62+
[Roberto Meloni](https://github.com/RobertoRueMeloni)

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module.exports = {
22
verbose: true,
33
setupFilesAfterEnv: ['./jest_setup/windowMock.js'],
4+
testEnvironment: "jsdom",
45
preset: 'ts-jest/presets/js-with-ts',
56
moduleNameMapper: {
67
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
78
'<rootDir>/jest_setup/fileMock.js',
89
'\\.(css|less|scss)$': '<rootDir>/jest_setup/styleMock.js',
910
},
1011
collectCoverage: true,
12+
types: ["jest","node"],
1113
};

0 commit comments

Comments
 (0)