From 8bebae84a051bdda081a50844886198ad4039dd3 Mon Sep 17 00:00:00 2001 From: Mason James Date: Fri, 26 Jul 2024 22:54:15 +1200 Subject: [PATCH] Bug 37490: Add a test to detect when yarn.lock is not updated to test... 1/ set koha repo to state where yarn.lock is not updated $ git reset --hard 67db70d4 2/ run test, observe FAIL $ prove ./xt/verify-yarnlock.t ./xt/verify-yarnlock.t .. error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`. ./xt/verify-yarnlock.t .. 1/1 # Failed test 'verify yarn.lock file is updated correctly' ... Result: FAIL 3/ set koha repo to state where yarn.lock is updated $ yarn install 4/ note yarn.lock is now updated $ git status ... modified: yarn.lock 5/ run test, observe SUCCESS $ prove -v ./xt/verify-yarnlock.t ./xt/verify-yarnlock.t .. ok 1 - verify yarn.lock file is updated correctly All tests successful. Files=1, Tests=1, 1 wallclock secs ( 0.02 usr 0.01 sys + 1.16 cusr 0.27 csys = 1.46 CPU) Result: PASS --- xt/verify-yarnlock.t | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 xt/verify-yarnlock.t diff --git a/xt/verify-yarnlock.t b/xt/verify-yarnlock.t new file mode 100755 index 0000000000..088495c9d8 --- /dev/null +++ b/xt/verify-yarnlock.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# Copyright (C) 2024 KohaAloha Ltd. +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +# This file tests that Koha's yarn.lock file is updated with the +# packages.json file. If this test fails, the likely solution is to run +# 'yarn install' to generate an updated yarn.lock file, then +# 'git commit ./yarn.lock'. + +use Modern::Perl; +use Test::More tests => 1; + +my $rc; + +# if KTD dirs exists? +if ( -d "/usr/local/share/.cache/yarn" and -d "/kohadevbox/node_modules" ) { + + # we use KTD's existing .cache/yarn and node_modules dirs + $rc = system("yarn check --modules-folder /kohadevbox/node_modules --cache-dir /usr/local/share/.cache/yarn"); + +} else { + + # else, we just use yarn's currently set dirs + $rc = system("yarn check"); + +} + +# yarn returns a 256 value for this specific lockfile error, +# but we assume any non-zero value is bad +is( $rc, 0, "verify yarn.lock file is updated correctly" ); -- 2.30.2