NODE_ENV和Jest [英] NODE_ENV with Jest

查看:185
本文介绍了NODE_ENV和Jest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从摩卡咖啡迁移到Jest.我的测试将导入"config"包,该包将根据NODE_ENV变量选择一个配置文件或其他配置文件.但是,从Jest运行测试时,看起来好像是在配置中找到了NODE_ENV变量

I am migrating from Mocha to Jest. My test import the 'config' package, which selects a configuration file or another depending on the NODE_ENV variable. However, it looks like NODE_ENV variable is found by config while running the test from Jest

下一行不起作用(即NODE_ENV被忽略):

Next line does not work (that is, NODE_ENV is ignored):

 NODE_ENV=test jest test/*.js --notify --config jest.config.json

因此,"config"包会报告:

As a consequence the 'config' package reports:

console.error node_modules/config/lib/config.js:1727
WARNING: NODE_ENV value of 'test' did not match any deployment config file names. 

您知道如何包含NODE_ENV吗?

Do you know how to include NODE_ENV?

推荐答案

Jest自动将环境变量NODE_ENV定义为test(请参见

Jest automatically defines environment variable NODE_ENV as test(see https://jestjs.io/docs/en/getting-started.html), as you can confirm from your error message:

console.error node_modules/config/lib/config.js:1727
WARNING: NODE_ENV value of 'test' did not match any deployment config file names. 

您可以做的就是简单地创建config/test.json并包含内容{},这是一个空的有效JSON对象.

What you can do is simply create config/test.json and include the contents {}, which is an empty valid JSON object.

请参见 https://github.com/lorenwest/node-config/wiki /严格模式

注意:当您使用 config 时,发生上述错误.包,与此同时,您在config目录中没有test.json文件.

Note: the aforementioned error occurs when you use the config package, and meanwhile you don't have the test.json file in the config directory.

这篇关于NODE_ENV和Jest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆