我之前运行了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" ]
}