jest.config.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* eslint-env node */
  2. const path = require('path'); // eslint-disable-line
  3. let testMatch;
  4. const {JEST_TESTS, CI_NODE_TOTAL, CI_NODE_INDEX} = process.env;
  5. /**
  6. * In CI we may need to shard our jest tests so that we can parellize the test runs
  7. *
  8. * `JEST_TESTS` is a list of all tests that will run, captured by `jest --listTests`
  9. * Then we split up the tests based on the total number of CI instances that will
  10. * be running the tests.
  11. */
  12. if (
  13. JEST_TESTS &&
  14. typeof CI_NODE_TOTAL !== 'undefined' &&
  15. typeof CI_NODE_INDEX !== 'undefined'
  16. ) {
  17. // Taken from https://github.com/facebook/jest/issues/6270#issue-326653779
  18. const tests = JSON.parse(process.env.JEST_TESTS).sort((a, b) => {
  19. return b.localeCompare(a);
  20. });
  21. const length = tests.length;
  22. const size = Math.floor(length / CI_NODE_TOTAL);
  23. const remainder = length % CI_NODE_TOTAL;
  24. const offset = Math.min(CI_NODE_INDEX, remainder) + CI_NODE_INDEX * size;
  25. const chunk = size + (CI_NODE_INDEX < remainder ? 1 : 0);
  26. testMatch = tests.slice(offset, offset + chunk);
  27. }
  28. module.exports = {
  29. verbose: false,
  30. collectCoverageFrom: [
  31. 'tests/js/spec/**/*.{js,jsx,tsx}',
  32. 'static/app/**/*.{js,jsx,ts,tsx}',
  33. ],
  34. coverageReporters: ['html', 'cobertura'],
  35. coverageDirectory: '.artifacts/coverage',
  36. snapshotSerializers: ['enzyme-to-json/serializer'],
  37. moduleNameMapper: {
  38. '^sentry-test/(.*)': '<rootDir>/tests/js/sentry-test/$1',
  39. '^sentry-locale/(.*)': '<rootDir>/src/sentry/locale/$1',
  40. '\\.(css|less|png|jpg|mp4)$': '<rootDir>/tests/js/sentry-test/importStyleMock.js',
  41. '\\.(svg)$': '<rootDir>/tests/js/sentry-test/svgMock.js',
  42. 'integration-docs-platforms':
  43. '<rootDir>/tests/fixtures/integration-docs/_platforms.json',
  44. },
  45. modulePaths: ['<rootDir>/static'],
  46. setupFiles: [
  47. '<rootDir>/static/app/utils/silence-react-unsafe-warnings.ts',
  48. '<rootDir>/tests/js/throw-on-react-error.js',
  49. '<rootDir>/tests/js/setup.js',
  50. 'jest-canvas-mock',
  51. ],
  52. setupFilesAfterEnv: ['<rootDir>/tests/js/setupFramework.ts'],
  53. testMatch: testMatch || ['<rootDir>/tests/js/**/*(*.)@(spec|test).(js|ts)?(x)'],
  54. testPathIgnorePatterns: ['<rootDir>/tests/sentry/lang/javascript/'],
  55. unmockedModulePathPatterns: [
  56. '<rootDir>/node_modules/react',
  57. '<rootDir>/node_modules/reflux',
  58. ],
  59. transform: {
  60. '^.+\\.jsx?$': 'babel-jest',
  61. '^.+\\.tsx?$': 'babel-jest',
  62. '^.+\\.pegjs?$': '<rootDir>/tests/js/jest-pegjs-transform.js',
  63. },
  64. moduleFileExtensions: ['js', 'ts', 'jsx', 'tsx'],
  65. globals: {},
  66. reporters: [
  67. 'default',
  68. [
  69. 'jest-junit',
  70. {
  71. outputDirectory: '.artifacts',
  72. outputName: 'jest.junit.xml',
  73. },
  74. ],
  75. ],
  76. testRunner: 'jest-circus/runner',
  77. testEnvironment: '<rootDir>/tests/js/instrumentedEnv',
  78. testEnvironmentOptions: {
  79. output: path.resolve(__dirname, '.artifacts', 'visual-snapshots', 'jest'),
  80. SENTRY_DSN: 'https://3fe1dce93e3a4267979ebad67f3de327@sentry.io/4857230',
  81. },
  82. };