0

I building a boildplate for nestjs and microservices (still work in progress)

now i got an issue that i try to run the app or run the test and it give me this enter image description here

the code located github link the issue that on tsconfig.json i added paths

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist/apps",
    "baseUrl": "./",
    "incremental": true,
    "paths": {
      "@frontapi/*": ["./apps/front-api/src/*"],
      "@config/*": ["./apps/config-server/src/*"],
      "@entities/*": ["./apps/entities-server/src/*"],
      "@devops/*": ["./apps/devops-mcu/src/*"],
      "@tasks/*": ["./apps/task-que-handler/src/*"],
      "@logicBus/*": ["./apps/logic-bus/src/*"],
      "@common/*": ["./apps/common/*"]
    }
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

and i run the package json two of the commands for testing: "start:frontapi": "npm run start:frontapi:env && tsc-watch -p tsconfig.build.json --onSuccess \"node -r tsconfig-paths/register -r ts-node/register --inspect-brk=5858 dist/front-api/src/main.js\"",

and "test:e2e": "npm run clean&&tsc -p tsconfig.build.json && jest --config ./apps/front-api/test/jest-e2e.json",

and both give me that it dont located @common/config/configuration and i have no idea what i have missing here and help with this one

Edit there is file called jest-e2e.json this his content

{
  "moduleFileExtensions": [
    "js",
    "json",
    "ts"
  ],
  "rootDir": ".",
  "testEnvironment": "node",
  "testRegex": ".e2e-spec.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  },
  "moduleNameMapper": {
    "^@frontapi/(.*)$": "./apps/front-api/src/$1",
    "^@config/(.*)$": "./apps/config-server/src/$1",
    "^@entities/(.*)$": "./apps/entities-server/src/$1",
    "^@devops/(.*)$": "./apps/devops-mcu/src/$1",
    "^@tasks/(.*)$": "./apps/task-que-handler/src/$1",
    "^@logicBus/(.*)$": "./apps/logic-bus/src/$1",
    "^@common/(.*)$": "./apps/common/$1"
  }
}

please let me know if i missing something here or you missing something will do my best to provide

2
  • Do you have your paths mapped in your jest.e2e.json config? Commented Feb 11, 2020 at 21:31
  • @JayMcDoniel yap just edit the post show it content Commented Feb 11, 2020 at 22:09

1 Answer 1

0

I was facing the same issue.

After taking a look at your project structure, I have some suggestions/observations. I will focus on apps/front-api.

There you have the jest.e2e.json file inside the test directory

{
  "moduleFileExtensions": ["js", "json", "ts"],
  "rootDir": ".",
  ...,
  "moduleNameMapper": {
    "^@frontapi/(.*)$": "./apps/front-api/src/$1",
    "^@config/(.*)$": "./apps/config-server/src/$1",
    "^@entities/(.*)$": "./apps/entities-server/src/$1",
    "^@devops/(.*)$": "./apps/devops-mcu/src/$1",
    "^@tasks/(.*)$": "./apps/task-que-handler/src/$1",
    "^@logicBus/(.*)$": "./apps/logic-bus/src/$1",
    "^@common/(.*)$": "./apps/common/$1"
  }
}

I'd like to point out that the rootDir: '.' makes reference to the directory the file is in, so in this case rootDir value will be /path/to/your/projectShowCase/backend/apps/front-api/test.

The important thing is that you can use relative paths in the moduleNameMapper. For instance:

  "moduleNameMapper": {
    "^@frontapi/(.*)$": "<rootDir>/../src/$1",
    "^@config/(.*)$": "<rootDir>/../../config-server/src/$1",
    ...,
    "^@common/(.*)$": "<rootDir>/../../common/$1"
  }

You just need to map each dependency to its specific path

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.