Tech Tips

  1. Uncategorized
  2. 413 view

[Coffee Script][Jenkins]Measure Coverage with Karma

jenkins nginx

Contents

Karma Setting

Needed Library

{
    "name": "sample",
    "version": "0.0.1",
    "dependencies": {
        "coffee-script": "1.7.1",
        "jasmine-node": "1.14.1",
        "grunt": "0.3.15",
        "requirejs": "2.1.11",
        "karma": "0.12.1",
        "karma-coverage": "0.2.1",
        "karma-jasmine": "0.1.5",
        "karma-coffee-preprocessor": "0.2.1",
        "karma-requirejs": "0.2.1",
        "karma-junit-reporter": "0.2.1",
        "karma-phantomjs-launcher": "0.1.2",
        "karma-nunit-reporter": "0.0.0",
        "cake": "0.1.1"
    }
}

Cakefile Setting

Preparing converter from coffee script to javascript to work Karma.
fs = require 'fs'
path = require 'path'
{spawn, exec} = require 'child_process'

coffee = (args) ->
  proc =         spawn './node_modules/.bin/coffee', args
  proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
  proc.on        'exit', (status) -> process.exit(1) if status != 0

jasmine = (args) ->
  proc =         spawn './node_modules/.bin/jasmine-node', args
  proc.stdout.on 'data', (buffer) -> console.log buffer.toString()
  proc.on        'exit', (status) -> process.exit(1) if status != 0

task 'buildspec', "build source files in './spec' to './lib'", ->
  target = [
    'src/sample1.coffee'
    'src/sample2.coffee'
    'spec/sample1_spec.coffee'
    'spec/sample2_spec.coffee'
  ]
  coffee ['-j','tmpspec','-o','lib','-c'].concat target
  exec 'sleep 1 && cat lib/tmpspec.js | grep -v "exports\." | grep -v "require(" > sample_spec.js', (err) ->
    throw err if err

Karmaのセッティング

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
      'sample_spec.js'
    ],
    browsers: ['PhantomJS'],
    singleRun: true,
    reporters: ['progress', 'coverage'],
    preprocessors: { 'sample_spec.js': ['coverage']},
    coverageReporter: {
      type: 'cobertura',
      dir: 'coverage/'
    }
  });
};

Run Karma

# Make JS for test
./node_modules/cake/bin/cake buildspec
# Execute Karma
./node_modules/karma/bin/karma start karma.conf.js
# Arrange coverage report for Jenkins
cp "coverage/PhantomJS 1.9.7 (Linux)/cobertura-coverage.xml" coverage/

Jenkins Setting

coffee-coverage-jenkins1

Uncategorized recent post

  1. Run Amazon FreeRTOS on M5Stack Core2 for AWS …

  2. Udacity Self-Driving Car Engineer Nanodegree …

  3. Install sbt 1.0.0 and run sample template

  4. Visualization of Neural Network and its Train…

  5. [Machine Learning]Created docker image includ…

関連記事

PAGE TOP