IntegreSQL client for managing isolated PostgreSQL databases in integration tests
npm install @devoxa/integresql-client
Installation •
Usage •
Contributors •
License
``bash`
yarn add --dev @devoxa/integresql-client
**To install IntegreSQL, please follow their
installation instructions.**
For a full usage example, have a look the integration tests.
1. Initialize the IntegreSQL client
`ts
import { IntegreSQLClient } from '@devoxa/integresql-client'
const integreSQL = new IntegreSQLClient({ url: 'http://localhost:5000' })
// options.url: The URL of the IntegreSQL instance
`
2. (Once per test runner process) Get a hash of the migrations & fixtures
`ts`
// The hash can be generated in any way that fits your business logic, the included
// helper creates a SHA1 hash of the file content of all files matching the glob patterns.
const hash = await integreSQL.hashFiles(['./migrations//', './fixtures//'])
3. (Once per test runner process) Initialize the template database
`ts`
await integreSQL.initializeTemplate(hash, async (databaseConfig) => {
await migrateTemplateDatabase(databaseConfig)
await seedTemplateDatabase(databaseConfig)
await disconnectFromDatabase(databaseConfig)
})
4. (Before each test) Get a isolated test database
`ts`
const databaseConfig = await integreSQL.getTestDatabase(hash)
- integreSQL.databaseConfigToConnectionUrl(databaseConfig)
- Converts the database configuration object into a
connection URL
You can directly send requests to the IntegreSQL instance via the included API client, or optionally
instantiate a new IntegreSQLApiClient yourself.
`ts
await integreSQL.api.reuseTestDatabase(hash, id)
const api = new IntegreSQLApiClient({ url: 'http://localhost:5000' })
await api.reuseTestDatabase(hash, id)
``
Thanks goes to these wonderful people (emoji key):
David Reeß 💻 📖 ⚠️ | Pedro Saratscheff 💻 ⚠️ |
This project follows the all-contributors
specification. Contributions of any kind welcome!
MIT