使用jest setupFiles的绝对路径

u4vypkhs  于 2022-12-08  发布在  Jest
关注(0)|答案(1)|浏览(217)

I am using a monorepo, where my modules are stored mostly one level above the project.
In jest.config.ts , I am defining setupFiles as:

{
   setupFiles: ["<rootDir>/../node_modules/@core/src/setupJest.ts"]
}

I would like to use an absolute path since the library directories could change

{
   setupFiles: ["@core/src/setupJest.ts"]
}

I tried using roots , moduleDirectories , modulePaths to define additional path, but it did not work (this is suggested by a lot of replies to similar questions on S/O, no worked for me).
Does anyone have an idea what else I can do. A bit lost, so will try anything.
Thank you

kkbh8khc

kkbh8khc1#

如果有人感兴趣的话
我通过以下方法解决了这个问题:
1.将sec/setupJest.ts定义为@core库的package.json中的“导出”(setupJest)。
1.使用中

const setupJestFile = require.resolve(‘setupJest’)

解析文件路径。4.在setupFiles中使用setupJestFile变量

相关问题