Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created August 31, 2012 20:58
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 ahomu/3558900 to your computer and use it in GitHub Desktop.
Save ahomu/3558900 to your computer and use it in GitHub Desktop.
更新したファイル+対応するテストケースのみ含むheadlessテスト用のSpecRunner.html作るくん
module.exports = function(grunt) {
var ejsTmpl = require('ejs').compile(grunt.file.read('test/SpecRunner.ejs')),
_ = grunt.util._,
async = grunt.util.async;
grunt.registerMultiTask('build-runner', 'Build SpecRunner.html for jasmine', function() {
var pairing = this.data.pairing,
options = this.data.options,
done = this.async(),
changed = grunt.file.watchFiles.changed[0] || grunt.file.watchFiles.added[0],
distFiles = [],
testFiles = [];
async.forEach(Object.keys(pairing), function(dist, next) {
var test = pairing[dist];
if (changed.indexOf(test) !== -1) {
distFiles.push(changed.replace(test, dist));
testFiles.push(changed);
}
else if (changed.indexOf(dist) !== -1) {
distFiles.push(changed);
testFiles.push(changed.replace(dist, test));
}
grunt.file.write('test/SpecRunner.html', ejsTmpl({
distFiles : distFiles,
testFiles : testFiles
}));
next();
}, done);
});
};
// 抜粋
module.exports = function(grunt) {
grunt.initConfig({
'build-runner': {
part: {
pairing: {
'dist/js' : 'test/spec'
},
options: {
dummy: 'haha'
},
watch: ['dist/js/**/*.js', 'test/spec/**/*.js']
}
},
jasmine: {
part: {
src:['test/SpecRunner.html'],
errorReporting: true
}
},
watch: {
jasmine: {
files: ['<config:build-runner.part.watch>'],
tasks: ['build-runner:part', 'jasmine:part']
}
}
});
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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="lib/jquery.1.3.2.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
<script type="text/javascript" src="../node_modules/grunt-jasmine-task/tasks/jasmine/jasmine-helper.js"></script>
<% for (var i=0; i < distFiles.length; i++) { %>
<script type="text/javascript" src="../<%= distFiles[i] %>"></script>
<% } %>
<% for (var i=0; i < testFiles.length; i++) { %>
<script type="text/javascript" src="../<%= testFiles[i] %>"></script>
<% } %>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment