jest.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. '\\.(css|less|png|jpg|mp4)$': '<rootDir>/tests/js/sentry-test/importStyleMock.js',
  40. '\\.(svg)$': '<rootDir>/tests/js/sentry-test/svgMock.js',
  41. 'integration-docs-platforms':
  42. '<rootDir>/tests/fixtures/integration-docs/_platforms.json',
  43. },
  44. modulePaths: ['<rootDir>/static'],
  45. setupFiles: [
  46. '<rootDir>/static/app/utils/silence-react-unsafe-warnings.ts',
  47. '<rootDir>/tests/js/throw-on-react-error.js',
  48. '<rootDir>/tests/js/setup.js',
  49. 'jest-canvas-mock',
  50. ],
  51. setupFilesAfterEnv: ['<rootDir>/tests/js/setupFramework.ts'],
  52. testMatch: testMatch || ['<rootDir>/tests/js/**/*(*.)@(spec|test).(js|ts)?(x)'],
  53. testPathIgnorePatterns: ['<rootDir>/tests/sentry/lang/javascript/'],
  54. unmockedModulePathPatterns: [
  55. '<rootDir>/node_modules/react',
  56. '<rootDir>/node_modules/reflux',
  57. ],
  58. transform: {
  59. '^.+\\.jsx?$': 'babel-jest',
  60. '^.+\\.tsx?$': 'babel-jest',
  61. '^.+\\.pegjs?$': '<rootDir>/tests/js/jest-pegjs-transform.js',
  62. },
  63. moduleFileExtensions: ['js', 'ts', 'jsx', 'tsx'],
  64. globals: {},
  65. reporters: [
  66. 'default',
  67. [
  68. 'jest-junit',
  69. {
  70. outputDirectory: '.artifacts',
  71. outputName: 'jest.junit.xml',
  72. },
  73. ],
  74. ],
  75. testRunner: 'jest-circus/runner',
  76. testEnvironment: '<rootDir>/tests/js/instrumentedEnv',
  77. testEnvironmentOptions: {
  78. output: path.resolve(__dirname, '.artifacts', 'visual-snapshots', 'jest'),
  79. SENTRY_DSN: 'https://3fe1dce93e3a4267979ebad67f3de327@sentry.io/4857230',
  80. },
  81. };