2011-06-10 15:02:26 +00:00
|
|
|
require 'jasmine/files_list'
|
2011-07-13 18:42:47 +00:00
|
|
|
require 'multi_json'
|
2011-06-10 15:02:26 +00:00
|
|
|
|
|
|
|
module Jasmine
|
|
|
|
class TemplateWriter
|
|
|
|
class << self
|
|
|
|
def write!(files_list)
|
|
|
|
output = [
|
|
|
|
[ "specrunner.#{$$}.html", files_list.files_to_html ]
|
|
|
|
]
|
|
|
|
|
|
|
|
output.unshift([ "specrunner.#{$$}.filter.html", files_list.filtered_files_to_html ]) if files_list.filtered?
|
|
|
|
|
|
|
|
output.each do |name, files|
|
2011-07-13 18:42:47 +00:00
|
|
|
File.open(name, 'w') { |fh| fh.print template_for(files, files_list.spec_file_line_numbers) }
|
2011-06-10 15:02:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
output.collect(&:first)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2011-07-13 18:42:47 +00:00
|
|
|
def template_for(files, spec_lines)
|
2011-06-10 15:02:26 +00:00
|
|
|
<<-HTML
|
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Jasmine Test Runner</title>
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.console = { log: function(data) {
|
|
|
|
JHW.log(JSON.stringify(data));
|
|
|
|
}, pp: function(data) {
|
|
|
|
JHW.log(jasmine ? jasmine.pp(data) : JSON.stringify(data));
|
|
|
|
} };
|
2011-07-22 11:42:25 +00:00
|
|
|
|
|
|
|
window.onbeforeunload = function(e) {
|
|
|
|
JHW.leavePageAttempt('The code tried to leave the test page. Check for unhandled form submits and link clicks.');
|
|
|
|
|
|
|
|
if (e = e || window.event) {
|
|
|
|
e.returnValue = "leaving";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "leaving";
|
|
|
|
};
|
2011-06-10 15:02:26 +00:00
|
|
|
</script>
|
|
|
|
#{files.join("\n")}
|
2011-07-13 18:42:47 +00:00
|
|
|
<script type="text/javascript">
|
2011-07-14 14:54:44 +00:00
|
|
|
HeadlessReporterResult.specLineNumbers = #{MultiJson.encode(spec_lines)};
|
2011-07-13 18:42:47 +00:00
|
|
|
</script>
|
2011-06-10 15:02:26 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2011-07-22 11:42:25 +00:00
|
|
|
jasmine.getEnv().addReporter(new jasmine.HeadlessReporter(function() {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
}));
|
2011-06-10 15:02:26 +00:00
|
|
|
jasmine.getEnv().execute();
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|