jest.config.js 3.2 KB

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