Skip to content

Commit

Permalink
feat: add feature to use default jest config
Browse files Browse the repository at this point in the history
affects: @medly/jest-config-react
  • Loading branch information
gmukul01 committed Dec 27, 2022
1 parent 094f41b commit 9e38db5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
27 changes: 26 additions & 1 deletion packages/jest-config-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ yarn add -D @medly/jest-config-react

## Usage

### 1. Use default config

Add below code in your `package.json`

```json
{
"script": {
"dist": "jest --config=node_modules/@medly/jest-config-react/index.js"
}
}
```

### 2. Overwrite default settings

Add below code in your `jest.config.js`

```js
Expand All @@ -28,6 +42,17 @@ module.exports = configure({
});
```

OR

```js
const baseConfig = require('@medly/jest-config-react');

module.exports = {
...baseConfig,
rootDir: './'
};
```

## Default config

To view the default config click [here](index.js)
To view the default config click [here](index.js)
11 changes: 6 additions & 5 deletions packages/jest-config-react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ const defaultConfig = {
collectCoverageFrom: [
'<rootDir>/src/**/*.(ts|tsx)',
'!<rootDir>/**/index.(ts|tsx)',
'!<rootDir>/**/types.(ts|tsx)',
'!<rootDir>/**/types/**',
'!<rootDir>/**/*.d.ts',
'!<rootDir>/src/App.tsx',
'!<rootDir>/src/theme/**',
'!<rootDir>/src/store/sagas.ts',
'!<rootDir>/node_modules/**',
'!<rootDir>/src/**/types.(ts|tsx)',
'!<rootDir>/src/**/types/**',
'!<rootDir>/src/utils/test-utils.tsx'
],
coverageDirectory: '<rootDir>/coverage/',
moduleFileExtensions: ['.mjs', 'ts', 'tsx', 'js', 'jsx', 'svg'],
roots: ['<rootDir>/src/'],
setupFilesAfterEnv: ['<rootDir>/node_modules/@medly/jest-config-react/setupAfterEnv.js'],
rootDir: process.cwd(),
setupFilesAfterEnv: [require.resolve('./setupAfterEnv.js')],
testEnvironment: 'jsdom',
testMatch: ['**/*.(spec|test).(ts|tsx)'],
verbose: true,
moduleNameMapper: {
'\\.(css|less|xsl)$': '<rootDir>/node_modules/@medly/jest-config-react/styleMock.js',
'\\.(css|less|xsl)$': require.resolve('./styleMock.js'),
'^@store(.*)$': '<rootDir>/src/store$1',
'^@test-utils': '<rootDir>/src/utils/test-utils',
'^@components(.*)$': '<rootDir>/src/components$1',
Expand Down

0 comments on commit 9e38db5

Please sign in to comment.