Koha-QA
view release on metacpan or search on metacpan
t/tidy/js.t view on Meta::CPAN
use Modern::Perl;
use File::ShareDir qw(dist_file dist_dir);
use File::Spec;
use IPC::Run3;
use Koha::QA::Tidy::JS;
BEGIN {
# Check if prettier is available via node
my ( $stdout, $stderr );
my $available = Koha::QA::Tidy::JS->_has_prettier();
unless ($available) {
print "1..0 # skip prettier is not available\n";
exit 0;
}
}
use Test::NoWarnings qw(had_no_warnings);
use Test::More tests => 9;
use Test::Warn;
use File::Temp qw(tempfile);
sub check_tidy {
my ( $content, $params ) = @_;
$params ||= {};
my $checker = Koha::QA::Tidy::JS->new( { content => $content, %$params } );
$checker->check();
return $checker->errors();
}
subtest 'File tidy should pass tidy check' => sub {
plan tests => 1;
my $input = <<'INPUT';
for (const user of ["Alice", "Bob", "Charlie"]) {
console.log(user);
}
INPUT
my @errors = check_tidy($input);
is( scalar @errors, 0 );
};
subtest 'File not tidy should not pass tidy check' => sub {
plan tests => 1;
my $input = <<'INPUT';
for ( const user of ["Alice", "Bob", "Charlie"] ) {
console.log( user );
}
INPUT
my @errors = check_tidy($input);
is_deeply(
\@errors,
[
{
message => 'JavaScript file is not tidy',
error => 'tidy_js'
( run in 0.992 second using v1.01-cache-2.11-cpan-eb134014566 )