【问题标题】:Running supertest-fetch's test on Heroku在 Heroku 上运行 supertest-fetch 的测试
【发布时间】:2018-11-03 15:08:28
【问题描述】:

我们希望在每次发布之前在 Heroku 上运行 supertest-fetch 的测试。

示例测试:

import {FetchFunction, makeFetch} from 'supertest-fetch';
import {koa} from '../koa';
import {Server} from 'http';

describe('User controller', () => {

    let fetch: FetchFunction;
    let server: Server;
    beforeAll(() => {
        server = koa.listen(3101);
        fetch = makeFetch(server);
    });

    afterAll(() => {
        server.close();
    });

    it('GET /users should return 200', async () => {
        const response = await fetch('/users');
        expect(response.status).toEqual(200);
    });
});

过程文件:

release: npm test && node db-tools/apply-migrations.js

在 Heroku 上运行该测试失败

remote: FAIL src/controller/user.spec.ts (5.506s)        
remote:   User controller              
remote:     ✕ GET /users should return 200 (48ms)        
remote: 
remote:   ● User controller › GET /users should return 200        
remote: 
remote:     FetchError: request to https://localhost/users failed, reason: connect ECONNREFUSED 127.0.0.1:443        
remote: 
remote:       at ClientRequest.<anonymous> (node_modules/node-fetch/lib/index.js:1345:11)        
remote: 

我不知道为什么 supertest-fetch 请求 https,即使它请求 http,我认为 Heroku 不允许任意端口提供服务。有人成功在 Heroku 上运行 supertest 的测试吗?

【问题讨论】:

    标签: heroku supertest


    【解决方案1】:

    现在super-fetch 正在向localhost:443 发出请求(这可能在您的FetchFunctionmakeFectch 文件中配置)在您的Heroku 环境中不起作用。如果您知道要测试的服务的公开 dns 目标,则可以将其添加到您的配置中。或者,如果您想更有活力,您可以使用the dyno metadata 来组合一个有效的公共网址。

    【讨论】:

      猜你喜欢
      • 2011-04-10
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多