Skip to content

Commit

Permalink
Merge pull request #1 from emnnipal/feature/jest
Browse files Browse the repository at this point in the history
feat: implement jest unit testing
  • Loading branch information
emnnipal authored Apr 22, 2022
2 parents c0cfd8c + 799abef commit f733c79
Show file tree
Hide file tree
Showing 9 changed files with 5,159 additions and 1,379 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
"sourceType": "module"
},
"plugins": ["react"],
"overrides": [
{
"files": ["*.test.jsx"],
"rules": {
"no-undef": "off"
}
}
],
"rules": {
"no-prototype-builtins": "off",
"linebreak-style": "off",
Expand Down
11 changes: 11 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
presets: [
'@babel/preset-env',
[
'@babel/preset-react',
{
runtime: 'automatic',
},
],
],
};
81 changes: 81 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module.exports = {
// Automatically clear mock calls, instances and results before every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: false,

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['<rootDir>/node_modules/'],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',

// An array of file extensions your modules use
moduleFileExtensions: [
'js',
'jsx',
'ts',
'tsx',
'json',
// "node"
],

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: ['node_modules', 'src'],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
'\\.(gif|ttf|eot|png|scss|css|less)$': '<rootDir>/src/__tests__/__mocks__/fileMock.js',
'^.+\\.svg$': '<rootDir>/src/__tests__/__mocks__/svgMock.js',
},

/**
* A preset that is used as a base for Jest's configuration
*
* 1. `ts-jest/presets/default` or `ts-jest`
* TypeScript files (.ts, .tsx) will be transformed by ts-jest to CommonJS syntax,
* leaving JavaScript files (.js, jsx) as-is.
*
* 2. `ts-jest/presets/default-esm` TypeScript files (.ts, .tsx) will be transformed
* by ts-jest to ESM syntax, leaving JavaScript files (.js, jsx) as-is.
*
* 3. `ts-jest/presets/js-with-ts`
* TypeScript and JavaScript files (.ts, .tsx, .js, .jsx) will be transformed by ts-jest
* to CommonJS syntax. You'll need to set allowJs to true in your tsconfig.json file.
*
* 4. `ts-jest/presets/js-with-ts-esm`
* TypeScript and JavaScript files (.ts, .tsx, .js, .jsx, .mjs) will be transformed by ts-jest to ESM syntax.
* You'll need to set allowJs to true in your tsconfig.json file.
*
* 5. `ts-jest/presets/js-with-babel`
* TypeScript files (.ts, .tsx) will be transformed by ts-jest to CommonJS syntax, and JavaScript files (.js, jsx) will be transformed by babel-jest.
*
* 6. `ts-jest/presets/js-with-babel-esm`
* TypeScript files (.ts, .tsx) will be transformed by ts-jest to ESM syntax, and JavaScript files (.js, jsx, .mjs) will be transformed by babel-jest.
*/
// preset: 'ts-jest',

// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
snapshotFormat: {
printBasicPrototype: false,
},

// The test environment that will be used for testing
testEnvironment: 'jsdom',

// The glob patterns Jest uses to detect test files
testMatch: [
'<rootDir>/src/**/__tests__/**/*test.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}',
],

// A map from regular expressions to paths to transformers
// transform: {
// '^.+\\.(ts|tsx|js|jsx|html)$': 'ts-jest',
// },
};
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"version": "0.0.0",
"scripts": {
"test": "jest",
"dev": "vite",
"build": "rm -rf build && vite build",
"preview": "vite preview",
Expand All @@ -28,11 +29,17 @@
"zustand": "4.0.0-rc.0"
},
"devDependencies": {
"@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.1",
"babel-jest": "^27.5.1",
"cross-env": "^7.0.3",
"dotenv": "^16.0.0",
"eslint": "^8.13.0",
Expand All @@ -43,8 +50,10 @@
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"lint-staged": "^12.4.0",
"prettier": "^2.6.2",
"react-test-renderer": "^18.0.0",
"sass": "^1.50.1",
"vite": "^2.9.5",
"vite-plugin-compression": "^0.5.1",
Expand Down
Loading

0 comments on commit f733c79

Please sign in to comment.