Last Updated: February 25, 2016
·
818
· jigsaw

How to switch test environment in Heroku

I am writing a code to Heroku for exclusively these days.I use the foreman when debugging in the local environment, but it is inconvenient if do not switch the test environment.

foreman is be able to select Procfile and .env at startup.

Create testProcfile like that.

test: npm test

Create .env like that.

TEST_VAL=TEST

Then

foreman start --env .testenv --procfile testProcfile

And I started with a set of these. It is a good idea to go out where reasonable values ​​in test environment and debugging environment. (For example, such as the destination of DB)

最近はもっぱら Heroku 向けにコードを書いています。ローカル環境でデバッグするときには foreman を使うのですが、テスト環境を切り替えられないと不便です。

調べてみると、 foreman は起動時に Procfile.env を選択できるようです。

test: npm test

のような testProcfile を作成し、

TEST_VAL=TEST

のような .testenv を用意します。そして、

foreman start --env .testenv --procfile testProcfile

とすると、これらの設定で起動してくれます。デバッグ環境とテスト環境で値が変わる部分は外出ししておくと便利です。(たとえばDBの接続先とか)