Skip Menu |

This queue is for tickets about the TAP-Formatter-HTML CPAN distribution.

Report information
The Basics
Id: 41457
Status: resolved
Priority: 0/
Queue: TAP-Formatter-HTML

People
Owner: steve [...] purkis.ca
Requestors: hemingway [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.08
Fixed in: (no value)



The attached patch resolves various issues: * it adds a force_inline_js function akin to the existing force_inline_css function * it adds a strict DOCTYPE to the resulting html * under XHTML, id attributes are not allowed to be empty. Those on the <tr class="test-run" were empty. resolved by commenting out the attribute. This didn't seem to cause any issues (all the tests pass). * Under TT, [% IF test.parse_errors %] tests true if parse_errors is an empty array. This has been replaced by [% IF tests.parse_errors.size > 0 %] * fixed various other XHTML violations (either by adding missing elements or by adding non-breaking spaces) * also fixed the s/incline_js/inline_js/ bug
Subject: TAP-Formatter-HTML-0.06.patch
diff -ur TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML/default_report.tt2 TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML/default_report.tt2 --- TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML/default_report.tt2 2008-08-26 15:58:14.000000000 +0100 +++ TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML/default_report.tt2 2008-12-05 10:49:55.000000000 +0000 @@ -1,3 +1,5 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + [%# TAP-Formatter-HTML: TT2 Template Copyright (c) 2008 Steve Purkis. All rights reserved. @@ -40,10 +42,12 @@ </div> <div id="menu"> + <ul> <li> <span id="show-all"><a href="#" title="show all tests">show all</a></span> <span id="show-failed"><a href="#" title="show failed tests only">show failed</a></span> </li> + </ul> </div> <div id="detail"> @@ -60,7 +64,7 @@ [%- FOREACH test IN report.tests %] <tr class="test-run [% test.test_status -%] [%- IF test.severity %][% ' severity-' _ test.severity %][% END -%] - [%- IF test.todo_passed %] todo-passed[% END %]" id="[% test.html_id %]"> + [%- IF test.todo_passed %] todo-passed[% END %]"><!-- id="[% test.html_id %]">--> <td class="file c"> <a class="file" href="#" title="Test [% IF test.has_problems %]failed![% ELSE %]ok.[% END %] [% IF test.num_parse_errors %] [% test.num_parse_errors %] parse error(s)! @@ -84,7 +88,7 @@ [%- SET max_tests = test.tests_run IF test.tests_run AND test.tests_run > max_tests %] <table class="TS">[%# TS=Test Summary. Note: use a table to caulculate widths automatically %] <tr> - [%- IF test.tests_run AND test.tests_run > 0 -%] + [% IF test.tests_run AND test.tests_run > 0 -%] [%- SET current_test = 0 -%] [%- FOREACH result IN test.results -%] [%- IF result.is_test %] @@ -107,7 +111,7 @@ </tr> </table> <div class="test-detail"> - [%- IF test.parse_errors %] + [%- IF test.parse_errors.size > 0 %] <ul class="parse-errors"> [%- FOREACH e IN test.parse_errors %] <li>Parse error: [% e %]</li> @@ -118,7 +122,7 @@ [%- FOREACH result IN test.results %] <li [% IF result.is_test %]id="[% result.html_id %]" [% END -%]class="[% result.css_type -%] [%- IF result.is_test %][% ' ' _ result.short_test_status -%][%- END -%] - [%- IF result.is_unplanned %] unp[% END -%]">[% result.raw | html -%] + [%- IF result.is_unplanned %] unp[% END -%]">[% result.raw | html -%]&nbsp; [%- IF result.is_unplanned %]<em> (unplanned!)</em>[% END -%] [%- IF result.todo_passed %]<em> (unexpectedly succeeded!)</em>[% END %]</li> [%- END -%] diff -ur TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML.pm TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML.pm --- TAP-Formatter-HTML-0.06-before/lib/TAP/Formatter/HTML.pm 2008-08-26 15:58:14.000000000 +0100 +++ TAP-Formatter-HTML-0.06-after/lib/TAP/Formatter/HTML.pm 2008-12-05 10:49:40.000000000 +0000 @@ -30,7 +30,8 @@ # you can use your own customized templates too: $fmt->template('custom.tt2') ->template_processor( Template->new ) - ->force_inline_css(0); + ->force_inline_css(0) + ->force_inline_js(0); =cut @@ -53,7 +54,7 @@ use base qw( TAP::Base ); use accessors qw( verbosity stdout escape_output tests session_class sessions template_processor template html html_id_iterator minify - css_uris js_uris inline_css inline_js abs_file_paths force_inline_css ); + css_uris js_uris inline_css inline_js abs_file_paths force_inline_css force_inline_js ); use constant default_session_class => 'TAP::Formatter::HTML::Session'; use constant default_template => 'TAP/Formatter/HTML/default_report.tt2'; @@ -98,6 +99,7 @@ ->abs_file_paths( 1 ) ->abs_file_paths( 1 ) ->force_inline_css( 1 ) + ->force_inline_js( 1 ) ->session_class( $self->default_session_class ) ->template_processor( $self->default_template_processor ) ->template( $self->default_template ) @@ -198,12 +200,13 @@ $self->check_uris; $self->slurp_css if $self->force_inline_css; + $self->slurp_js if $self->force_inline_js; my $params = { report => $r, js_uris => $self->js_uris, css_uris => $self->css_uris, - incline_js => $self->inline_js, + inline_js => $self->inline_js, inline_css => $self->inline_css, formatter => { class => ref( $self ), version => $self->VERSION }, @@ -364,6 +367,34 @@ $self->inline_css( $inline_css ); } +sub slurp_js { + my ($self) = shift; + $self->info("slurping js files inline"); + + my $inline_js = $self->inline_js || ''; + foreach my $uri (@{ $self->js_uris }) { + my $scheme = $uri->scheme; + if ($scheme && $scheme eq 'file') { + my $path = $uri->path; + if (-e $path) { + if (open my $fh, $path) { + local $/ = undef; + $inline_js .= <$fh>; + } else { + $self->log("Warning: couldn't open $path: $!"); + } + } else { + $self->log("Warning: couldn't read $path: file does not exist!"); + } + } else { + $self->log("Warning: can't include $uri inline: not a file uri"); + } + } + + $self->inline_js( $inline_js ); +} + + sub log { my $self = shift; push @_, "\n" unless grep {/\n/} @_; @@ -583,6 +614,13 @@ sending the output around - that way you don't have to send a CSS file too. Defaults to I<1>. +=head3 force_inline_js( [ $boolean ] ) + +If set, the formatter will attempt to slurp in any I<file> javascript URI's listed in +L</js_uris>, and append them to L</inline_js>. This is handy if you'll be +sending the output around - that way you don't have to send javascript files too. +Defaults to I<1>. + =head2 $html = $fmt->summary( $aggregator ) C<summary> produces a summary report after all tests are run. C<$aggregator> @@ -597,7 +635,7 @@ report => %test_report js_uris => @js_uris css_uris => @js_uris - incline_js => $inline_js + inline_js => $inline_js inline_css => $inline_css formatter => %formatter_info
Thanks for this report & fixes. I'll hopefully get this in for 0.08; unfortunately I didn't get the report until now :-/ The inline_js fix is in for 0.07 though.
Hi Neil, I've not managed to get most of your fixes in, unfortunately. As it stands, 0.08 was waiting one the back-burner for several months :-/. I figured it was best to release the fixes so far. I'd like to get these in to 0.09 though. If you're available to help, I can put the source on github and give you a commit bit. Cheers, -Steve
I've applied the same (still missing) patches to the 0.08: - includes also the patch from issue #49621 - small changes to the top-left corner menu (default_report.css) to render it corretly with Firefox 3 (Linux)
diff -ur TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML/default_report.css TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML/default_report.css --- TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML/default_report.css 2009-09-02 23:48:21.000000000 +0300 +++ TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML/default_report.css 2009-10-21 08:48:54.000000000 +0300 @@ -13,13 +13,16 @@ left: 8px; top: 8px; padding: 2px; - width: 100px; - height: 26px; font-size: small; background-color: #eeffcc; opacity: 0.5; } +#menu ul { + margin: 0px; + padding: 5px; +} + #menu li { text-decoration: none; list-style: none; Only in TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML: default_report.css~ diff -ur TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML/default_report.js TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML/default_report.js --- TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML/default_report.js 2009-09-02 23:48:21.000000000 +0300 +++ TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML/default_report.js 2009-10-21 09:02:26.000000000 +0300 @@ -32,7 +32,7 @@ // highlight a particular test? var testId = $(this).attr("href"); - if (!testId) { + if (testId) { var $testElem = $detail.find(testId); $testElem.show().scrollTo(1000); var bgColor = $testElem.css("background-color"); diff -ur TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML/default_report.tt2 TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML/default_report.tt2 --- TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML/default_report.tt2 2009-09-02 23:48:21.000000000 +0300 +++ TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML/default_report.tt2 2009-10-20 15:24:31.000000000 +0300 @@ -1,3 +1,5 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + [%# TAP-Formatter-HTML: TT2 Template Copyright (c) 2008 Steve Purkis. All rights reserved. @@ -40,10 +42,12 @@ </div> <div id="menu"> + <ul> <li> <span id="show-all"><a href="#" title="show all tests">show all</a></span> <span id="show-failed"><a href="#" title="show failed tests only">show failed</a></span> </li> + </ul> </div> <div id="detail"> @@ -60,7 +64,7 @@ [%- FOREACH test IN report.tests %] <tr class="test-run [% test.test_status -%] [%- IF test.severity %][% ' severity-' _ test.severity %][% END -%] - [%- IF test.todo_passed %] todo-passed[% END %]" id="[% test.html_id %]"> + [%- IF test.todo_passed %] todo-passed[% END %]"><!-- id="[% test.html_id %]">--> <td class="file c"> <a class="file" href="#" title="Test [% IF test.has_problems %]failed![% ELSE %]ok.[% END %] [% IF test.num_parse_errors %] [% test.num_parse_errors %] parse error(s)! @@ -84,7 +88,7 @@ [%- SET max_tests = test.tests_run IF test.tests_run AND test.tests_run > max_tests %] <table class="TS">[%# TS=Test Summary. Note: use a table to caulculate widths automatically %] <tr> - [%- IF test.tests_run AND test.tests_run > 0 -%] + [% IF test.tests_run AND test.tests_run > 0 -%] [%- SET current_test = 0 -%] [%- FOREACH result IN test.results -%] [%- IF result.is_test %] @@ -107,7 +111,7 @@ </tr> </table> <div class="test-detail"> - [%- IF test.parse_errors %] + [%- IF test.parse_errors.size > 0 %] <ul class="parse-errors"> [%- FOREACH e IN test.parse_errors %] <li>Parse error: [% e %]</li> @@ -118,7 +122,7 @@ [%- FOREACH result IN test.results %] <li [% IF result.is_test %]id="[% result.html_id %]" [% END -%]class="[% result.css_type -%] [%- IF result.is_test %][% ' ' _ result.short_test_status -%][%- END -%] - [%- IF result.is_unplanned %] unp[% END -%]">[% result.raw | html -%] + [%- IF result.is_unplanned %] unp[% END -%]">[% result.raw | html -%]&nbsp; [%- IF result.is_unplanned %]<em> (unplanned!)</em>[% END -%] [%- IF result.todo_passed %]<em> (unexpectedly succeeded!)</em>[% END %]</li> [%- END -%] diff -ur TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML.pm TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML.pm --- TAP-Formatter-HTML-0.08-before/lib/TAP/Formatter/HTML.pm 2009-09-02 23:48:21.000000000 +0300 +++ TAP-Formatter-HTML-0.08-after/lib/TAP/Formatter/HTML.pm 2009-10-20 15:40:43.000000000 +0300 @@ -37,7 +37,8 @@ # you can use your own customized templates too: $fmt->template('custom.tt2') ->template_processor( Template->new ) - ->force_inline_css(0); + ->force_inline_css(0) + ->force_inline_js(0); =cut @@ -62,7 +63,7 @@ use base qw( TAP::Base ); use accessors qw( verbosity stdout output_fh escape_output tests session_class sessions template_processor template html html_id_iterator minify - css_uris js_uris inline_css inline_js abs_file_paths force_inline_css ); + css_uris js_uris inline_css inline_js abs_file_paths force_inline_css force_inline_js ); use constant default_session_class => 'TAP::Formatter::HTML::Session'; use constant default_template => 'TAP/Formatter/HTML/default_report.tt2'; @@ -113,6 +114,7 @@ ->abs_file_paths( 1 ) ->abs_file_paths( 1 ) ->force_inline_css( 1 ) + ->force_inline_js( 1 ) ->session_class( $self->default_session_class ) ->template_processor( $self->default_template_processor ) ->template( $self->default_template ) @@ -146,6 +148,11 @@ if (defined( $force )) { $self->force_inline_css( $force ); } + + $force = $ENV{TAP_FORMATTER_HTML_FORCE_INLINE_JS}; + if (defined( $force )) { + $self->force_inline_js( $force ); + } if (my $uris = $ENV{TAP_FORMATTER_HTML_CSS_URIS}) { my $list = [ split( ':', $uris ) ]; @@ -259,6 +266,7 @@ $self->check_uris; $self->slurp_css if $self->force_inline_css; + $self->slurp_js if $self->force_inline_js; my $params = { report => $r, @@ -434,6 +442,34 @@ $self->inline_css( $inline_css ); } +sub slurp_js { + my ($self) = shift; + $self->info("slurping js files inline"); + + my $inline_js = $self->inline_js || ''; + foreach my $uri (@{ $self->js_uris }) { + my $scheme = $uri->scheme; + if ($scheme && $scheme eq 'file') { + my $path = $uri->path; + if (-e $path) { + if (open my $fh, $path) { + local $/ = undef; + $inline_js .= <$fh>; + } else { + $self->log("Warning: couldn't open $path: $!"); + } + } else { + $self->log("Warning: couldn't read $path: file does not exist!"); + } + } else { + $self->log("Warning: can't include $uri inline: not a file uri"); + } + } + + $self->inline_js( $inline_js ); +} + + sub log { my $self = shift; push @_, "\n" unless grep {/\n/} @_; @@ -729,6 +765,16 @@ You can set this with the C<TAP_FORMATTER_HTML_FORCE_INLINE_CSS=0|1> environment variable. +=head3 force_inline_js( [ $boolean ] ) + +If set, the formatter will attempt to slurp in any I<file> javascript URI's listed in +L</js_uris>, and append them to L</inline_js>. This is handy if you'll be +sending the output around - that way you don't have to send javascript files too. +Defaults to I<1>. + +You can set this with the C<TAP_FORMATTER_HTML_FORCE_INLINE_JS=0|1> environment +variable. + =head2 API METHODS =head3 summary @@ -763,6 +809,7 @@ TAP_FORMATTER_HTML_OUTFILE=/path/to/file TAP_FORMATTER_HTML_FORCE_INLINE_CSS=0|1 + TAP_FORMATTER_HTML_FORCE_INLINE_JS=0|1 TAP_FORMATTER_HTML_CSS_URIS=/path/to.css:/another/path.css TAP_FORMATTER_HTML_JS_URIS=/path/to.js:/another/path.js TAP_FORMATTER_HTML_TEMPLATE=/path/to.tt
A quick update - I've tried applying this patch and found a few problems: 1. tests break: t/selenium_basic.t & t/04_really_quiet.t 2. having jquery as inline js doesn't work in firefox 3 on my mac, you get weird behaviour like divs rolling back up right after they've rolled down. I'll investigate when I've got some more time.
On Sun Dec 06 17:06:53 2009, SPURKIS wrote: Show quoted text
> A quick update - I've tried applying this patch and found a few > problems: > > 1. tests break: t/selenium_basic.t & t/04_really_quiet.t > 2. having jquery as inline js doesn't work in firefox 3 on my mac, you > get weird behaviour like > divs rolling back up right after they've rolled down. > > I'll investigate when I've got some more time.
I've applied this patch and hacked about to get things working. This will be fixed in the next release which I'm just working on it now. Should be on CPAN later this week. Note that force_inline_js will be off by default, as slurping in jquery causes errors. Thanks again, -Steve
fixed in 0.09.