Skip to content

Commit 4ac900c

Browse files
committed
build: dedupe test targets
1 parent 72418cb commit 4ac900c

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

Makefile

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ endif
2222

2323
DOCKER_EXEC := docker exec -it $(CONTAINER_NAME)
2424
DOCKER_CLEAN := docker rm -f $(CONTAINER_NAME) || true
25+
TEST_VOLUMES := \
26+
-v $(PWD)/src/tests:/usr/src/app/tests \
27+
-v $(PWD)/src/examples/simple-server/index.js:/usr/src/app/index.js \
28+
-v $(PWD)/src/examples/simple-server/.config/worker/services.yaml:/home/udx/.config/worker/services.yaml
29+
TEST_ENV := -e NODE_ENV=test
30+
TEST_RUN := docker run --rm $(TEST_VOLUMES) $(TEST_ENV) $(DOCKER_IMAGE)
2531

2632
# Build the Docker image with multi-platform support
2733
build:
@@ -82,38 +88,28 @@ wait-container-ready:
8288
@echo "Container is ready."
8389

8490
# Run all tests in the tests directory
85-
run-all-tests:
91+
run-all-tests: build
8692
@echo "Running all tests in Docker container..."
87-
@docker run --rm \
88-
-v $(PWD)/src/tests:/usr/src/app/tests \
89-
-v $(PWD)/src/examples/simple-server/index.js:/usr/src/app/index.js \
90-
-v $(PWD)/src/examples/simple-server/.config/worker/services.yaml:/home/udx/.config/worker/services.yaml \
91-
-e NODE_ENV=test \
92-
$(DOCKER_IMAGE) \
93+
@$(TEST_RUN) \
9394
/bin/sh -c 'cd /usr/src/app/tests && for test_script in *.sh; do \
9495
echo "Running $$test_script..."; \
9596
sh ./$$test_script || { echo "Test $$test_script failed"; exit 1; }; \
9697
done'
9798

9899
# Run a specific test script
99-
run-test:
100+
run-test: build
100101
@if [ -z "$(TEST_SCRIPT)" ]; then \
101102
echo "TEST_SCRIPT is required (e.g., make run-test TEST_SCRIPT=10_validate_environment.sh)"; \
102103
exit 1; \
103104
fi
104105
@echo "Running test $(TEST_SCRIPT) in Docker container..."
105-
@docker run --rm \
106-
-v $(PWD)/src/tests:/usr/src/app/tests \
107-
-v $(PWD)/src/examples/simple-server/index.js:/usr/src/app/index.js \
108-
-v $(PWD)/src/examples/simple-server/.config/worker/services.yaml:/home/udx/.config/worker/services.yaml \
109-
-e NODE_ENV=test \
110-
$(DOCKER_IMAGE) \
106+
@$(TEST_RUN) \
111107
/bin/sh -c 'cd /usr/src/app/tests && sh ./$(TEST_SCRIPT)'
112108

113109
# Run validation tests (build and run-all-tests)
114-
test: build run-all-tests
110+
test: run-all-tests
115111
@echo "Validation tests completed."
116112

117113
# Development pipeline (build and test)
118-
dev-pipeline: build test
114+
dev-pipeline: test
119115
@echo "Development pipeline completed successfully."

Makefile.help

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ help:
99
@echo " clean Stop and remove any existing container with the specified name"
1010
@echo " wait-container-ready Wait for the container to be ready by checking application readiness"
1111
@echo " run-test Run a specific test script in the test environment (requires TEST_SCRIPT variable)"
12-
@echo " run-all-tests Run all test scripts in the tests directory with a test environment"
13-
@echo " test Run validation tests (build and run-all-tests)"
14-
@echo " dev-pipeline Execute the full development pipeline (build and test)\n"
12+
@echo " run-all-tests Build the image and run all test scripts"
13+
@echo " test Run validation tests (same as run-all-tests)"
14+
@echo " dev-pipeline Execute the validation pipeline\n"
1515
@echo "Variables (with default values):\n"
1616
@echo " IMAGE_NAME = $(IMAGE_NAME) # Name of the Docker image"
1717
@echo " TAG = $(TAG) # Tag for the Docker image"

0 commit comments

Comments
 (0)