From 0192bb0cb8d749913962cf47e6ade3ecb0b4f6c9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 2 May 2023 10:32:11 +0200 Subject: [PATCH] Bug 33625: Add test Signed-off-by: Martin Renvoize --- xt/vue_tidy.t | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/xt/vue_tidy.t b/xt/vue_tidy.t index 122aea1f50..7052e6f882 100755 --- a/xt/vue_tidy.t +++ b/xt/vue_tidy.t @@ -20,17 +20,17 @@ use File::Slurp qw( read_file ); use File::Find; use FindBin(); use Data::Dumper qw( Dumper ); -use Test::More tests => 1; +use Test::More tests => 2; my $vue_dir = "$FindBin::Bin/../koha-tmpl/intranet-tmpl/prog/js/vue"; my @files; -sub wanted { +sub wanted_vue { my $name = $File::Find::name; push @files, $name if $name =~ /\.vue$/; } -find({ wanted => \&wanted, no_chdir => 1 }, $vue_dir); +find({ wanted => \&wanted_vue, no_chdir => 1 }, $vue_dir); my @not_tidy; foreach my $filepath (@files) { @@ -42,4 +42,26 @@ foreach my $filepath (@files) { } } -is(scalar(@not_tidy), 0, 'No vue file should be messy') or diag Dumper \@not_tidy; +is(scalar(@not_tidy), 0, 'No .vue file should be messy') or diag Dumper \@not_tidy; + +@files = (); +sub wanted_js_ts { + my $name = $File::Find::name; + push @files, $name + if ( $name =~ /\.js$/ + || $name =~ /\.ts$/ ) + && $name !~ m{koha-tmpl/intranet-tmpl/prog/js/vue/dist}; # Exclude dist +} +find({ wanted => \&wanted_js_ts, no_chdir => 1 }, $vue_dir); + +@not_tidy = (); +foreach my $filepath (@files) { + chomp $filepath; + my $tidy = qx{yarn --silent run prettier --trailing-comma es5 --arrow-parens avoid $filepath}; + my $content = read_file $filepath; + if ( $content ne $tidy ) { + push @not_tidy, $filepath; + } +} + +is(scalar(@not_tidy), 0, 'No js file from vue directory should be messy') or diag Dumper \@not_tidy;