-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Package.json file
{
"name": "medusa-test-project",
"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=false --runInBand --forceExit",
"test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
},
"dependencies": {
"@medusajs/admin-sdk": "2.12.2",
"@medusajs/cli": "2.12.2",
"@medusajs/framework": "2.12.2",
"@medusajs/medusa": "2.12.2"
},
"devDependencies": {
"@medusajs/test-utils": "2.12.2",
"@swc/core": "^1.7.28",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.13",
"@types/node": "^20.12.11",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.2.25",
"jest": "^29.7.0",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"vite": "^5.4.14",
"yalc": "^1.0.0-pre.53"
},
"engines": {
"node": ">=20"
}
}Node.js version
22.16.0
Database and its version
PostgreSQL 18.1
Operating system name and version
Windows 11 Pro 25H2
Browser name
No response
What happended?
When placing unit test files (.spec.ts, .test.ts) or tests/ directories inside src/workflows/, the server fails to start during medusa develop.
The ResourceLoader scans all files in src/workflows/ and attempts to load test files at runtime, where Jest globals are not available.
Error:
ReferenceError: jest is not defined
at Object. (src/workflows/my-feature/tests/service.unit.spec.ts:9:1)
Expected behavior
Test files should be excluded from auto-loading.
Patterns to exclude:
- *.spec.ts / *.spec.js
- *.test.ts / *.test.js
- Files inside tests/ directories
Actual behavior
Server crashes with "jest is not defined" because test files containing jest.mock() are loaded outside the Jest test runner context.
The tsconfig.json exclusions don't help since this is runtime module loading, not TypeScript compilation.
Link to reproduction repo
https://github.com/florianhv/medusa-test-files-bug-reproduction