Skip to content

Instantly share code, notes, and snippets.

@asabaylus
Created July 6, 2012 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asabaylus/3059886 to your computer and use it in GitHub Desktop.
Save asabaylus/3059886 to your computer and use it in GitHub Desktop.
Jasmine Junit Reporter Scafolding
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:jquery.sessiontimeout.js.jquery.json>',
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(", ") %> */'
},
concat: {
dist: {
src: ['<banner:meta.banner>', '<file_strip_banner:src/<%= pkg.name %>.js>'],
dest: 'dist/<%= pkg.name %>.js'
}
},
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'dist/<%= pkg.name %>.min.js'
}
},
jasmine: {
all: ['test/junit.html'],
junit: {
dest: 'test-results'
}
},
lint: {
files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
},
watch: {
files: '<config:lint.files>',
tasks: 'lint qunit'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
devel:true,
jquery: true
},
globals: {}
},
uglify: {}
});
// Default task.
// run Jasmin in versbose mode (-v) to help with debugging
grunt.registerTask('default', 'lint jasmine concat min');
// Jamsmine BDD task
grunt.loadNpmTasks('grunt-jasmine-task');
};
<!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="../libs/jasmine/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="../libs/jasmine/jasmine.css">
<script type="text/javascript" src="../libs/jasmine/jasmine.js"></script>
<script type="text/javascript" src="../libs/jasmine/jasmine-html.js"></script>
<!-- For JUnit output of test results include the following link
to Lary Myer's JUnit reporter -->
<script type="text/javascript" src="../node_modules/grunt-jasmine-task/tasks/jasmine/jasmine-junit-reporter.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/your_spec_file_here.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="../libs/jquery/jquery.js"></script>
<script type="text/javascript" src="../src/your_scripts_here.js"></script>
</head>
<body>
<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>
</body>
</html>
@cdcrews
Copy link

cdcrews commented Aug 1, 2013

I know I'm a year late, but I'm trying to get this to work and can't seem to. I really need the junit xml output. Running grunt jasmine gives me the following error:
"path.existsSync is now called fs.existsSync.
Running "jasmine:junit" (jasmine) task
An error occurred while processing a template (Cannot call method 'indexOf' of undefined).
Use --force to continue. "

Any idea why if I have my files formatted as above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment