Github loading guide-Travis CI and Codecov-mycodinglife-segmentfault

Github loading guide-Travis CI and Codecov-mycodinglife-segmentfault

It s been a long time since I wrote a blog, and I took advantage of my free time a year ago to come up with something lighter.
Recently, I have accumulated some Angular components and plan to open source them entirely. Since we want to open source, the reliability of the code is very important. There must be no single test. In order to ensure that the code submitted every time can run well, continuous integration can not be less. I have seen some icons for single test coverage and build results in the introduction of many open source projects, like this:

I think it's pretty cool. I plan to include the entire set in my own open source components.
After Google decided to use TravisCI for continuous integration, Codecov used to count the coverage of single test.

Travis CI

Travis CI is an emerging open source continuous integration construction project abroad and supports the Github project. Very convenient to use.

  1. Log in to Travis CI with Github account ;

  2. Github projects will be automatically synchronized after login, select the projects that need to use Travis CI

  3. Add a .travis.ymlfile in the root directory of the project , with the following content:

# 
language: node_js
# nodejs 
node_js:
  - 0.12.5

# 
script:
  - npm run ci

# 
branches:
  only:
    - master 

See here for more syntax . It is very convenient to use, so that every time you push code to github, Travis CI will automatically run .travis.ymlit script. Automatically compile and run single test.
Since Travis CI runs npm installthe npm package that the installation project depends on before each build , make sure that all dependent packages have been package.jsondeclared in the code when submitting the code , otherwise the build will fail.

Codecov

Codecov is an open source test result display platform that visualizes test results. Many open source projects on Github use Codecov to display single test results.
Like Travis CI, Codecov supports Github account login and will also synchronize projects in Github. To use Codecov in the nodejs environment, you need to install the corresponding npm package, run the following command to install:

npm install codecov --save-dev 

The function of this package is to upload the result file generated by our running single test to Codecov for visual display. At the same time, the result file type supported by codecov is cobertura. Therefore, it is necessary to ensure that the type of the result file of the single test execution is cobertura.
The front-end project carries out karmaa combination of unit test promotion +'jasmine'. Google will know what these two are. The karmasingle test can be run through a simple configuration. The following is a configuration file in one of my projects for your reference:

//Karma configuration
//Generated on Mon Feb 01 2016 21:34:22 GMT+0800 ( )

module.exports = function(config) {
  config.set({

   //base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


   //frameworks to use
   //available frameworks: https://npmjs.org/browse/keyword/karma-adapter
   // jasmine, requirejs 
    frameworks: ['jasmine', 'requirejs'],


   //list of files/patterns to load in the browser
    files: [
       //karma requirejs 
        'test/test-main.js',
       // includeed false js requirejs 
        {pattern: 'node_modules/jquery/dist/jquery.min.js', included: false},
        {pattern: 'node_modules/angular/angular.min.js', included: false},
        {pattern: 'node_modules/angular-mocks/angular-mocks.js', included: false},
        {pattern: 'src/bg-single-selector.js', included: false},
        {pattern: 'test/selector.spec.js', included: false}
    ],


   //list of files to exclude
    exclude: [
    ],


   //preprocess matching files before serving them to the browser
   //available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
   // bg-single-selector.js 
    preprocessors: {
        'src/bg-single-selector.js': 'coverage'
    },


   //test results reporter to use
   //possible values: 'dots', 'progress'
   //available reporters: https://npmjs.org/browse/keyword/karma-reporter
   // 
    reporters: ['progress', 'coverage', 'verbose'],
   // 
    coverageReporter:{
        reporters: [{
            type:'text-summary'
        }, {
            type: 'html',
            dir: 'test/coverage'
        }, {
           // Codecov 
            type: 'cobertura',
            subdir: '.',
            dir: 'test/coverage'
        }]
    },

   //web server port
    port: 9876,


   //enable/disable colors in the output (reporters and logs)
    colors: true,


   //level of logging
   //possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


   //enable/disable watching file and executing tests whenever any file changes
    autoWatch: true,

   //start these browsers
   //available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],
   // 
    plugins: [
        'karma-jasmine',
        'karma-coverage',
        'karma-verbose-reporter',
        'karma-phantomjs-launcher',
        'karma-requirejs'
    ],

   //Continuous Integration mode
   //if true, Karma captures browsers, runs the tests and exits
    singleRun: true
  })
}
 

Unit test through karma, write the command .travis.ymlinto it, you can run single test every time you build, and run at the same timecodecov [cobertura-coverage.xml ] the single test results will be uploaded to Codecov. Running codecov locally will fail. You need to add this process to the build script of Travis CI to upload successfully. Because it will be treated as a private project when running locally, the token provided by Codecov needs to be added when uploading the results for private projects.

Add icon to github

At the last step, both Travis CI and Codecov provide icon links to display the results. We only need to add the icon link to the README of the project to see the result.
For Travis CI, click on the icon in the figure below:


The address of the icon will pop up.
For Codecov, open the project's setting list and you will see it as follows:

Finally, just add the corresponding link to the README file. Here is the final effect:

Isn't it awesome!
Project address: BGSingleSelector , everyone is welcome to try it out, and don t be stingy with Star.

Finally, make an advertisement. Baidu warning platform . This is an intelligent alarm platform that provides real-time and accurate alarm delivery and the ability to co-process faults. No longer need to worry about missing monitoring alarms, liberating operation and maintenance manpower.

Finally, Amway downloads my personal blog, welcome to visit: bin-playground.top