node.js - 在 Azure 函数(Nodejs)中使用 Jest 进行测试时未定义 process.env 变量
问题描述
process.env
运行时显示未定义的变量yarn run jest
。我已将每个配置变量存储在我的local.settings.json
文件中,并且它在正常调试中运行良好。
我的代码是这样的:
local.settings.json
:
{
"IsEncrypted": false,
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"Values": {
"IOTHUB_CONNECTION_STRING": "xxxxxxxxxxxxxxxxxx",
"AZURE_DEVOPS_URL": "xxxxxxxxxxxxxxxxxxxx"
}
}
jest.config.js
:
module.exports = {
log: jest.fn(),
}
天蓝色 httptrigger 功能 - index.js
:
const iothubConnectionString = process.env["IOTHUB_CONNECTION_STRING"];
console.log( iothubConnectionString ) //undefined
由于这些配置变量,我的测试失败了。我需要通过考试。任何人都可以请帮助我。
解决方案
local.settings.json
特定于 Azure Functions 核心工具。只要您使用 Core Tools CLI 运行该函数,您就可以通过 process.env 访问此文件中定义的环境变量
推荐阅读
- node.js - Nginx 提供与 VueJS 应用程序分开的登录页面
- python - Aioredis 不支持 3.5 之前的 python 版本
- python - 我有两个矩阵已转换为灰度图像,我想找到它们之间的平均 SSIM 值(python)
- ios - UITextView - 启用听写警报很快消失
- gcc - 可以将 gcc 配置为编译代码的位置无关代码但数据的位置相关代码吗?
- python - Python - 需要帮助将字典字典写入 CSV 文件
- typescript - componentDidMount() 中的 Async Await API 调用突然失败/超过超时?反应原生。还原。打字稿
- python - 根据列值复制行
- python - 使用 matplotlib 将 2D 直方图投影到一个轴
- php - 使用 jquery ajax 和 php 逐个加载部分