Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

2.6 KB
Raw Blame
const path = require("path")

const { loadEnv } = require("@medusajs/framework/utils")
loadEnv("test", process.cwd())

module.exports = {
  transform: {
    // Mercur patches shipped core-flows cart, order and payment files and the
    // order module's repository utils. Jest never
    // consults Node's module hooks, so without this the patches are inert under
    // test and the suite silently exercises unpatched code.
    "node_modules[\\\\/].*(core-flows[\\\\/]dist[\\\\/](cart|order|payment)|order[\\\\/]dist[\\\\/]utils)[\\\\/].*\\.js$":
      "@mercurjs/core/patches/jest-transformer",
    "^.+\\.[jt]s$": [
      "@swc/jest",
      {
        jsc: {
          parser: { syntax: "typescript", decorators: true },
          target: "es2021",
        },
      },
    ],
  },
  testEnvironment: "node",
  // Everything in node_modules is left untransformed except the core-flows cart,
  // order and payment files the patches target, and the ESM-only htmlparser2
  // chain that sanitize-html require()s (Jest can't load ESM through require).
  transformIgnorePatterns: [
    "/node_modules/(?!.*(core-flows[\\\\/]dist[\\\\/](cart|order|payment)|order[\\\\/]dist[\\\\/]utils)[\\\\/]|(?:.*[\\\\/])?(htmlparser2|domhandler|domutils|domelementtype|dom-serializer|entities)[\\\\/]dist[\\\\/])",
  ],
  moduleFileExtensions: ["js", "ts", "json"],
  modulePathIgnorePatterns: ["dist/"],
  setupFiles: [path.join(__dirname, "setup.js")],
  // Balance `--shard` partitions by estimated duration instead of file count
  // so heavy specs don't cluster in one shard and blow the job timeout.
  testSequencer: path.join(__dirname, "test-sequencer.js"),
}

if (process.env.TEST_TYPE === "integration:http") {
  module.exports.testMatch = ["**/http/**/*.spec.[jt]s"]
  // The meilisearch specs exercise routes/modules that ship in the
  // `@mercurjs/registry` block, which is only wired into the test app when
  // MEILISEARCH_HOST is set (see the dedicated test:integration:meilisearch
  // script). Without it the routes 404, so skip them in the default HTTP run.
  if (!process.env.MEILISEARCH_HOST) {
    module.exports.testPathIgnorePatterns = ["/node_modules/", "/http/meilisearch/"]
  }
} else if (process.env.TEST_TYPE === "integration:modules") {
  module.exports.testMatch = ["**/src/modules/*/__tests__/**/*.[jt]s"]
} else if (process.env.TEST_TYPE === "unit") {
  // Unit specs live next to the source they cover, in the workspace packages
  // rather than here, so the run is rooted at the repo.
  module.exports.rootDir = path.join(__dirname, "..")
  module.exports.testMatch = [
    "**/packages/core/src/**/__tests__/**/*.unit.spec.[jt]s",
  ]
}