5

I am setting-up Heroku-CI to run integration tests. My goal is to:

  • populate the database with seed data before each test
  • make API calls to the app and check results

I'm having a hard time finding any source on the internet that explains how to connect to the database/make API calls from the test suites.

As explained in the official doc I setted-up my app.json to provision the heroku-postgresql:in-dyno addon: https://devcenter.heroku.com/articles/heroku-ci#provisioning-add-ons-the-addons-key-example

{
  "environments": {
    "test": {
      "addons": [
        "heroku-postgresql:in-dyno"
      ]
    }
  },
  "addons": [
    "heroku-postgresql"
  ],
}

So I am expecting the DATABASE_URL env variable to be defined as explained in the doc: https://devcenter.heroku.com/articles/heroku-ci-in-dyno-databases#usage

I dumped process.env and got (filtered out for clarity):

CI_NODE_INDEX=0
SHLVL=2
PORT=13825
WEB_CONCURRENCY=5
CI_NODE_TOTAL=1
HEROKU_TEST_RUN_COMMIT_VERSION=9d21e06632878c2d23fb4e8f51017d5e87628ac7
STACK=heroku-18
HEROKU_TEST_RUN_ID=e5e28b13-efbe-4ef0-bc50-ed3a041bca04
HEROKU_TEST_RUN_NUMBER=27
NODE_ENV=test
JEST_WORKER_ID=1

DATABASE_URL is not defined. How am I supposed to connect to the database and populate it with seed data?

I am not specifying DATABASE_URL anywhere in the app.json but I do not believe I should, just like review apps.

I also tried to make API calls to my server using the PORT env variable: http://localhost:${process.env.PORT}/graphql but got connect ECONNREFUSED 127.0.0.1:13825

This is puzzling me, any insight would be appreciated!

Nicolas Keller
  • 701
  • 5
  • 8
  • Did you paid attention to this paragraph? It says you must add the "buildpacks" key in the `app.json`: https://devcenter.heroku.com/articles/heroku-ci-in-dyno-databases#usage – Massimiliano Kraus Jan 29 '20 at 22:09

0 Answers0