jest.config.js 3.2 KB

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