Mock unit test an API that uses postgres or integration test API with a "test" database?

This page summarizes the projects mentioned and recommended in the original post on /r/node

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • testcontainers-python

    Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

  • For later stuff, I tend to go all the way, have a separate database that gets seeded, all tests are performed against it, then it gets shut down. Testcontainers work well with this.

  • testcontainers-node

    Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

  • Yup, there's a bunch of them on https://testcontainers.com/. I worked only with Python though, don't have Node projects big enough to implement this.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • integresql

    IntegreSQL manages isolated PostgreSQL databases for your integration tests.

  • For the case of PostgreSQL I've found IntegreSQL and its Javascript client really helpful because it can create a copy of the database per test case, which it helps to write integration tests with real DB calls.

  • integresql-client

    IntegreSQL client for managing isolated PostgreSQL databases in integration tests.

  • For the case of PostgreSQL I've found IntegreSQL and its Javascript client really helpful because it can create a copy of the database per test case, which it helps to write integration tests with real DB calls.

  • pg-transactional-tests

    Wraps each test in transaction for `pg` package

  • How to clean it between test runs? How to have no conflicts between tests that run in parallel? Here is a library to solve this: pg-transactional-tests, I'm going to update in a near day or two so should be working fine, it served me well previously at work projects.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts