Skip to content

Commit

Permalink
Merge pull request #5494 from Martchus/sneaky-npm
Browse files Browse the repository at this point in the history
Ensure npm packages are installed when invoking tests
  • Loading branch information
mergify[bot] authored Mar 1, 2024
2 parents 229df7d + cc8ac11 commit 1d22005
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ else
install: install-opensuse
endif

# Ensure npm packages are installed and up-to-date (unless local-npm-registry is installed; in this case we can
# assume installing npm packages is taken care of separately, e.g. in builds on OBS)
node_modules: package-lock.json
@which local-npm-registry >/dev/null 2>&1 || npm install --no-audit --no-fund
@touch node_modules

.PHONY: test
ifeq ($(TRAVIS),true)
test: run-tests-within-container
Expand All @@ -185,44 +191,44 @@ endif
test-checkstyle: test-checkstyle-standalone test-tidy-compile

.PHONY: test-t
test-t:
test-t: node_modules
$(MAKE) test-with-database TIMEOUT_M=25 PROVE_ARGS="$$HARNESS t/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)"

.PHONY: test-heavy
test-heavy:
test-heavy: node_modules
$(MAKE) test-with-database HEAVY=1 TIMEOUT_M=25 PROVE_ARGS="$$HARNESS $$(grep -l HEAVY=1 t/*.t | tr '\n' ' ')"

.PHONY: test-ui
test-ui:
test-ui: node_modules
$(MAKE) test-with-database TIMEOUT_M=25 PROVE_ARGS="$$HARNESS t/ui/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)"

.PHONY: test-api
test-api:
test-api: node_modules
$(MAKE) test-with-database TIMEOUT_M=20 PROVE_ARGS="$$HARNESS t/api/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)"

# put unstable tests in tools/unstable_tests.txt and uncomment in circle CI config to handle unstables with retries
.PHONY: test-unstable
test-unstable:
test-unstable: node_modules
for f in $$(cat tools/unstable_tests.txt); do $(MAKE) test-with-database COVERDB_SUFFIX=$$(echo $${COVERDB_SUFFIX}_$$f | tr '/' '_') TIMEOUT_M=10 PROVE_ARGS="$$HARNESS $$f" RETRY=5 || exit; done

.PHONY: test-fullstack
test-fullstack:
test-fullstack: node_modules
$(MAKE) test-with-database FULLSTACK=1 TIMEOUT_M=30 PROVE_ARGS="$$HARNESS t/full-stack.t t/33-developer_mode.t"

.PHONY: test-fullstack-unstable
test-fullstack-unstable:
test-fullstack-unstable: node_modules
$(MAKE) test-with-database FULLSTACK=1 TIMEOUT_M=15 PROVE_ARGS="$$HARNESS t/05-scheduler-full.t" RETRY=5

# we have apparently-redundant -I args in PERL5OPT here because Docker
# only works with one and Fedora's build system only works with the other
.PHONY: test-with-database
test-with-database:
test-with-database: node_modules
test -d $(TEST_PG_PATH) && (pg_ctl -D $(TEST_PG_PATH) -s status >&/dev/null || pg_ctl -D $(TEST_PG_PATH) -s start) || ./t/test_postgresql $(TEST_PG_PATH)
$(MAKE) test-unit-and-integration TEST_PG="DBI:Pg:dbname=openqa_test;host=$(TEST_PG_PATH)"
-[ $(KEEP_DB) = 1 ] || pg_ctl -D $(TEST_PG_PATH) stop

.PHONY: test-unit-and-integration
test-unit-and-integration:
test-unit-and-integration: node_modules
export GLOBIGNORE="$(GLOBIGNORE)";\
export DEVEL_COVER_DB_FORMAT=JSON;\
export PERL5OPT="$(COVEROPT)$(PERL5OPT) -It/lib -I$(PWD)/t/lib -I$(PWD)/external/os-autoinst-common/lib -MOpenQA::Test::PatchDeparse";\
Expand Down
10 changes: 9 additions & 1 deletion lib/OpenQA/WebAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ sub startup ($self) {
$self->asset->store->retries(5) if $Mojolicious::Plugin::AssetPack::VERSION > 2.13;

# -> read assets/assetpack.def
$self->asset->process;
eval { $self->asset->process };
if (my $assetpack_error = $@) { # uncoverable statement
$assetpack_error # uncoverable statement
.= 'If you invoked this service for development (from a Git checkout) you probably just need to'
. ' invoke "make node_modules" before running this service. If you invoked this service via a packaged binary/service'
. " then there is probably a problem with the packaging.\n"
if $assetpack_error =~ qr/could not find input asset.*node_modules/i; # uncoverable statement
die $assetpack_error; # uncoverable statement
}

# set cookie timeout to 48 hours (will be updated on each request)
$self->app->sessions->default_expiration(48 * 60 * 60);
Expand Down

0 comments on commit 1d22005

Please sign in to comment.