Very small example project using Behavior Driven Development (BDD) with Cucumber, Node.js and TypeScript to develop an image uploading, downloading and rating web application.
Under development and currently only provides a single microservice with a REST API to upload, download and rate image files.
Important notice: this is only intended as an example project on behavior-driven development with Cucumber. There are many issues that have not been taken into account, such as concurrency, security and user management. The application is in no way intended for any kind of production use in its current state.
The following dependencies are necessary for developing and/or running the application. Dependencies not mentioned here will be resolved through yarn, refer the projects package.json file to see them.
Used to store and retrieve the images. For development you can emulate Azure Storage locally using Azurite. Azurite needs to be configured in loose mode, see this GitHub issue.
For packaging the application as a docker image.
The runtime environment used to execute the application. Requires version 16 or newer.
For dependency management of Node.js packages
Add a .env file containing the following variables:
AZURE_STORAGE_CONNECTION_STRING- Connection string to use for Azure Storage. If you are running Azurite locally for development on port 10000 this would e.g. be
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1; - Required
- Connection string to use for Azure Storage. If you are running Azurite locally for development on port 10000 this would e.g. be
AZURE_STORAGE_CONTAINER_NAME- Container name to use for storing images in Azure Storage.
- Optional, default is
imgrater-images
ACCEPTANCE_TEST_BASE_URL- The base URL to make HTTP requests to in the acceptance tests. If you are running the application locally on port 9001 this would be
http://localhost:9001 - Optional, only required to run acceptance tests
- The base URL to make HTTP requests to in the acceptance tests. If you are running the application locally on port 9001 this would be
PORT- the TCP port the application should listen to for its REST API, e.g.
9001 - Optional, default is
9001
- the TCP port the application should listen to for its REST API, e.g.
- Make sure all necessary dependencies are installed (see Dependencies and Setup above)
- Make sure the application is correctly configured (see Configuration above)
- If not using real Azure Storage make sure that Azurite is running (and configured in loose mode)
- If you wish to run the application with Docker, make sure Docker is installed and running
To run the application locally with ts-node without first transpiling the TypeScript to JavaScript, run the following command
yarn start
Alternatively first transpile the TypeScript code to JavaScript by running the following command:
yarn build
And then launch the application directly using node:
node dist/index.js
To run the application locally with ts-node-dev and automatically restarting on code changes, run the following command:
yarn start:dev
If you want to see the code coverage of the application after executing e.g. acceptance tests, you can launch the application with nyc:
yarn start:coverage
To build a docker image run the following command: yarn docker:build, this will produce a docker image with the tag imgrater.
To start the application using the .env file from the project and exposing port 9001, you can e.g. run the following command:
docker run --env-file .env --publish 9001:9001 imgrater
If you are using Azurite instead of real Azure Storage it needs to be accessible to the docker container. This can be achieved by e.g. running Azurite using docker as well on the same network as the docker container running the application:
- Create a new docker network:
docker network create imgrater_network - Run the application in a docker container attached to this network:
docker run --net imgrater_network --name imgrater --rm --env-file .env.docker --publish 9001:9001 imgrater - Run Azurite (in loose mode) in a docker container attached to the same network:
docker run --net imgrater_network --name azurite --rm --publish 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0 --loose
To stop the running containers you can run: docker stop imgrater and docker stop azurite.
You can also build the docker image and then start both the application and Azurite in docker containers on the same network using the docker-compose.yml file by running the following command:
yarn docker:start
To execute the unit tests for the application, run the following command: yarn test
To run the unit tests and also generate a JUnit-compatible XML report run the following command: yarn test:report
There are acceptance tests for the application written in the Gherkin language. To execute these tests follow these steps:
- Make sure the application is running (e.g. by running
yarn startoryarn docker:startsee previous section on running the application) - Make sure
ACCEPTANCE_TEST_BASE_URLis configured correctly in.env, see previous section on configuration - Run the following command
yarn test:acceptance
To run the acceptance tests and also generate a JUnit-compatible XML report and an HTML report that will be opened in the default browser run the following command:
yarn test:acceptance:report
The application provides a RESTful HTTP API. This is documented with an OpenAPI specification in the file swagger.yaml.