integresql-client
IntegreSQL client for managing isolated PostgreSQL databases in integration tests.
Installation •
Usage •
Contributors •
License
Installation
yarn add --dev @devoxa/integresql-client
To install IntegreSQL, please follow their
installation instructions.
Usage
Full example
For a full usage example, have a look the integration tests.
Step-by-step guide
- Initialize the IntegreSQL client
import { IntegreSQLClient } from '@devoxa/integresql-client'
const integreSQL = new IntegreSQLClient({ url: 'http://localhost:5000' })
- (Once per test runner process) Get a hash of the migrations & fixtures
const hash = await integreSQL.hashFiles(['./migrations/**/*', './fixtures/**/*'])
- (Once per test runner process) Initialize the template database
await integreSQL.initializeTemplate(hash, async (databaseConfig) => {
await migrateTemplateDatabase(databaseConfig)
await seedTemplateDatabase(databaseConfig)
await disconnectFromDatabase(databaseConfig)
})
- (Before each test) Get a isolated test database
const databaseConfig = await integreSQL.getTestDatabase(hash)
Helpers
integreSQL.databaseConfigToConnectionUrl(databaseConfig)
API requests
You can directly send requests to the IntegreSQL instance via the included API client, or optionally
instantiate a new IntegreSQLApiClient
yourself.
await integreSQL.api.reuseTestDatabase(hash, id)
const api = new IntegreSQLApiClient({ url: 'http://localhost:5000' })
await api.reuseTestDatabase(hash, id)
Contributors
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors
specification. Contributions of any kind welcome!
License
MIT