For frontend testing, ensure you've prepared your environment as follows:
- React Testing Library versions 13+ require React v18. If your project uses an older version of React, be sure to install version 12
npm install --save-dev @testing-library/react@12
- install additional packages
npm install -g jest
npm i @jest/types
npm i ts-jest
npm i jest-environment-jsdom
npm i --save-dev @types/jest @testing-library/jest-dom
<!-- npm i --save-dev @types/jest -->
npm i @types/node
npm install -D ts-node
- create jest.config.js
module.exports = {
verbose: true,
setupFilesAfterEnv: ['./jest_setup/windowMock.js'],
testEnvironment: "jsdom",
preset: 'ts-jest/presets/js-with-ts',
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/jest_setup/fileMock.js',
'\\.(css|less|scss)$': '<rootDir>/jest_setup/styleMock.js',
},
collectCoverage: true,
types: ["jest","node"],
};
- make sure jest_setup folder is at root directory of Chronos with styleMock.js and windowMock.js
styleMock.js
module.exports = {};
windowMock.js
// Mock window environment
window.require = require;
// Mock import statements for Plotly
window.URL.createObjectURL = () => {};
// Mock get context
HTMLCanvasElement.prototype.getContext = () => {};
-
update database info inside
test_settings.json
-
use
npm run test
to run jest tests
For backend testing, ensure you've prepared your environment as follows:
- create
jest.config.js
module.exports = {
roots: ['<rootDir>'], // Set the root directory for test files (adjust this path to your test folder)
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
collectCoverage: true,
coverageDirectory: 'coverage',
testPathIgnorePatterns: ['/node_modules/', '/__tests__/'],
};
- install additional packages
npm i mongodb-memory-server
- use
npm run backend-test
to run jest tests
Perform end-to-end testing with the following steps:
- install the following packages
npm i selenium-webdriver
npm i chromedriver
-
use
npm run dev:app
to start the app -
use
./node_modules/.bin/chromedriver
to run the Chromedriver executable -
use
npm run start:e2e
to run the end-to-end tests
Chronos hopes to inspire an active community of both users and developers. For questions, comments, or contributions, please submit a pull request.
Read our contributing README to further learn how you can take part in improving Chronos.