-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use testcontainers for API integration tests
- Loading branch information
Showing
7 changed files
with
1,151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
import { dirname, join } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
import { PostgreSqlContainer } from "@testcontainers/postgresql"; | ||
import { runner } from "node-pg-migrate"; | ||
|
||
import { connectDb, disconnectDb } from "./db.js"; | ||
|
||
beforeAll(() => connectDb()); | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
/** @type {import("@testcontainers/postgresql").StartedPostgreSqlContainer} */ | ||
let dbContainer; | ||
|
||
beforeAll(async () => { | ||
dbContainer = await new PostgreSqlContainer().start(); | ||
const connectionString = dbContainer.getConnectionUri(); | ||
await applyMigrations(connectionString); | ||
await connectDb({ connectionString }); | ||
}, 60_000); | ||
|
||
afterAll(async () => { | ||
await disconnectDb(); | ||
if (dbContainer) { | ||
await dbContainer.stop(); | ||
} | ||
}); | ||
|
||
afterAll(() => disconnectDb()); | ||
async function applyMigrations(databaseUrl) { | ||
await runner({ | ||
databaseUrl, | ||
dir: join(__dirname, "migrations"), | ||
direction: "up", | ||
ignorePattern: "(config|template)\\.cjs$", | ||
}); | ||
} |
Oops, something went wrong.