gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:00:05 25 4
gpt4 key购买 nike

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

此问题在 documentation 中有简要说明。 ,但我的方案要求存在特定表才能运行我的测试。我的database project将使用 node app.js 命令创建自己。我已经将其作为依赖项在本地进行了测试; npm 安装依赖项没有错误,并创建了数据库。

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

success_failure

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

熟悉这个 CI 过程的人可以帮忙吗?我真的很想启动并运行数据库管道。我宁愿避免 running Travis CI locally因为我认为没有必要。应该有一种方法告诉 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

等等等——对于这种模式,只需在 Travis CI 的 bash 环境中直接从 psql 运行 SQL 脚本。

关于node.js - 如何使用 Node.js 应用程序在 Travis CI 中创建真实的实时数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32849262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com