Skip to content

Commit

Permalink
refactor: simplify jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Sep 19, 2022
1 parent dd0434e commit 5c512b6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 48 deletions.
38 changes: 11 additions & 27 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
import type { Config } from '@jest/types'
import glob from 'glob'

const packages = glob.sync(`./src`).map(p => p.replace(/^\./, `<rootDir>`))
import type { Config } from 'jest'

const ignoreDirs = [
'build/',
'dist/',
'node_modules/',
`\\.cache`,
'scripts/',
'public/',
'generators/',
'generated/',
'website/',
'tests/',
'packages/',
]

const config: Config.InitialOptions = {
export default async (): Promise<Config> => ({
preset: 'ts-jest',
testEnvironment: 'jsdom',
testEnvironmentOptions: {
url: `http://localhost`,
},
roots: packages,
verbose: false,
silent: true,
roots: ['./src'],
transform: {
'^.+\\.[jt]sx?$': `<rootDir>/tests/jest-preprocess.js`,
},
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': `identity-obj-proxy`,
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': `<rootDir>/tests/file-mock.js`,
'^.+\\.[t]sx?$': `ts-jest`,
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
testPathIgnorePatterns: ignoreDirs,
transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
coveragePathIgnorePatterns: ignoreDirs,
coverageDirectory: '<rootDir>/coverage/',
globals: {
__PATH_PREFIX__: ``,
},
setupFiles: [`<rootDir>/tests/loadershim.js`],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.([t]sx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}

export default config
})
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"devDependencies": {
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^7.0.2",
"@types/glob": "^8.0.0",
"@types/jest": "^29.0.3",
"@types/node": "^18.7.18",
"@types/react": "^17.0.38",
Expand All @@ -60,11 +59,11 @@
"eslint-plugin-tree-shaking": "^1.10.0",
"jest": "^29.0.3",
"jest-environment-jsdom": "^29.0.3",
"jest-preset-gatsby": "^1.0.134",
"netlify-cli": "^11.8.0",
"plop": "^3.0.5",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.1",
"ts-node": "^10.2.1",
"typescript": "^4.5.5"
},
Expand Down
1 change: 0 additions & 1 deletion tests/file-mock.js

This file was deleted.

5 changes: 0 additions & 5 deletions tests/jest-preprocess.js

This file was deleted.

13 changes: 0 additions & 13 deletions tests/loadershim.js

This file was deleted.

0 comments on commit 5c512b6

Please sign in to comment.