将 postgresql 添加到我的应用程序后,每次我在 travis 上运行测试时,我都会收到一条错误消息,指出当我在 travis.yml 中运行 database.js 时,数据库不存在。 但我的测试在本地通过 这是我的 .yml 文件
services:
- postgresql
before_script:
- travis_wait 30 yarn install
- "psql -c 'create database myDiary;' -U postgres"
- travis_wait npm install
- node build/models/database.js
这是我在 database.js 中的连接
const connectionString = 'postgres://postgres:password@localhost:5432/myDiary';
const client = new pg.Client(connectionString);
client.connect();
附件是我的travis输出
Travis CI 错误输出
最佳答案
Travis 没有创建 myDiary 数据库,因为整行都被字符串化了。只有 -c 后面的命令应该是一个字符串。
services:
- postgresql
before_script:
- travis_wait 30 yarn install
- psql -c 'create database myDiary;' -U postgres
- travis_wait npm install
- node build/models/database.js
关于node.js - 创建后 Postgresql 数据库在 travis ci 中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51569499/