From c0afa4f36b0c55c8eca0a3f389f7597fcac17e18 Mon Sep 17 00:00:00 2001 From: tyranron Date: Tue, 1 Nov 2022 11:01:19 +0100 Subject: [PATCH] Improve tests - show output of failed tests - ensure Docker images are not pulled in tests --- Makefile | 8 ++++---- package.json | 2 +- tests/main.bats | 16 ++++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a50caff..9f8e587 100644 --- a/Makefile +++ b/Makefile @@ -65,10 +65,9 @@ test: test.docker # Docker commands # ################### -docker-registries = $(strip $(if $(call eq,$(registries),),\ - $(REGISTRIES),$(subst $(comma), ,$(registries)))) -docker-tags = $(strip $(if $(call eq,$(tags),),\ - $(TAGS),$(subst $(comma), ,$(tags)))) +docker-registries = $(strip \ + $(or $(subst $(comma), ,$(registries)),$(REGISTRIES))) +docker-tags = $(strip $(or $(subst $(comma), ,$(tags)),$(TAGS))) # Build Docker image with the given tag. @@ -180,6 +179,7 @@ endif IMAGE=$(OWNER)/$(NAME):$(or $(tag),$(VERSION)) \ node_modules/.bin/bats \ --timing $(if $(call eq,$(CI),),--pretty,--formatter tap) \ + --print-output-on-failure \ tests/main.bats diff --git a/package.json b/package.json index 84e240a..99180f2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "devDependencies": { - "bats": "^1.1" + "bats": "^1.8" } } diff --git a/tests/main.bats b/tests/main.bats index 94dbfed..eb505ef 100644 --- a/tests/main.bats +++ b/tests/main.bats @@ -2,12 +2,14 @@ @test "Firefox is installed" { - run docker run --rm --entrypoint sh $IMAGE -c 'test -f /opt/firefox/firefox' + run docker run --rm --pull never --entrypoint sh $IMAGE -c \ + 'test -f /opt/firefox/firefox' [ "$status" -eq 0 ] } @test "Firefox runs ok" { - run docker run --rm --entrypoint sh $IMAGE -c '/opt/firefox/firefox --help' + run docker run --rm --pull never --entrypoint sh $IMAGE -c \ + '/opt/firefox/firefox --help' [ "$status" -eq 0 ] } @@ -17,7 +19,7 @@ [ ! "$output" = '' ] expected="$output" - run docker run --rm -e MOZ_HEADLESS=0 --entrypoint sh $IMAGE -c \ + run docker run --rm --pull never -e MOZ_HEADLESS=0 --entrypoint sh $IMAGE -c \ "/opt/firefox/firefox -v" [ "$status" -eq 0 ] [ ! "$output" = '' ] @@ -28,12 +30,14 @@ @test "geckodriver is installed" { - run docker run --rm --entrypoint sh $IMAGE -c 'which geckodriver' + run docker run --rm --pull never --entrypoint sh $IMAGE -c \ + 'which geckodriver' [ "$status" -eq 0 ] } @test "geckodriver runs ok" { - run docker run --rm --entrypoint sh $IMAGE -c 'geckodriver --help' + run docker run --rm --pull never --entrypoint sh $IMAGE -c \ + 'geckodriver --help' [ "$status" -eq 0 ] } @@ -43,7 +47,7 @@ [ ! "$output" = '' ] expected="$output" - run docker run --rm --entrypoint sh $IMAGE -c \ + run docker run --rm --pull never --entrypoint sh $IMAGE -c \ "geckodriver -V | grep -m 1 geckodriver | cut -d ' ' -f2" [ "$status" -eq 0 ] [ ! "$output" = '' ]