【问题标题】:ReferenceError: process is not definedReferenceError:未定义进程
【发布时间】:2023-03-07 21:15:01
【问题描述】:

我正在运行 k6 测试并为某些代码使用环境变量。我不断收到这个该死的错误:

ReferenceError: 进程未定义

我尝试过使用 __ENV.yadda 在类似问题中建议的替代方案,但没有奏效。

import http from "k6/http";

let formData = {
  client_id: "LoadTesting",
  grant_type: "blah_blah",
  scope: "Scope",
};
const messageHeaders = {
  'Content-Type': 'Client Type',
};

let user = null;
export function authorizeUser() {
  formData.client_secret = process.env.REACT_APP_CLIENT_SECRET;
  if (!user) {
    let res = http.post(`https://localhost:44341/connect/token`, formData, { headers: messageHeaders });
    if (res.status != 200) {
      console.log('res: ', res.status);
      throw new Error("couldn't load user");
    }
    user = JSON.parse(res.body).access_token;
    return user;
  }
}

我只想让我的环境变量工作!

【问题讨论】:

    标签: javascript process environment-variables


    【解决方案1】:

    k6 中的环境变量的工作方式与 Node.js 不同,请尝试以下操作: https://k6.io/docs/using-k6/environment-variables

    【讨论】:

      猜你喜欢
      • 2022-08-14
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 2022-07-17
      • 2022-09-27
      • 2015-12-07
      • 2017-05-12
      • 1970-01-01
      相关资源
      最近更新 更多