Reputation: 2952
I have an open source project that uses Node.js, Knex.js, PostgreSQL, and Travis CI. I'm currently writing integration tests to test the database connection and implement the repository pattern. My tests will not run on Travis CI.
This problem is briefly addressed in the documentation, but my scenario requires that specific tables exist in order for my tests to run. My database project will create itself with the node app.js
command. I've tested this locally as a dependency; npm
installs the dependency without errors and the database gets created.
However, despite the script successfully running on Travis CI (here is my .travis.yml
), mocha
(by way of npm test
) goes on to say that it cannot find the user I created.
I've followed the steps outlined in this SO question, to no avail. Travis CI seems to ignore the config/database.yml
file and it has no effect.
Will anyone familiar with this CI process please help? I really want to get the database pipeline up and running. I'd prefer to avoid running Travis CI locally because I just don't think it's necessary. There should be a way to tell Travis CI to create the database user, the database, and keep the connection alive long enough to run the integration tests.
Upvotes: 1
Views: 1826
Reputation: 2952
Updated .travis.yml
(build succeeds, tests pass):
language: node_js
node_js: "0.12"
addons:
postgresql: "9.4"
before_script:
- psql -U postgres -d postgres -a -f ./node_modules/navaja-sql/machete-db-user.sql
- export PGPASSWORD="replace_me"
- psql -U machetedb_app_user -d postgres -a -f ./node_modules/navaja-sql/machete-db.sql
- psql -U machetedb_app_user -d machetedb -a -f ./node_modules/navaja-sql/machete-employer.sql
etc. etc. -- for this pattern just run the SQL scripts directly from psql
on Travis CI's bash environment.
Upvotes: 2