我有一个通过 Jest 进行工作测试的 nestjs monorepo 应用程序。这与全局单元测试有关,它们从 package.json 中的 nestjs CLI 创建的配置中获取配置。
我的 storage.service.ts 使用jimp
其中一种方法来调整图像大小。
这具有@jimp/types
依赖于@jimp/gif
哪个依赖于gifwrap
.
对于在我的控制台中运行的每个测试,我都会看到以下错误:
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at node_modules/.pnpm/gifwrap@0.9.2/node_modules/gifwrap/src/gifcodec.js:7:15
我还使用 beforeAll() 和 afterAll() 钩子来关闭 nestjs 模块。
笑话配置:
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "./coverage",
"testEnvironment": "node",
"roots": [
"<rootDir>/apps/",
"<rootDir>/libs/"
],
"moduleNameMapper": {
...
我怎样才能消除这个错误,或者甚至像修复它一样大胆?