Skip to content

Commit

Permalink
chore: work with test container
Browse files Browse the repository at this point in the history
  • Loading branch information
rudemex committed May 4, 2022
1 parent 129ad03 commit 3c9b000
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
3 changes: 1 addition & 2 deletions packages/config/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//const {setupContainers} = require("@tresdoce-nestjs-toolkit/test-utils")
//const container = new setupContainers();

jest.setTimeout(30000);

/*beforeAll(async () => {
console.log("BEFORE ALL")
await container.start()
Expand All @@ -12,6 +10,7 @@ afterAll(async () => {
console.log("AFTER ALL")
await container.stop();
})*/
jest.setTimeout(30000);

expect.extend({
toContainObject(received, argument) {
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/testcontainers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as setupContainers } from './setupContainers';
export { default as setupContainers } from './testContainers';
23 changes: 0 additions & 23 deletions packages/test-utils/src/testcontainers/setupContainers.ts

This file was deleted.

27 changes: 27 additions & 0 deletions packages/test-utils/src/testcontainers/testContainers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//import { GenericContainer } from 'testcontainers';

export default class testContainers {
private static _instance?: testContainers;
private username = 'mdelgado';

constructor(private image: string = 'postgres:13') {
if (testContainers._instance) throw new Error('Use setupContainers.instance instead of new.');
testContainers._instance = this;
}

public static get instance(): testContainers {
return testContainers._instance ?? (testContainers._instance = new testContainers());
}

public async start(): Promise<void> {
console.log('1 START: ', testContainers._instance);
this.username = 'sarasa';
console.log('2 START: ', testContainers._instance);
}

public async stop(): Promise<void> {
console.log('1 STOP: ', testContainers._instance);
this.username = '';
console.log('2 STOP: ', testContainers._instance);
}
}

0 comments on commit 3c9b000

Please sign in to comment.