如何使用 Node.js 应用程序在 Travis CI 中创建真实的实时数据库?

How to create a real live database in Travis CI with a Node.js app?

我有一个 open source project,它使用 Node.js、Knex.js、PostgreSQL 和 Travis CI。我目前正在编写集成测试来测试数据库连接并实现存储库模式。我的测试不会 运行 在 Travis CI.

此问题已在 documentation, but my scenario requires that specific tables exist in order for my tests to run. My database project 中简要解决,将使用 node app.js 命令自行创建。我已经将其作为依赖项在本地进行了测试; npm 正确安装依赖项并创建数据库。

然而,尽管脚本在 Travis CI 上成功 运行ning(here 是我的 .travis.yml),mocha(通过 npm test) 继续说找不到我创建的用户。

我已按照 this SO question 中概述的步骤进行操作,但无济于事。 Travis CI 似乎忽略了 config/database.yml 文件并且没有任何效果。

熟悉此 CI 过程的任何人都可以帮忙吗?我真的很想启动数据库管道并 运行ning。我宁愿避免 因为我认为没有必要。应该有一种方法告诉 Travis CI 创建数据库用户、数据库,并保持连接足够长的时间以 运行 集成测试。

已更新 .travis.yml(构建成功,测试通过):

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

等等等——对于此模式,仅 运行 SQL 脚本直接来自 psql on Travis CI 的 bash 环境。