我正在尝试通过 travis-ci 构建我的项目,但是当 travis 尝试通过 mocha 测试项目时发生未知错误。我知道问题不在于mysql,因为连接在那里并且脚本正在运行。
我正在测试使用 - ts-node/register - Mocha - Chai - Chai-http - mySQL(使用池)
该测试在本地运行良好,但在 travis 上却失败了。我在想它可能与 ts-node/register 相关,在 travis 中。
1 - 我已经尝试完全删除测试并且构建已修复。但是当我尝试测试它时,它惨遭失败。
包.json
{
"name": "xxxxxxxxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "ENV='PRODUCTION' node dist/app.js --verbose",
"debug": "node --inspect dist/app.js",
"dev": "ENV='DEVELOPMENT' nodemon src/app.ts --verbose",
"build": "tsc -p .",
"test": "ENV='TEST' mocha -r ts-node/register test/{,dbMappers}/**.test.ts --exit; ",
"test:awesome": "ENV='TEST' mocha -r ts-node/register test/{,dbMappers}/**.test.ts --reporter mochawesome --exit; "
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"app-root-path": "^2.2.1",
"bcrypt": "^3.0.6",
"body-parser": "^1.19.0",
"colors": "^1.3.3",
"cors": "^2.8.5",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mysql": "^2.17.1",
"uuid": "^3.3.2",
"winston": "^3.2.1"
},
"devDependencies": {
"@types/app-root-path": "^1.2.4",
"@types/bcrypt": "^3.0.0",
"@types/body-parser": "^1.17.0",
"@types/chai": "^4.2.0",
"@types/chai-http": "^4.2.0",
"@types/colors": "^1.2.1",
"@types/cors": "^2.8.5",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.0",
"@types/jsonwebtoken": "^8.3.2",
"@types/mocha": "^5.2.7",
"@types/mysql": "^2.15.6",
"@types/node": "^12.6.8",
"@types/uuid": "^3.4.5",
"@types/winston": "^2.4.4",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"mocha": "^6.2.0",
"mochawesome": "^4.1.0",
"nodemon": "^1.19.1",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
}
}
.travis.yml
language: node_js
node_js:
- "stable"
directories:
- "node_modules"
services:
- mysql
cache:
- "node_modules"
before_script:
- mysql -u root -e "CREATE USER 'test'@'localhost' IDENTIFIED BY 'xxxx'"
- mysql -u root -e 'CREATE DATABASE backend;'
- mysql -u root -e 'SHOW DATABASES'
- mysql -u root -e "GRANT ALL ON backend.* TO 'test'@'localhost';"
- npm install
env:
- ENV: 'TEST'
Travis 仓库 https://travis-ci.com/moh682/hbas-system-api
travis 暴露的错误仅此而已。
yyy@1.0.0 test /home/travis/build/xxx/yyy ENV='TEST' mocha -r ts-node/register test/{,dbMappers}/**.test.ts --exit;
xxx = 用户名 | yyy = 回购名称