jest.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const config = {
  2. // all ts or tsx files need to be transformed using jest-preprocess.js
  3. // Set up Babel config in jest-preprocess.js
  4. transform: {
  5. // Allow tests in TypeScript using the .ts or .tsx
  6. '^.+\\.[jt]sx?$': '<rootDir>/test-utils/jest-preprocess.js',
  7. },
  8. testRegex: '(/__tests__/.*(test|spec))\\.([tj]sx?)$',
  9. moduleDirectories: ['node_modules', __dirname],
  10. // Works like webpack rules. Tells Jest how to handle imports
  11. moduleNameMapper: {
  12. // Mock static file imports and assets which Jest can’t handle
  13. // stylesheets use the package identity-obj-proxy
  14. '.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
  15. // Manual mock other files using file-mock.js
  16. '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
  17. '<rootDir>/__mocks__/file-mock.js',
  18. // Mock SVG
  19. '\\.svg': '<rootDir>/__mocks__/svgr-mock.js',
  20. '^~/(.*)$': '<rootDir>/src/$1',
  21. },
  22. moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  23. testPathIgnorePatterns: ['node_modules', '.cache', 'public'],
  24. // Gatsby includes un-transpiled ES6 code. Exclude the gatsby module.
  25. transformIgnorePatterns: ['node_modules/(?!(gatsby)/)'],
  26. globals: {
  27. __PATH_PREFIX__: '',
  28. },
  29. collectCoverageFrom: [
  30. 'src/**/*.{js,jsx,ts,tsx}',
  31. '!<rootDir>/src/**/*.stories.{ts,tsx}',
  32. '!<rootDir>/src/**/__tests__/**/*',
  33. '!<rootDir>/src/components/**/index.ts',
  34. '!<rootDir>/node_modules/',
  35. '!<rootDir>/test-utils/',
  36. ],
  37. testURL: 'http://localhost',
  38. setupFiles: ['<rootDir>/test-utils/loadershim.js', 'jest-localstorage-mock'],
  39. setupFilesAfterEnv: ['<rootDir>/test-utils/setup-test-env.ts'],
  40. };
  41. module.exports = config;