test: setup automated tests with jest

This commit is contained in:
David Laganiere 2023-01-03 19:07:54 -05:00
parent 8785b94392
commit 23be268630
No known key found for this signature in database
GPG key ID: 18C4B80581C28747
4 changed files with 745 additions and 15 deletions

32
frontend/jest.config.js Normal file
View file

@ -0,0 +1,32 @@
// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
moduleDirectories: ["node_modules", "<rootDir>/"],
transform: {
// Use babel-jest to transpile tests with the below presets
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
"^.+\\.(js|jsx|ts|tsx)$": [
"babel-jest",
{
presets: [
"@babel/preset-env",
[
"@babel/preset-react",
{
runtime: "automatic",
},
],
],
},
],
},
testEnvironment: "jest-environment-jsdom",
moduleNameMapper: {
"^uuid$": require.resolve("uuid"),
"^@fontsource/roboto$": "identity-obj-proxy",
"\\.(png)$": "identity-obj-proxy",
},
testPathIgnorePatterns: ["<rootDir>/cypress/"],
};
module.exports = customJestConfig;

6
frontend/jest.setup.js Normal file
View file

@ -0,0 +1,6 @@
// Optional: configure or set up a testing framework before each test.
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect";

View file

@ -23,12 +23,17 @@
"styled-components": "^5.3.5" "styled-components": "^5.3.5"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "12.1.5",
"axios-mock-adapter": "^1.21.2",
"jest-transform-css": "^6.0.0",
"source-map-explorer": "^2.5.2" "source-map-explorer": "^2.5.2"
}, },
"scripts": { "scripts": {
"start": "BROWSER=none react-scripts start", "start": "BROWSER=none react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"analyze": "source-map-explorer 'build/static/js/*.js'" "analyze": "source-map-explorer 'build/static/js/*.js'",
"test:unit": "npx jest --coverage --testPathPattern='unit'"
}, },
"homepage": "/app", "homepage": "/app",
"proxy": "http://127.0.0.1:4000", "proxy": "http://127.0.0.1:4000",

715
yarn.lock

File diff suppressed because it is too large Load diff