const commonSettings = {
  moduleFileExtensions: ["ts", "tsx", "js", "jsx", "vue", "json", "node"],
  moduleNameMapper: {
    "^@/(.*)$": "<rootDir>/$1",
    "^~/(.*)$": "<rootDir>/$1",
    "^vue$": "vue/dist/vue.common.js",
  },
  testPathIgnorePatterns: ["/node_modules/", "/.nuxt/", "/.nuxt_mom/"],

  transform: {
    "\\.(js|jsx|mjs|cjs|ts|tsx)$": [
      "babel-jest",
      {
        presets: ["@babel/preset-env", "@babel/preset-typescript"],
        babelrc: false,
        configFile: false,
        plugins: [
          // "@babel/plugin-proposal-export-default-from",
          "@babel/plugin-syntax-dynamic-import",
          "@babel/plugin-transform-modules-commonjs",
          "@babel/plugin-transform-runtime",
        ],
      },
    ],
    "\\.(vue)$": "vue-jest",
  },
  transformIgnorePatterns: [
    "^.+\\.module\\.(css|sass|scss|less)$",
    "node_modules/(?!@mega-apps/)",
  ],
  collectCoverage: false,
  collectCoverageFrom: [
    "<rootDir>/{components,pages,mixins,store,utils,api}/**/*.{tsx,jsx,ts,js,vue}",
    "!<rootDir>/**/*.d.ts",
  ],
  coverageReporters: ["html"],
};

const presets = {
  "jest-playwright-preset": {
    globalSetup: "jest-playwright-preset/setup.js",
    globalTeardown: "jest-playwright-preset/teardown.js",
    testEnvironment: "jest-playwright-preset/lib/PlaywrightEnvironment.js",
    runner: "jest-playwright-preset/runner.js",
    setupFilesAfterEnv: [
      "expect-playwright",
      "jest-playwright-preset/lib/extends.js",
    ],
    verbose: true,
  },
};

module.exports = {
  projects: [
    {
      ...commonSettings,
      displayName: "Unit Tests (Jest)",
      testMatch: [
        "<rootDir>/**/*{__tests__,tests,test}/unit/**/*.{spec,test}.{js,jsx,ts,tsx}",
      ],
    },
    {
      ...commonSettings,
      displayName: "Integration Tests (Jest)",
      testMatch: [
        "<rootDir>/*{__tests__,tests,test}/integration/**/*.{spec,test}.{js,jsx,ts,tsx}",
      ],
    },
    {
      ...commonSettings,
      displayName: "E2E Tests (Jest + Playwright)",
      testMatch: [
        "<rootDir>/*{__tests__,tests,test}/e2e/**/*.{spec,test}.{js,jsx,ts,tsx}",
      ],
      // preset: "jest-playwright-preset",

      ...presets["jest-playwright-preset"],
    },
  ],
};
