@kunk/testing 3.0.30 → 3.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +1 -8
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{afterAll,afterEach,expect,mock,setDefaultTimeout,setSystemTime}from"bun:test";import{PostgresContainer}from"@kunk/docker";import{DatabaseConfig}from"@kunk/server";setSystemTime(new Date(`2025-03-01T09:00:00.000Z`)),setDefaultTimeout(1e4);const db=await PostgresContainer.start();DatabaseConfig.set({uri:`postgresql://app_user:${db.password}@${db.hostname}:${db.port}/${db.database}`,maxPoolSize:3,idleTimeout:5,connectionTimeout:30}),afterAll(async()=>{await db.stop()}),afterEach(async()=>{mock.clearAllMocks(),mock.restore()});function expectToMatchObject(e,t){return expect(e).toMatchObject(t)}async function CLEAR_TEST_DATA(){await db.clear()}export{CLEAR_TEST_DATA,expectToMatchObject};
1
+ import{afterAll,afterEach,expect,mock,setDefaultTimeout,setSystemTime}from"bun:test";import{PostgreSqlContainer}from"@testcontainers/postgresql";import{Wait}from"testcontainers";import{drizzle}from"drizzle-orm/bun-sql";import*as path from"path";import{migrate}from"drizzle-orm/bun-sql/migrator";import"lodash/fp";import"@faker-js/faker";import"drizzle-orm";import*as pg from"drizzle-orm/pg-core";import{DatabaseConfig}from"@kunk/server";async function migrate$1(e){let t=new Bun.SQL(e);if(e.adapter!==`postgres`)throw Error(`Only PostgreSQL is supported`);await t.file(path.resolve(__dirname,`./setup.sql`)),await migrate(drizzle({client:t}),{migrationsFolder:`drizzle/migrations`}),await t`select create_role_with_password('app_user', ${e.password})`,await t`grant writers to app_user`}pg.pgSchema;async function dockerExec(e,t){let n=new(await(import(`dockerode`).then(e=>e.default)));try{let r=await(await n.getContainer(e.getId()??``).exec({Cmd:t,AttachStdout:!0,AttachStderr:!0})).start({abortSignal:AbortSignal.timeout(2e3)}),i=``;r.on(`data`,e=>{i+=e.toString()}),await new Promise(e=>r.on(`end`,e)),console.log(`Output:`,i)}catch{}}var PostgresContainer=class e{container=null;static CLEAR_TEST_DATA;constructor(e){this.options=e}static async start(t={}){let n=new e(t);return await n.start(),n}async start(){let e=!!process.env.LOGGING,t=new PostgreSqlContainer(`postgres:18`).withWaitStrategy(Wait.forLogMessage(`database system is ready to accept connections`,1)).withName(`postgres-${this.database}`).withDatabase(this.database).withUsername(this.username).withPassword(this.password).withResourcesQuota({memory:.5,cpu:1}).withLogConsumer(t=>{t.on(`data`,t=>{e&&console.debug(`PostgreSQL: `,t.toString())})});this.options.port&&(t=t.withReuse().withExposedPorts({container:5432,host:Number(this.options.port)})),this.container=await t.start(),await new Promise(e=>setTimeout(e,1e3)),await migrate$1({adapter:`postgres`,hostname:this.hostname,port:this.port,username:this.username,password:this.password,database:this.database,max:1}),console.log(`DATABASE CONFIG FINISHED`)}get hostname(){return this.container?.getHost()}get port(){return this.container?.getMappedPort(5432)}get username(){return this.options.username??`kunk`}get password(){return this.options.password??`kunk`}get database(){return this.options.database??`kunk`}async stop(){await this.container?.stop(),this.container=null}async clear(){this.container&&await dockerExec(this.container,[`psql`,`--username`,`kunk`,`--password`,`kunk`,`--host`,this.container.getHost(),`--port`,this.container.getMappedPort(5432).toString(),`--database`,`kunk`,`--command`,`DROP DATABASE kunk`])}};setSystemTime(new Date(`2025-03-01T09:00:00.000Z`)),setDefaultTimeout(1e4);const db=await PostgresContainer.start();DatabaseConfig.set({uri:`postgresql://app_user:${db.password}@${db.hostname}:${db.port}/${db.database}`,maxPoolSize:3,idleTimeout:5,connectionTimeout:30}),afterAll(async()=>{await db.stop()}),afterEach(async()=>{mock.clearAllMocks(),mock.restore()});function expectToMatchObject(e,t){return expect(e).toMatchObject(t)}async function CLEAR_TEST_DATA(){await db.clear()}export{CLEAR_TEST_DATA,expectToMatchObject};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kunk/testing",
3
- "version": "3.0.30",
3
+ "version": "3.0.32",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -12,12 +12,5 @@
12
12
  "default": "./dist/index.mjs"
13
13
  },
14
14
  "./package.json": "./package.json"
15
- },
16
- "dependencies": {
17
- "@kunk/api": "3.0.26",
18
- "@kunk/database": "3.0.26",
19
- "@kunk/server": "3.0.25",
20
- "@kunk/model": "3.0.26",
21
- "@kunk/docker": "3.0.26"
22
15
  }
23
16
  }