@kunk/testing 3.0.35 → 3.0.37

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 -1
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{afterAll,afterEach,expect,mock,setDefaultTimeout,setSystemTime}from"bun:test";import{PostgreSqlContainer}from"@testcontainers/postgresql";import{Wait}from"testcontainers";import{migrate}from"@kunk/database";import{DatabaseConfig}from"@kunk/server";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({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};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kunk/testing",
3
- "version": "3.0.35",
3
+ "version": "3.0.37",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"