Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jestjs 尝试使用NestJS、Jest和GraphQLFederationModule进行测试时出错_Jestjs_Apollo_Nestjs_Ts Jest_Protobufjs - Fatal编程技术网

Jestjs 尝试使用NestJS、Jest和GraphQLFederationModule进行测试时出错

Jestjs 尝试使用NestJS、Jest和GraphQLFederationModule进行测试时出错,jestjs,apollo,nestjs,ts-jest,protobufjs,Jestjs,Apollo,Nestjs,Ts Jest,Protobufjs,当我尝试使用此模块进行测试时,会出现以下错误: FAIL test/test.e2e-spec.ts (28.561s) AppController (e2e) × test (4555ms) ● AppController (e2e) › test Configuration error: Could not locate module ./src/index-minimal mapped as: C:\absolute\path\server

当我尝试使用此模块进行测试时,会出现以下错误:

 FAIL  test/test.e2e-spec.ts (28.561s)
  AppController (e2e)
    × test (4555ms)

  ● AppController (e2e) › test

    Configuration error:

    Could not locate module ./src/index-minimal mapped as:
    C:\absolute\path\server\company\src\$1.

    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/src\/(.*)/": "C:\absolute\path\server\company\src\$1"
      },
      "resolver": undefined
    }

      at createNoMappedModuleFoundError (../node_modules/jest-resolve/build/index.js:545:17)
      at Object.<anonymous> (../node_modules/@apollo/protobufjs/minimal.js:4:18)
当我在app.module中尝试以下设置时,它工作正常:

@Module({
  imports: [
    ...,
    GraphQLModule.forRootAsync({
      imports: [CustomConfigModule],
      inject: [EnvironmentStateService],
      useFactory: (environmentStateService: EnvironmentStateService) => ({
        introspection: environmentStateService.isDev,
        debug: environmentStateService.isDev,
        playground: environmentStateService.isDev,
        autoSchemaFile: true,
        tracing: environmentStateService.isDev,
      }),
    }),
    ...,
  ],
})
export class AppModule {}
我一直在查看该文件,其中给出了错误,我在node_模块(minimal.js)中发现了以下protobufjs代码:


有人知道会发生什么吗?谢谢大家!

我已将路径改为:“src/folder/…”到“@App/folder/…”,最后效果很好,但我很好奇为什么会发生这种情况,如果有任何解决方案,我会关注可能的解决方案和建议,非常感谢

如果有人想查看解决方案,则如下所示:

tsconfig.json:

{
  "compilerOptions": {
    ...
    "baseUrl": "./",
    "paths": {
      "@App/*": ["src/*"]
    },
    ...
  },
  ...
}
jest配置文件:

{
  "moduleFileExtensions": ["js", "json", "ts"],
  "rootDir": ".",
  "testRegex": ".e2e-spec.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  },
  "testEnvironment": "node",
  "moduleNameMapper": {
    "^@App/(.*)$": "<rootDir>/../src/$1"
  }
}
{
“moduleFileExtensions”:[“js”、“json”、“ts”],
“rootDir”:“,
“testRegex”:“.e2e-spec.ts$”,
“转变”:{
“^.+\.(t|j)s$”:“ts笑话”
},
“测试环境”:“节点”,
“moduleNameMapper”:{
“^@App/(.*)$”:“/../src/$1”
}
}
问候

// minimal library entry point.

"use strict";
module.exports = require("./src/index-minimal");
{
  "compilerOptions": {
    ...
    "baseUrl": "./",
    "paths": {
      "@App/*": ["src/*"]
    },
    ...
  },
  ...
}
{
  "moduleFileExtensions": ["js", "json", "ts"],
  "rootDir": ".",
  "testRegex": ".e2e-spec.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  },
  "testEnvironment": "node",
  "moduleNameMapper": {
    "^@App/(.*)$": "<rootDir>/../src/$1"
  }
}