Skip to content

Commit

Permalink
feat: provide support for custom jest configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakhar Dolozhevskiy committed Aug 23, 2021
1 parent 7e65196 commit 3d9fa32
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
name: Install dependencies
working_directory: ~/repo
command: |
sudo npm i --unsafe-perm=true cross-env -g && sudo npm i --unsafe-perm=true mhy@11.1.2 -g
sudo npm i --unsafe-perm=true cross-env -g && sudo npm i --unsafe-perm=true mhy@latest -g
- deploy:
name: Trigger deployment
Expand Down
3 changes: 3 additions & 0 deletions docs/configs/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[https://jestjs.io/docs/en/configuration.html](https://jestjs.io/docs/en/configuration.html)

For custom jest setup file support you can simple add file with such name pattern `jest.setup.[js|ts]` to your project
and provide all needed configurations there

```bash
# Print config to console
mhy config jest
Expand Down
35 changes: 2 additions & 33 deletions src/configs/jest/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
import path from 'path'
import '@/utils/globals'

import { loadConfig } from '@/utils'
import mhyConfig from '@/configs/mhy'

const jestConfig = loadConfig('jest', {
setupFilesAfterEnv: [path.resolve(__dirname, './setup.js')],
rootDir: process.cwd(),
roots: [path.resolve(process.cwd(), mhyConfig.srcFolder)],
watchPathIgnorePatterns: ['__.*__'],
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
modulePaths: [
path.resolve(process.cwd(), mhyConfig.srcFolder),
path.resolve(process.cwd(), 'node_modules'),
path.resolve(__dirname, '../../../node_modules')
],
transform: {
'^.+\\.[jt]sx?$': require.resolve('./preprocess')
},
transformIgnorePatterns: [],
bail: true,
testRegex: '\\.?(test|tests|spec|integration)\\.[jt]sx?$',
collectCoverage: false,
verbose: true,
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'identity-obj-proxy',
'\\.(s?css|less)$': 'identity-obj-proxy',
'\\.(svgx?)$': path.resolve(__dirname, 'mocks/react-null.js')
},
collectCoverageFrom: ['**/*.js'],
watchPlugins: []
})

export default jestConfig
export default from './loader'
39 changes: 39 additions & 0 deletions src/configs/jest/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path'

import { loadConfig } from '@/utils'
import mhyConfig from '@/configs/mhy'

const srcPath = path.join(process.cwd(), mhyConfig.srcFolder)

const jestConfig = loadConfig('jest', {
setupFilesAfterEnv: [
path.resolve(__dirname, './setup.js'),
...require.context(srcPath, true, /jest\.setup\.[jt]sx?$/).keys()
],
rootDir: process.cwd(),
roots: [srcPath],
watchPathIgnorePatterns: ['__.*__'],
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
modulePaths: [
path.resolve(process.cwd(), mhyConfig.srcFolder),
path.resolve(process.cwd(), 'node_modules'),
path.resolve(__dirname, '../../../node_modules')
],
transform: {
'^.+\\.[jt]sx?$': require.resolve('./preprocess')
},
transformIgnorePatterns: [],
bail: true,
testRegex: '\\.?(test|tests|spec|integration)\\.[jt]sx?$',
collectCoverage: false,
verbose: true,
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 'identity-obj-proxy',
'\\.(s?css|less)$': 'identity-obj-proxy',
'\\.(svgx?)$': path.resolve(__dirname, 'mocks/react-null.js')
},
collectCoverageFrom: ['**/*.js'],
watchPlugins: []
})

export default jestConfig

0 comments on commit 3d9fa32

Please sign in to comment.