npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@giltayar/microservices-are-made-for-testing

v1.0.22

Published

Companion code to the "These microservices are made for testing, and testing is what we'll do" talk.

Downloads

36

Readme

microservices-are-made-for-testing

Companion code to the "These microservices are made for testing, and testing is what we'll do" talk.

You can find the talk slides here

This package is a microservice, complete with testing, that gives CRUD functionality to a "tenants" database.

Note! This package uses Node's ESM support, so Node v13 is the minimum version

Installing and running

  • To install and build it, run:
npm ci
npm run build # Builds the docker image
npm test # Tests the microservice
  • To run it as a microservice in a docker container
# run postgres
docker run --name postgres -d -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:12.1
# run the microservice
docker run -d -e "DATABASE_CONNECTION_STRING=postgresql://user:password@postgres:5432/postgres" giltayar/microservices-are-made-for-testing
  • Alternatively, it can be run outside of the docker container, using ./scripts/run-microservices-are-made-for-testing.js (or npm start), and the environment variables as defined below.
# run postgres
docker run -d -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:12.1
export DATABASE_CONNECTION_STRING=postgresql://user:password@localhost:5432/postgres
npm start

Services it depends on

  • Docker: you need it to run the tests, but not necessarily in production
  • Postgres: you don't need to install Postgres to run the tests (because the tests run the Postgres docker container by themselves), but you will need it in a production environment.

Using the package to run the application

const createApp = require('@giltayar/microservices-are-made-for-testing')

// configuration options aee the same as the above corresponding environment variables
const app = createApp({databaseConnectionString: '...'})

// app is a fastify app. Use listen to start it in the usual way for [fastify](https://fastify.io)
await app.listen(/*...*/)

You can see an example of such use in test/commons/setup.js.

Building and Testing

To build and test it:

npm ci
npm run build # Builds the docker image
npm test # Tests the microservice

Tests

Tests can be found in the test folder, where there are three folders:

  • unit: for the unit tests
  • it: for the integration tests, where I run the app using require and HTTP against it to check it
  • e2e: for the "e2e" tests, where I run the app using its docker container and HTTP against it to check it

Publishing

To publish the microservice, do:

npm publish

This will publish both the NPM package and the microservice.