4

We'd like to run supertest-fetch's tests on Heroku before each release.

Example test:

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);
    });
});

Procfile:

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

Running that test on Heroku fails with

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: 

I don't know why supertest-fetch makes request for https and even if it made request for http, I don't think Heroku allows arbitrary ports to serve. Did anybody succeed at running supertest's tests on Heroku?

Dread Boy
  • 772
  • 6
  • 28

1 Answers1

1

Right now super-fetch is making a request to localhost:443 (this is probably configured in your FetchFunction or makeFectch file) which won't work in your Heroku environment. You if you know the publicly exposed dns target of the service you'd like to test, you can add that to your configuration instead. Alternatively, if you'd like to be a bit more dynamic you could probably use the dyno metadata to put together a valid and public url.

RangerRanger
  • 2,455
  • 2
  • 16
  • 36