我已经启动并运行了k6,但是现在每次尝试运行测试时,都会出现此错误:ReferenceError:未定义regeneratorRuntime。
我曾尝试安装和导入babel,有人建议这样做,但没有成功。
import http from "k6/http";
import { check } from "k6";
async function registerHandlers() {
const dataForBody = 'client_id=LoadTesting&grant_type=client_credentials&' +
`scope=${encodeURI('StitchApi')}&` +
`client_secret=${encodeURI(process.env.REACT_APP_CLIENT_SECRET)}`;
const messageHeaders = {
'Content-Type': 'application/x-www-form-urlencoded',
};
axios({
method: 'post',
url: process.env.REACT_APP_STITCH_AUTH_URL,
headers: messageHeaders,
data: dataForBody,
}).then((response) => {
return response;
}).catch((error) =>
global.console.log('axios error: ', error)
)
}
// const queries = JSON.parse(open("./easygraphql-load-tester-queries.json"));
const url = "https://mywebsite.net/Api/GraphQL/";
const authorization = registerHandlers();
console.log("AUTH!!!!!!", authorization);
const payload = JSON.stringify({
query: `
{
student(id: "5asdfasdfasdfasdf") {
name
}
}
` });
const params = {
headers: {
"authorization": "asdfasdfasdfasdfasdfasdfasdf",
"content-type": "application/json",
}
}
export default function () {
// console.log('query: ', queries);
let res = http.post(url, payload, params);
check(res, {
"status is 200": (r) => r.status === 200,
"is authenticated": (r) => r.json().authenticated === true,
"is correct user": (r) => r.json().user === "user",
"caption is correct": (r) => r.html("h1").text() == "Example Domain",
});
};
我只希望我的负载测试正常工作!
编辑:
我正在使用
"@babel/core": "^7.4.0",
我的babel.rc文件如下:
{
"presets": [ "es2015", "stage-0" ]
}
答案 0 :(得分:1)
我看到您正在使用Promises,但目前k6没有an event loop。因此,您的代码将无法正常工作,不幸的是,Babel在这里没有帮助:(。
另外,您正在尝试使用axios,但是您不导入它,并且(由于它既不是浏览器也不是节点)它也将(可能)不起作用,因为它将不支持k6。 .js;)。
尽管要使它正常工作,您需要使用k6的http库而不是axios来获得您的授权并且不使用async
。另外global
是特定于node.js的AFAIK>