Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test database url #40

Open
LawEKS opened this issue Aug 10, 2018 · 0 comments
Open

Test database url #40

LawEKS opened this issue Aug 10, 2018 · 0 comments

Comments

@LawEKS
Copy link

LawEKS commented Aug 10, 2018

Currently your application can only supports a development database.
It is a good idea to supply a test database url to run your tests on.
Otherwise you be deleting any information you add as you are working on the development database

I would do something like this:

// db_connection.js
let DB_URL = process.env.DATABASE_URL;

if (process.env.NODE_ENV === 'test') {
  DB_URL = process.env.TEST_DATABASE_URL;
}

if (!DB_URL) {
  throw new Error('Environment variable DATABASE_URL must be set');
}

const params = url.parse(DB_URL);
# config.env

DATABASE_URL=postgres://admin:doggo@localhost:5432/dogspotting_dev
TEST_DATABASE_URL=postgres://admin:doggo@localhost:5432/dogspotting_test

DB_MAX_CONNECTIONS=4
// package.json

  "scripts": {
    "start": "nodemon server.js",
    "test": "NODE_ENV=test node tests/test.server.js | tap-spec",
    "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
  },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant