packages: add jest

This commit is contained in:
Chika 2022-09-17 17:02:33 +03:00
parent 6319a25d0f
commit 262e6746bb
5 changed files with 1641 additions and 56 deletions

View File

@ -1,4 +1,5 @@
{
"root": true,
"env": {
"browser": true,
"es2021": true,
@ -16,7 +17,7 @@
"project": "./tsconfig.json"
},
"parser": "@typescript-eslint/parser",
"plugins": ["react", "prettier", "@typescript-eslint", "unicorn"],
"plugins": ["react", "prettier", "@typescript-eslint", "unicorn", "testing-library"],
"rules": {
"linebreak-style": ["error", "windows"],
"comma-dangle": "off",
@ -74,5 +75,12 @@
}
],
"import/no-unresolved": "warn"
}
},
"overrides": [
// Only uses Testing Library lint rules in test files
{
"files": ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
"extends": ["plugin:testing-library/react"]
}
]
}

25
jest.config.js Normal file
View File

@ -0,0 +1,25 @@
// jest.config.js
const nextJest = require('next/jest');
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
});
// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleDirectories: ['node_modules', '<rootDir>/'],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'lodash-es': 'lodash',
},
testEnvironment: 'jest-environment-jsdom',
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);

6
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

@ -12,7 +12,9 @@
"precommit": "yarn prettier && yarn lint:fix",
"graphql:codegen": "graphql-codegen --config .graphqlrc.yml",
"graphql:schema": "dotenv -e .env.local apollo client:download-schema graphql/crm.schema.graphql",
"prepare": "husky install"
"prepare": "husky install",
"test": "jest --watch",
"test:ci": "jest --ci"
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
@ -44,6 +46,9 @@
"@graphql-codegen/cli": "2.12.0",
"@graphql-codegen/typescript": "2.7.3",
"@graphql-codegen/typescript-operations": "2.5.3",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/lodash-es": "^4.17.6",
"@types/node": "18.7.18",
"@types/react": "18.0.20",
@ -60,8 +65,11 @@
"eslint-config-next": "12.3.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-testing-library": "^5.6.4",
"eslint-plugin-unicorn": "^43.0.2",
"husky": "^7.0.4",
"jest": "^29.0.3",
"jest-environment-jsdom": "^29.0.3",
"msw": "^0.39.2",
"prettier": "2.7.1",
"typescript": "4.8.3"

1644
yarn.lock

File diff suppressed because it is too large Load Diff