| File: | t/logger.t |
| Coverage: | 87.5% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 1 1 1 | 1298335862285930 17858 10 | use Test::More tests => 17; | ||||
| 2 | 1 1 1 | 614 150223 11 | use Test::Mojo; | ||||
| 3 | |||||||
| 4 | # Make sure sockets are working | ||||||
| 5 | 1 | 301814 | plan skip_all => 'working sockets required for this test!' | ||||
| 6 | unless Mojo::IOLoop->new->generate_port; # Test server | ||||||
| 7 | |||||||
| 8 | 1 1 1 | 257 47050 9 | use Mojolicious::Lite; | ||||
| 9 | |||||||
| 10 | 1 | 505 | plugin 'console_logger'; | ||||
| 11 | |||||||
| 12 | get '/:template' => sub { | ||||||
| 13 | 2 | 147 | my $self = shift; | ||||
| 14 | 2 | 19 | app->log->info('info'); | ||||
| 15 | 2 | 112 | app->log->debug('debug'); | ||||
| 16 | 2 | 110 | app->log->error('error'); | ||||
| 17 | 2 | 110 | app->log->fatal({json => 'structure'}); | ||||
| 18 | |||||||
| 19 | 2 | 114 | $self->render($self->stash->{template}) | ||||
| 20 | if $self->stash->{template}; | ||||||
| 21 | |||||||
| 22 | # Template not found, generates exception | ||||||
| 23 | 2 | 306 | $self->rendered; | ||||
| 24 | 1 | 72 | }; | ||||
| 25 | |||||||
| 26 | # Tests | ||||||
| 27 | 1 | 561 | my $client = app->client; | ||||
| 28 | 1 | 118 | my $t = Test::Mojo->new; | ||||
| 29 | |||||||
| 30 | # Script tag in dynamic content | ||||||
| 31 | $t->get_ok($_)->status_is(200)->element_exists('script') | ||||||
| 32 | ->content_like( | ||||||
| 33 | qr/console\.group\("info"\);.*?console\.log\("info"\);.*?console\.groupEnd\("info"\);/ | ||||||
| 34 | ) | ||||||
| 35 | ->content_like( | ||||||
| 36 | qr/console\.group\("debug"\);.*?console\.log\("debug"\);.*?console\.groupEnd\("debug"\);/ | ||||||
| 37 | ) | ||||||
| 38 | ->content_like( | ||||||
| 39 | qr/console\.group\("error"\);.*?console\.log\("error"\);.*?console\.groupEnd\("error"\);/ | ||||||
| 40 | ) | ||||||
| 41 | ->content_like( | ||||||
| 42 | qr/console\.group\("fatal"\);.*?console\.log\({"json":"structure"}\);.*?console\.groupEnd\("fatal"\);/ | ||||||
| 43 | ) | ||||||
| 44 | |||||||
| 45 | 1 1 | 25 9 | for qw| /normal /exception |; | ||||
| 46 | |||||||
| 47 | # No script tag in static content | ||||||
| 48 | 1 | 288 | $t->get_ok('/js/prettify.js')->status_is(200)->element_exists(':not(script)'); | ||||
| 49 | |||||||