MCPcopy
hub / github.com/kysely-org/kysely / TestContext

Class TestContext

example/test/test-context.ts:18–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16import { Pool } from 'pg'
17
18export class TestContext {
19 #app?: App
20
21 request = axios.create({
22 baseURL: `http://localhost:${testConfig.port}`,
23 validateStatus: () => true,
24 })
25
26 get db(): Kysely<Database> {
27 return this.#app!.db
28 }
29
30 before = async (): Promise<void> => {
31 const adminDb = new Kysely<any>({
32 dialect: new PostgresDialect({
33 pool: new Pool(testConfig.adminDatabase),
34 }),
35 })
36
37 // Create our test database
38 const { database } = testConfig.database
39 await sql`drop database if exists ${sql.id(database!)}`.execute(adminDb)
40 await sql`create database ${sql.id(database!)}`.execute(adminDb)
41 await adminDb.destroy()
42
43 // Now connect to the test database and run the migrations
44 const db = new Kysely<any>({
45 dialect: new PostgresDialect({
46 pool: new Pool(testConfig.database),
47 }),
48 })
49
50 const migrator = new Migrator({
51 db,
52 provider: new FileMigrationProvider({
53 fs,
54 path,
55 migrationFolder: path.join(__dirname, '../src/migrations'),
56 }),
57 })
58
59 await migrator.migrateToLatest()
60 await db.destroy()
61 }
62
63 after = async (): Promise<void> => {
64 // Nothing to do here at the moment
65 }
66
67 beforeEach = async (): Promise<void> => {
68 this.#app = new App(testConfig)
69
70 // Clear the database
71 await this.db.deleteFrom('user').execute()
72
73 await this.#app.start()
74 }
75

Callers

nothing calls this directly

Calls 9

createMethod · 0.80
idMethod · 0.80
migrateToLatestMethod · 0.80
startMethod · 0.80
stopMethod · 0.80
executeMethod · 0.65
destroyMethod · 0.65
joinMethod · 0.65
deleteFromMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…