i am building a Backend App in Nodejs. I mock my Database and API with Firestore and Wiremock.
Therefore, i am trying to check for my Integration Tests in my Github Actions Pipeline.
i have tried so far:
- Running the firestore emulator over docker-compose.
This is not the recommended way, but the connection was somehow there in the pipeline.
This is my docker-compose file which the pipeline executed
version: '3.9'
services:
firestore-emulator:
image: mtlynch/firestore-emulator
environment:
- FIRESTORE_PROJECT_ID=test-project
- FIRESTORE_EMULATOR_HOST=firestore-emulator:8888
- PORT=8888
ports:
- 8888:8888
volumes:
- ${PWD}/__test__/firestore-data:/opt/data
wiremock:
image: wiremock/wiremock:3.1.0
container_name: wiremock-container
command: --verbose
ports:
- "1080:8080"
volumes:
- ${PWD}/__test__/wiremock:/home/wiremock
application:
image: europe-west3-docker.pkg.dev/$PROJECT_ID/woopick-registry/$IMAGE_NAME:latest
ports:
- 5000:5000
environment:
NODE_ENV: test
SERVICE_PORT: 5000
WOO_BASE_URL: http://wiremock:8080
JWT_SECRET: secret
FIRESTORE_EMULATOR_HOST: firestore-emulator:8888
FIRESTORE_PROJECT_ID: test-project
PROJECT_ID: test-project
depends_on:
firestore-emulator:
condition: service_started
wiremock:
condition: service_started
my pipeline:
- name: Start wiremock and application
run: |-
docker-compose -f docker-compose.github-pipeline.yml up -d
- name: Check Docker Network
run: docker network ls
- name: Check Wiremock Mount
run: docker exec wiremock-container ls -al /home/wiremock/mappings
- name: Run all the tests
run: npm run test
This is where my test executed. Somehow, at console.log, the correct User is being printed out. But if i call the integration test with httpClient, there was no user found.
describe("Get products test", () => {
beforeEach(async () => {
await insertUser(mockUserWithHashedPassword);
await mambuApiMockServer.requests.deleteAllRequests();
});
afterAll(async () => {
await clearFirestoreData({ projectId: "test-project" });
await Promise.all(apps().map((app) => app.delete()));
});
it("should return a product list", async () => {
const users = await getCollectionDocuments("users");
console.log(users);
const response = await httpClient.get("api/v1/products?per_page=10&page=1", { headers: { authorization: createAuthorizationHeader(mockUserWithHashedPassword.user_id) } });
console.log(response.data);
application_1 | Running on 5000
application_1 | getUsers []
application_1 | warn: GET /products?per_page=10&page=1 - 404 - Not Found ***ERROR*** user not found by id 1
application_1 | info: GET /products?per_page=10&page=1 - 404
At this setup, the firestore emulator can not persist data after being inserted. but the connection was there, i guess?
2. Setting up firestore integration tests over sdk
This is what firebase official docs recommended:
version: '3.9'
services:
wiremock:
image: wiremock/wiremock:3.1.0
container_name: wiremock-container
command: --verbose
ports:
- "1080:8080"
volumes:
- ${PWD}/__test__/wiremock:/home/wiremock
application:
image: europe-west3-docker.pkg.dev/$PROJECT_ID/woopick-registry/$IMAGE_NAME:latest
ports:
- 5000:5000
environment:
NODE_ENV: test
SERVICE_PORT: 5000
WOO_BASE_URL: http://wiremock:8080
FIRESTORE_EMULATOR_HOST: host.docker.internal:8888
JWT_SECRET: secret
PROJECT_ID: test-project
depends_on:
wiremock:
condition: service_started
This works fine locally when i set the FIRESTORE_EMULATOR_HOST to host.docker.internal:8888.But in the pipeline it doesnt connect.In order to run the emulator and test in debug modefirebase, this command is required:
firebase emulators:exec --project=test-project --only firestore 'npm run test'
Any help or suggestion will be appreciated. I was trying on my own since weeks. repo: https://github.com/Woo-Pick-Fullfillment-Inventory/Backend-Woo-Inventory
thank you so much in advance!!!!