0

我正在尝试使用 supertest-with-proxy 测试 API,如下所示。由于错误:ECONNREFUSED:连接被拒绝,它们都失败了。

测试1:

import supertest from "supertest-with-proxy";
import { expect } from "chai";
var config = require("../../TestData/api_config.js");
const request = supertest(config.URL2);
    
describe('cdcapi', () => {
it('healthcheck' , function () {
  request 
  .get(`/get/healthcheck`)
  .proxy(process.env.HTTPS_PROXY)
  .set('Authorization', `Bearer ${config.TOKEN}`)
  .end((err,res)=> {
  console.log("I am here :) ")
  console.log(err);
  expect(res.status).to.be.eq(200);
  });
});
})
 

测试 2:

describe('cdcapi3', function() {
  it('healthcheck', function(done) {
    request
      .get('/get/healthcheck')
      .proxy(process.env.HTTPS_PROXY)
      .set('Authorization', `Bearer ${config.TOKEN}`)
      .expect('Content-Type', /json/)
      .expect(200, done)
      .end((err,res)=> {
        console.log("I am here 3 :) ")
         console.log(err);
       });
  });
});

测试 3:异步

describe('cdcapi2', async () => {
  it('healthcheck' , async () => {
      await request 
      .get(`/get/healthcheck`)
      .proxy(process.env.HTTPS_PROXY)
      .set('Authorization', `Bearer ${config.TOKEN}`)
      .end((err,res)=> {
       console.log("I am here :) ")
        console.log(err);
        expect(res.status).to.be.eq(200);
      });
  });
})

包.json:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},

我如何运行: npx wdio --suite cdcapi

错误:

[0-0] I am here :) 
[0-0] Error: ECONNREFUSED: Connection refused
[0-0] at Test.assert (C:\<....>\node_modules\supertest-with-proxy\lib\test.js:166:15)


cdcapi2 healthcheck
ECONNREFUSED: Connection refused
Error: ECONNREFUSED: Connection refused
    at Test.assert (C:\testframework\node_modules\supertest-with-proxy\lib\test.js:166:15)
    at localAssert (C:\testframework\node_modules\supertest-with-proxy\lib\test.js:132:12)
    at C:\testframework\node_modules\supertest-with-proxy\lib\test.js:129:5
    at Test.Request.callback (C:\testframework\node_modules\supertest-with-proxy\node_modules\superagent\lib\node\index.js:728:3)
    at ClientRequest.<anonymous> (C:\testframework\node_modules\supertest-with-proxy\node_modules\superagent\lib\node\index.js:647:10)
    at Object.onceWrapper (events.js:421:26)

我尝试浏览其他类似的帖子,但找不到解决方案。提前致谢!!

4

0 回答 0