2013-10-14 3 views
2

이 자동화 된 단위 테스트 malarkey를 배우려고합니다. Grunt를 사용하여 자동으로 Mocha 테스트를 실행하고 테스트 결과를 파일로 출력하고 싶습니다. 내가 할 수있는 한, grunt-mocha-cov을 사용해야합니다. 나는 일종의 일을했습니다. 테스트가 그루트를 통과하면 결과 파일을 씁니다. 확인을 누릅니다. 그러나 그들 중 하나가 실패하면 나는 이것을 얻는다 :테스트 실행이 실패 할 때 모카를 실행합니다.

Running "mochacov:all" (mochacov) task 
Warning: Use --force to continue. 

Aborted due to warnings. 

파일이 생성되지 않는다. 아무도 내가 잘못 가고 있다고 말할 수 있습니까?

내 프로젝트의 다음과 같은 구성 :

enter image description here

내 테스트 폴더는 다음과 같습니다 하나의 파일, test.js, 포함

:

var chai = require("chai"), 
    assert = chai.assert, 
    expect = chai.expect; 

    var foobar = { 
     sayHello: function() { 
     return 'Hello World!'; 
     } 
    } 

    describe('Foobar', function() { 
     describe('#sayHello()', function() { 
     it('should work with assert', function() { 
      assert.equal(foobar.sayHello(), 'Hello World!'); 
     }); 
     it('should work with expect', function() { 
      expect(foobar.sayHello()).to.equal('Hello Worlxd!'); 
     }); 
     }); 
    }); 

package.json이있다을

{ 
    "name": "GruntTest", 
    "version": "0.0.1", 
    "private": true, 
    "devDependencies": { 
    "grunt": "~0.4.1", 
    "grunt-mocha-cli": "~1.3.0", 
    "grunt-contrib-qunit": "~0.3.0", 
    "grunt-contrib-jshint": "~0.6.4", 
    "grunt-mocha": "~0.4.1", 
    "should": "~2.0.1", 
    "chai": "~1.8.1", 
    "grunt-mocha-cov": "0.0.7" 
    }, 
    "description": "Grunt Test", 
    "main": "grunt.js", 
    "dependencies": { 
    "grunt": "~0.4.1" 
    }, 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "BSD" 
} 

여기 내 Gruntfile.js가 있습니다.

module.exports = function(grunt) { 

    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    mochacov: { 
     options: { 
     reporter: 'XUnit', 
     require: ['should'], 
     output: 'test-results.xml', 
     bail: false 
     }, 
     all: ['test/*.js'] 
    } 
    }); 

    grunt.loadNpmTasks('grunt-mocha-cov'); 
    grunt.registerTask('default', ['mochacov']); 

}; 

편집

는 자비의 조언에 따라 나는 mochacov과 xUnit의 파일 기자로 일하고 있어요. 여기에 다른 나의 새로운 개선 Gruntfile, 경우에 유용에 사람의 : 단말기가 경고를 제공

module.exports = function(grunt) { 

    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    mochacov: { 
    options: { 
     reporter: 'xunit-file', 
     require: ['should'], 
     bail: false 
    }, 
    all: ['test/*.js'] 
    } 
    }); 

    grunt.loadNpmTasks('grunt-mocha-cov'); 
    grunt.registerTask('default', ['mochacov']); 

}; 

"이 때문에 경고를 중단되었습니다"하지만 mochacov는 시험 결과와 파일 xunit.xml을 만듭니다.

답변

1

시도 하나 : https://github.com/yaymukund/grunt-simple-mocha

다음 기자 중 하나

이 같은 http://visionmedia.github.io/mocha/#reporters

또는 무언가 : https://github.com/peerigon/xunit-file

하지만 진실은 서버 측에서 꿀꿀 도랑해야하고, Makefile을 사용하십시오! 여기

내가 사용하는 고전 하나입니다

MOCHA="node_modules/.bin/mocha" 
_MOCHA="node_modules/.bin/_mocha" 
JSHINT="node_modules/.bin/jshint" 
ISTANBUL="node_modules/.bin/istanbul" 

TESTS=$(shell find test/ -name "*.test.js") 

clean: 
    rm -rf reports 

test: 
    $(MOCHA) -R spec $(TESTS) 

jshint: 
    $(JSHINT) src test 

coverage: 
    @# check if reports folder exists, if not create it 
    @test -d reports || mkdir reports 
    $(ISTANBUL) cover --dir ./reports $(_MOCHA) -- -R spec $(TESTS) 

.PHONY: clean test jshint coverage 

단지 dev에 종속 등의 모카, jshint와 이스탄불을 설치, 그것을 그리고 어떤 사람들은 설치하는 당신을 말할 것이다 당신은

을 갈 수 있어요 이 도구들은 모두 globaly이지만, 여러분에게 달렸습니다.

+0

감사합니다. xavier - grunt-simple-mocha가 콘솔로 출력하는 중입니다. xunit-file이 작동하는 데 문제가 있습니다. 나는 계속 노력할 것이다. –

+0

지난 번 서버 쪽에서 grunt를 사용했을 때 다음과 같았습니다. https://github.com/xseignard/rss-unify/tree/a560641050a3e8e06bb040220e53feff83a1003d/server보세요 –

+0

고맙습니다. Xavier 님, 제가 mochacov와 함께 작업하게되었습니다! –

관련 문제