【发布时间】:2021-08-04 06:59:40
【问题描述】:
我想知道是否有可能获得开玩笑的运行时配置对象或文件路径。
我的用例是在我的自定义匹配器上使用各种运行时配置属性
// ./jest.config.js
const path = require("path");
module.exports = {
prop1: "foo",
prop2: "bar"
};
// my-custom-matcher.js
expect.extend({
matcherName(received: any, pathToFile: string) {
const relativeDir = path.join(runtimeconfigpath, pathToFile); // i need the path to the runtimeconfigpath being used here
const baz = runtimeconfig.foo // or access the config properties like this
}
});
我尝试了各种东西并在文档中进行了挖掘,但我在任何地方都没有看到这个。 我能想到的最接近的替代方案是使用配置全局变量,但如果“预设”和配置扩展发挥作用,这会使事情变得复杂。
任何帮助将不胜感激。
【问题讨论】:
标签: javascript node.js typescript jestjs ts-jest