How to get xml output from running grunt jasmine

I am trying to integrate my test into bamboo. With bamboo, it seems like I need test results in junit xml format. Because of this, I need to execute the "grunt jasmine" execution to output the test results in xml format. I am new to jasmine / grunt / junit and have spent more time than I would like to admit trying to get this to work. I followed various tutorials and tips (mostly https://gist.github.com/asabaylus/3059886 ), but I was just stuck.

When I run "grunt jasmine" from gitbash, the specifications run successfully, but the output file is not generated, and I get the following error ... "Error while processing the template (cannot call the indexO method f 'of undefined). Use -force to continue.

Interrupted due to warnings.

Do I need to change any other files? Can someone help me work this out?

Please thanks! CC

Grunt.js file

/*global module:false*/ module.exports = function ( grunt ) { // Project configuration. grunt.initConfig({ meta: { banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' + '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */' }, lint: { files: ['grunt.js', 'src/**/*.js'] }, jasmine: { all: ['./SpecRunner.html'], junit: { dest: 'test-results' } }, concat: { dist: { src : ['<banner:meta.banner>', '<file_strip_banner:src/buyitnow.js>'], dest: 'dist/buyitnow/<%= meta.version %>/buyitnow.js' } }, min: { dist: { src : ['<banner:meta.banner>', '<config:concat.dist.dest>'], dest: 'dist/buyitnow/<%= meta.version %>/buyitnow.min.js' } }, watch: { files: '<config:lint.files>', tasks: 'lint' }, jshint: { options: { curly : true, eqeqeq : true, immed : true, latedef: true, newcap : true, noarg : true, sub : true, undef : true, boss : true, eqnull : true, browser: true, jquery : true, node : true }, globals: {} }, uglify: {} }); grunt.loadNpmTasks('grunt-jasmine-task'); // Default task. grunt.registerTask('default', 'lint jasmine concat min cssmin');}; 

My specrunner.html file

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Jasmine Spec Runner</title> <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png"> <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script> <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script> <script type="text/javascript" src="lib/jasmine.async.min.js"></script> <script type="text/javascript" src="lib/sinon-1.6.0.js"></script> <!-- For JUnit output of test results include the following link to Lary Myer JUnit reporter --> <script type="text/javascript" src="node_modules/jasmine-reporters/src/jasmine.junit_reporter.js"></script> <!-- include spec files here... --> <script type="text/javascript" src="spec/binSpec.js"></script> <script type="text/javascript"> (function() { var jasmineEnv = jasmine.getEnv(); jasmineEnv.updateInterval = 1000; var htmlReporter = new jasmine.HtmlReporter(); jasmineEnv.addReporter(htmlReporter); // Specify target test results folder as below, for now var junitReporter = new jasmine.JUnitXmlReporter('test-results/'); jasmineEnv.addReporter(junitReporter); jasmineEnv.specFilter = function(spec) { return htmlReporter.specFilter(spec); }; var currentWindowOnload = window.onload; window.onload = function() { if (currentWindowOnload) { currentWindowOnload(); } execJasmine(); }; function execJasmine() { jasmineEnv.execute(); } })(); </script> </head> <body> </body> </html> 
+4
source share
2 answers

As Amir T said, you can use grunt-contrib-jasmine . Moreover, grunt-jasmine-task no longer active.

The options.junit.path parameter can be used to create unit reports, which can then be used by Jenkins / Hudson, Travis, Bamboo, etc. This parameter should contain the name of the folder in which reports will be generated ( grunt-contrib-jasmine will create xml for each specification file). This is an example configuration:

 jasmine: { tests: { src: 'dist/buyitnow/<%= meta.version %>/buyitnow.min.js', options: { specs: 'spec/*Spec.js', junit: { path: 'build/junit' }, } } } 

You do not need to create a SpecRunner.html file created automatically by grunt-contrib-jasmine

+1
source

I can do this using grunt-contrib-jasmine@0.5.2

 jasmine: { pivotal: { src: 'build/application.js', options: { specs: 'test/**/*_spec.js', helpers: 'test/**/*_helper.js', junit: { path: 'build/.test' }, } } } 
0
source

Source: https://habr.com/ru/post/1495029/


All Articles