1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
use lib '.';
use t::Helper;
plan skip_all => 'TEST_SASS=1' unless $ENV{TEST_SASS} or -e '.test-everything';
my $t = t::Helper->t(pipes => [qw(Sass Css)]);
my $sass = $t->app->asset->pipe('Sass');
isa_ok($sass, 'Mojolicious::Plugin::AssetPack::Pipe::Sass');
$sass->{has_module} = ''; # make sure CSS::Sass is not used
$t->app->asset->process('app.css' => ('sass.sass', 'sass/sass-1.scss'));
$t->get_ok('/')->status_is(200)->element_exists(qq(link[href="/asset/8d347a7a6f/sass.css"]))
->element_exists(qq(link[href="/asset/71dcf0669a/sass-1.css"]));
my $html = $t->tx->res->dom;
$t->get_ok($html->at('link:nth-of-child(1)')->{href})->status_is(200)->content_like(qr{\.sass\W+color:\s+\#aaa}s);
$t->get_ok($html->at('link:nth-of-child(2)')->{href})->status_is(200)->content_like(qr{footer.*\#aaa.*body.*\#222}s);
# Processing invalid sass file should fail as it does with CSS::Sass
$t = t::Helper->t(pipes => [qw(Sass)]);
$t->app->asset->pipe('Sass')->{has_module} = ''; # make sure CSS::Sass is not used
ok((not eval { $t->app->asset->process('invalid.css' => 'sass-invalid.sass') }), 'compile invalid sass file');
like $@, qr/Undefined variable/, 'sass complains about undefined variable';
$ENV{MOJO_MODE} = 'Test_minify_from_here';
$t = t::Helper->t(pipes => [qw(Sass Css Combine)]);
$t->app->asset->pipe('Sass')->{has_module} = ''; # make sure CSS::Sass is not used
$t->app->asset->process('app.css' => ('sass.sass', 'sass/sass-1.scss'));
$t->get_ok('/')->status_is(200);
$t->get_ok($t->tx->res->dom->at('link')->{href})->status_is(200)->content_unlike(qr/[ ]/)
; # No spaces in minified version
done_testing;
__DATA__
@@ index.html.ep
%= asset 'app.css'
@@ sass.sass
$color: #aaa
.sass
color: $color
@@ sass-invalid.sass
.sass
color: $undefined
|