0%

持续集成

参考

资源

travis-ci 持续集成

示例

.travis.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
language: node_js
cache:
directories:
- ~/.npm
notifications:
email: true
node_js:
- 'node'
- 'lts/*'
install: npm install
before_install:
- npm install -g npm@5
- npm install -g greenkeeper-lockfile@1
jobs:
include:
- stage: test
script:
- npm run build
- npm run build:prod
- npm run lint:fix
- npm run test
- npm run report-coverage
before_script: greenkeeper-lockfile-update
after_script: greenkeeper-lockfile-upload
- stage: deploy
node_js: 'node'
if: branch = master
script:
- npm run deploy

生命周期

使用 jest 生成代码覆盖率报告, 并用 codecov 上传

安装

1
npm i test -D
1
npm install codecov --save-dev

jest.config.js

1
2
3
4
5
6
7
8
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
collectCoverage: true,
testEnvironment: 'node',
testMatch: ['<rootDir>/__tests__/**/*spec.js']
}

package.json

1
2
3
4
5
6
{
"scripts": {
"test": "jest",
"report-coverage": "codecov"
},
}

.travis.yml

1
2
3
script:
- npm run test
- npm run report-coverage