jest.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // For a detailed explanation regarding each configuration property, visit:
  2. // https://jestjs.io/docs/en/configuration.html
  3. // https://kulshekhar.github.io/ts-jest/user/config/
  4. const MODULE_NAME_MAPPING = {
  5. '^\\^/(.+)$': '<rootDir>/$1',
  6. '^~/(.+)$': '<rootDir>/src/$1',
  7. '^@growi/([^/]+)$': '<rootDir>/../$1/src',
  8. '^@growi/([^/]+)/(.+)$': '<rootDir>/../$1/src/$2',
  9. };
  10. module.exports = {
  11. // Indicates whether each individual test should be reported during the run
  12. verbose: true,
  13. preset: 'ts-jest/presets/js-with-ts',
  14. projects: [
  15. {
  16. displayName: 'unit',
  17. preset: 'ts-jest/presets/js-with-ts',
  18. // transform ESM to CJS
  19. transformIgnorePatterns: [
  20. '/node_modules/(?!remark-gfm)/',
  21. ],
  22. rootDir: '.',
  23. roots: ['<rootDir>'],
  24. testMatch: ['<rootDir>/test/unit/**/*.test.ts', '<rootDir>/test/unit/**/*.test.js'],
  25. testEnvironment: 'node',
  26. // Automatically clear mock calls and instances between every test
  27. clearMocks: true,
  28. moduleNameMapper: MODULE_NAME_MAPPING,
  29. },
  30. {
  31. displayName: 'server',
  32. preset: 'ts-jest/presets/js-with-ts',
  33. rootDir: '.',
  34. roots: ['<rootDir>'],
  35. testMatch: ['<rootDir>/test/integration/**/*.test.ts', '<rootDir>/test/integration/**/*.test.js'],
  36. // https://regex101.com/r/jTaxYS/1
  37. modulePathIgnorePatterns: ['<rootDir>/test/integration/*.*/v5(..*)*.[t|j]s'],
  38. testEnvironment: 'node',
  39. globalSetup: '<rootDir>/test/integration/global-setup.js',
  40. globalTeardown: '<rootDir>/test/integration/global-teardown.js',
  41. setupFilesAfterEnv: ['<rootDir>/test/integration/setup.js'],
  42. // Automatically clear mock calls and instances between every test
  43. clearMocks: true,
  44. moduleNameMapper: MODULE_NAME_MAPPING,
  45. },
  46. {
  47. displayName: 'server-v5',
  48. preset: 'ts-jest/presets/js-with-ts',
  49. rootDir: '.',
  50. roots: ['<rootDir>'],
  51. testMatch: ['<rootDir>/test/integration/**/v5.*.test.ts', '<rootDir>/test/integration/**/v5.*.test.js'],
  52. testEnvironment: 'node',
  53. globalSetup: '<rootDir>/test/integration/global-setup.js',
  54. globalTeardown: '<rootDir>/test/integration/global-teardown.js',
  55. setupFilesAfterEnv: ['<rootDir>/test/integration/setup.js'],
  56. // Automatically clear mock calls and instances between every test
  57. clearMocks: true,
  58. moduleNameMapper: MODULE_NAME_MAPPING,
  59. },
  60. ],
  61. // Automatically clear mock calls and instances between every test
  62. clearMocks: true,
  63. // Indicates whether the coverage information should be collected while executing the test
  64. collectCoverage: true,
  65. // An array of glob patterns indicating a set of files for which coverage information should be collected
  66. // collectCoverageFrom: undefined,
  67. // The directory where Jest should output its coverage files
  68. coverageDirectory: 'coverage',
  69. // An array of regexp pattern strings used to skip coverage collection
  70. coveragePathIgnorePatterns: [
  71. 'index.ts',
  72. '/config/',
  73. '/resource/',
  74. '/node_modules/',
  75. ],
  76. };