Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Integration Tests fail to import custom files #10698

Open
Avia-Code opened this issue Dec 23, 2024 · 0 comments
Open

[Bug]: Integration Tests fail to import custom files #10698

Avia-Code opened this issue Dec 23, 2024 · 0 comments

Comments

@Avia-Code
Copy link
Contributor

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.1.2^",
    "@medusajs/framework": "2.1.2^",
    "@medusajs/medusa": "2.1.2^",
    "@medusajs/cli": "2.1.2^",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@mikro-orm/cli": "5.9.7",
    "@swc/jest": "^0.2.36",
    "@medusajs/test-utils": "2.1.2^",
    "@types/jest": "^29.5.13",
    "jest": "^29.7.0",
    "@types/node": "^20.0.0",
    "@swc/core": "1.5.7",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v20.16.0

Database and its version

PostgreSQL 15.3-alpine

Operating system name and version

MacOS Sonoma 14.3

Browser name

No response

What happended?

When running integration tests with the command:
yarn test:integration:http
the following error occurs:

 FAIL  integration-tests/http/health.spec.ts (7.517 s)
    Ping
      ✕ ping the server health endpoint (262 ms)

  ●  › Ping › ping the server health endpoint

    Cannot find module 'src/workflows/link-order-to-store' from 'src/subscribers/order-placed.ts'

    Require stack:
      src/subscribers/order-placed.ts
      node_modules/@medusajs/utils/dist/common/dynamic-import.js
      node_modules/@medusajs/utils/dist/common/index.js
      node_modules/@medusajs/utils/dist/auth/token.js
      node_modules/@medusajs/utils/dist/auth/index.js
      node_modules/@medusajs/utils/dist/index.js
      node_modules/@medusajs/framework/dist/utils/index.js
      node_modules/@medusajs/test-utils/dist/init-modules.js
      node_modules/@medusajs/test-utils/dist/index.js
      integration-tests/http/health.spec.ts

The integration test fails to resolve the path for src/workflows/link-order-to-store when imported in src/subscribers/order-placed.ts.

However, the issue does not occur when running the project using:
yarn dev

or when building the project with:
yarn build

Changing the import statement in src/subscribers/order-placed.ts from:
import { linkOrderToStoreWorkflow } from "src/workflows/link-order-to-store";

to:
import { linkOrderToStoreWorkflow } from "../workflows/link-order-to-store";
resolves the issue, and the integration tests pass successfully.

This problem is also reproducible with other files and imports using absolute paths.

Expected behavior

The integration tests should resolve modules using absolute imports (e.g., src/...) without errors, consistent with how the project runs via yarn dev and yarn build.

Actual behavior

Integration tests fail to resolve modules imported using absolute paths, resulting in a "Cannot find module" error. Changing the imports to relative paths resolves the issue.

Link to reproduction repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant