当我尝试使用此模块进行测试时,它给了我以下错误:
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)
开玩笑的配置文件是:
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"testEnvironment": "node",
"moduleDirectories": ["node_modules", "src"],
"moduleNameMapper": {
"src/(.*)": "<rootDir>/../src/$1"
}
}
app.module 文件:
@Module({
imports: [
...,
GraphQLFederationModule.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 {}
当我在 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_modules (minimal.js) 中找到了以下 protobufjs 代码:
// minimal library entry point.
"use strict";
module.exports = require("./src/index-minimal");
有谁知道可能会发生什么?谢谢!