Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ lerna-debug.log*
# Project related
/instances/*
!/instances/.gitkeep
/test/
# Testing
/coverage/
/src/env.yml
/store
*.env
Expand Down
73 changes: 73 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Jest configuration for Evolution API test suite.
* Uses ts-jest to handle TypeScript files and moduleNameMapper
* to resolve path aliases defined in tsconfig.json.
*/

import type { Config } from 'jest';

const config: Config = {
// Use ts-jest preset for TypeScript support
preset: 'ts-jest',

// Node environment (no DOM needed for API tests)
testEnvironment: 'node',

// Automatically clear mock calls and instances before every test
clearMocks: true,

// Collect coverage information
collectCoverage: true,

// Coverage output directory
coverageDirectory: 'coverage',

// Coverage provider
coverageProvider: 'v8',

// Only collect coverage from source files (not test files or node_modules)
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/main.ts',
],

// Map TypeScript path aliases to actual paths (mirrors tsconfig.json paths)
moduleNameMapper: {
'^@api/(.*)$': '<rootDir>/src/api/$1',
'^@cache/(.*)$': '<rootDir>/src/cache/$1',
'^@config/(.*)$': '<rootDir>/src/config/$1',
'^@exceptions$': '<rootDir>/src/exceptions',
'^@libs/(.*)$': '<rootDir>/src/libs/$1',
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
'^@validate/(.*)$': '<rootDir>/src/validate/$1',
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider pointing ts-jest at the existing tsconfig instead of an inline override.

The custom tsconfig block here (e.g., strict: false, rootDir: './') can drift from tsconfig.json and cause tests to compile differently from the app. Prefer using ts-jest’s tsconfig option to point at the main tsconfig (or a dedicated test tsconfig) so the configuration stays consistent and easier to maintain.

Suggested implementation:

    '^@utils/(.*)$': '<rootDir>/src/utils/$1',
    '^@validate/(.*)$': '<rootDir>/src/validate/$1',
  },

  // ts-jest configuration
  transform: {
    '^.+\\.tsx?$': [
      'ts-jest',
      {
        // Use the main TypeScript configuration to keep tests aligned
        // with the application compilation settings.
        tsconfig: '<rootDir>/tsconfig.json',
      },
    ],
  },

  // Map TypeScript path aliases to actual paths (mirrors tsconfig.json paths)
  moduleNameMapper: {
  • If you have a dedicated test TypeScript configuration (e.g., tsconfig.test.json), update the tsconfig path accordingly: tsconfig: '<rootDir>/tsconfig.test.json'.
  • Make sure ts-jest is correctly set up in the rest of jest.config.ts (e.g., preset: 'ts-jest' if you are using the preset); adjust as needed to match existing project conventions.


// ts-jest configuration
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: {
// Relax strict mode for tests
strict: false,
strictNullChecks: false,
esModuleInterop: true,
// Point rootDir to project root so test files are included
rootDir: './',
},
},
],
},

// Test file patterns
testMatch: ['**/test/**/*.test.ts', '**/*.test.ts'],

// Directories to ignore
testPathIgnorePatterns: ['/node_modules/', '/dist/'],

// Verbose output
verbose: true,
};

export default config;
Loading