import type { Config } from "@jest/types";

const config: Config.InitialOptions = {
    preset: "ts-jest",
    testEnvironment: "jsdom",
    roots: ["<rootDir>/src", "<rootDir>/tests"],
    testMatch: ["**/__tests__/**/*.+(ts|tsx|js)", "**/?(*.)+(spec|test).+(ts|tsx|js)"],
    transform: {
        "^.+\\.(ts|tsx)$": "ts-jest",
        "^.+\\.(js|jsx)$": "babel-jest", // optional — اگر babel ندارید می‌توانید حذف کنید
    },
    moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
    moduleNameMapper: {
        "^@/(.*)$": "<rootDir>/src/$1",
        "^@public/lotties/(.*)$": "<rootDir>/public/lotties/$1",
        "^@package.json$": "<rootDir>/package.json",
        // "^@appointment/(.*)$": "<rootDir>/src/apps/appointment/$1",
        // "^@card/(.*)$": "<rootDir>/src/apps/card/$1",
        "^@new-ui/(.*)$": "<rootDir>/src/apps/new-ui/$1",
        // "^@new-ui-card/(.*)$": "<rootDir>/src/apps/new-ui-card/$1",

        // static assets & styles
        "^.+\\.(css|scss|sass)$": "<rootDir>/tests/__mocks__/styleMock.js",
        "^.+\\.(jpg|jpeg|png|gif|webp|svg)$": "<rootDir>/tests/__mocks__/fileMock.js",
    },
    setupFiles: ["<rootDir>/tests/jestSetupFiles.ts"], // اجرا قبل از env
    setupFilesAfterEnv: ["<rootDir>/tests/setupTests.ts"], // اجرا بعد از env
    moduleDirectories: ["node_modules", "src"],
    testPathIgnorePatterns: ["/node_modules/", "/dist/", "/build/"],
    transformIgnorePatterns: ["/node_modules/(?!(some-esm-package)/)"], // اگر نیاز به transpile node_modules دارید آن‌ها را لیست کنید
    collectCoverage: false,
    globals: {
        "ts-jest": {
            tsconfig: "tsconfig.jest.json", // اگر فایل جدا دارید؛ در غیر این‌صورت 'tsconfig.json'
        },
    },
};

export default config;
