Postman & Newman - cookieJar.getAll() 需要回调函数

Postman & Newman - cookieJar.getAll() requires a callback function

我正在尝试调用 graphql 并从 cookie 中获取数据,它 运行 在 postman 应用程序中运行良好。但是,当我尝试使用 Newman

在命令行上 运行 这个邮递员集合时

在终端中: newman run postman_collection.json -e environment.json

然后它给了我错误

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, 
or by rejecting a promise which was not handled with .catch(). 
The promise rejected with the reason "TypeError: CookieJar.getAll() requires a callback function".] 
{
  code: 'ERR_UNHANDLED_REJECTION'
}

而测试脚本代码是这样的

pm.test("Get a test data", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.data.createTest.success).to.eql(true);
});

pm.test("Test data cookies set", async function () {
    const cookieJar = pm.cookies.jar();
    const url = pm.environment.get("service-url");
    const cookies = await cookieJar.getAll(url);
    const cookieNames = cookies.map(cookie => cookie.name);
    pm.expect(cookieNames).to.include("test-token");
    pm.expect(cookieNames).to.include("legacy-test-token");
});

所以我假设错误是因为 getAll() 需要一个回调函数,你知道我做错了什么吗?我该如何改进它,你能帮我解决这个问题吗?非常感谢

'it runs well in postman app' --> 我怀疑。我试过了,它总是通过。

我添加了回调,还更改了 Postman GUI 中的设置 Whitelist Domain

pm.test("Test data cookies set", function () {
    const cookieJar = pm.cookies.jar();
    const url = pm.environment.get("service-url");
    cookieJar.getAll(url, (error, cookies)=> {
        if(error) console.log(error);
        
        const cookieNames = cookies.map(cookie => cookie.name);
        pm.expect(cookieNames).to.include("test-token");
        pm.expect(cookieNames).to.include("legacy-test-token");
    });
    
});