Node.js Nock、Async/Await、Bitbucket:在Chai开始断言之前不会返回截获

Node.js Nock、Async/Await、Bitbucket:在Chai开始断言之前不会返回截获,node.js,async-await,bitbucket,chai,nock,Node.js,Async Await,Bitbucket,Chai,Nock,我有一个进行外部API调用的端点 //outside.js const createTicket = async () => { try{ const someOptions = { /*stuff here*/} results = await rp.post('https://xcxxx.zendesk.api.com/request.json', someOptions) return results; }catch(e)

我有一个进行外部API调用的端点


//outside.js
const createTicket = async () => {
    try{
    const someOptions =  { /*stuff here*/}
        results = await rp.post('https://xcxxx.zendesk.api.com/request.json', someOptions)
        return results; 
    }catch(e) {
        return e
    }
}


//router.js
const {createTicket} = required("../outside.js")
router.post("/test", (req, res) => {
    /*do stuff*/
    createTicket();

    return res.status(200).send();
})

//index.js
app.use(require("router.js"));
...


//index.test.js
const server=require("../index.js");  /*test calls index.js, which uses router.js*/
const nock = require("nock");
const chai = require("chai");
/*lots of other requires*/

describe("Should send ticket when POST fails", function(done){
   let ticketNock= nock(`https://xcxxx.zendesk.com`)
                .log(console.log)
                .post('/api/v2/requests.json')
                .reply(200);
    chai.request(server)
                .post("/test")
                .send({info: 'fail this'})
                .then((res) => {

                    expect(ticketNock.isDone()).to.equal(true);


                    nock.restore();
                    nock.cleanAll();
                    done();
                })
                .catch((error) => {
                    done(error);
                })
当我测试
/test
时,我试图使用Nock拦截
https://external.api.com/request.json
。测试在本地顺利通过,但当我将其推到bitbucket并运行管道时,它无法拦截

我猜,
router.js
中的代码没有调用wait

我的问题是,在不更改源代码的情况下,是否可以解决? 间谍和存根可能也不是一种选择


否则,如果有人知道为什么这只会让Bitbucket失败,我也很想听听你的意见。谢谢。

我想说清楚,控制器对
POST/test
的期望是在知道调用外部API是否成功之前做出响应?您的猜测似乎是准确的,您的测试可能是在向外部发出请求之前断言的。我们仍然可以测试这一点,但是,在我们提供反馈之前,我们需要更多关于您的测试的信息。我的假设是,Bitbucket本身不是一个因素,但与您尝试过的其他事情相比,延迟更多。再加上重定向之类的事情可能会增加请求解决所需的时间。@MattR.Wilson,谢谢您的提醒。我已经更新了上面的代码。请让我知道您的想法。为了清楚起见,您的控制器对
POST/test
的期望是,它在知道调用外部API是否成功之前做出响应?您的猜测似乎是准确的,您的测试可能是在向外部发出请求之前断言的。我们仍然可以测试这一点,但是,在我们提供反馈之前,我们需要更多关于您的测试的信息。我的假设是,Bitbucket本身不是一个因素,但与您尝试过的其他事情相比,延迟更多。再加上重定向之类的事情可能会增加请求解决所需的时间。@MattR.Wilson,谢谢您的提醒。我已经更新了上面的代码。请让我知道你的想法。