I have the following code in my gitlab repo
package.json
{
...
"scripts": {
"test": "mocha --require ts-node/register --watch-extensions ts,tsx \"src/**/*.{spec,test}.{ts,tsx}\""
}
...
}
.gitlab-ci.yml
stages:
- test
test:
image: node:8
stage: test
script:
- npm install
- npm run test
test.ts
import { exec } from 'child_process';
import { promisify } from 'util';
const Exec = promisify(exec);
describe(test, async () => {
before(async () => {
// next line doesn't work in GitLab-CI
await Exec(`docker run -d --rm -p 1113:1113 -p 2113:2113 eventstore/eventstore`);
// an so on
})
});
it work well when I run "npm run test" in my local machine.
My Question is how can I run this test in Gitlab-CI?
答案 0 :(得分:1)
如果您尝试运行连接到事件存储库docker的测试,则可以使用gitlab服务:
GitLab CI使用services关键字定义哪些Docker容器 应该与您的基本图片相关联。
首先,您需要设置docker executor
然后,您将可以使用事件存储作为服务。这是example with postgres。更多信息here。
示例:
test_server:
tags:
- docker
services:
- eventstore:latest
script:
- npm install && npm run test
编辑:
要access服务:
该服务的主机名的默认别名是根据其映像名创建的
或使用alias:
services:
- name: mysql:latest
alias: mysql-1