Skip to content

Commit

Permalink
fix(repository-tests): disconnect datasources after tests finish
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
  • Loading branch information
bajtos committed Aug 11, 2020
1 parent b7cf13f commit c574303
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/repository-tests/src/crud-test-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ export function crudRepositoryTestSuite(
);
before(
withCrudCtx(function setupGlobalDataSource(ctx: CrudTestContext) {
debug('Initializing the shared datasource instance.');
ctx.dataSource = new juggler.DataSource(ctx.dataSourceOptions);
}),
);
after(
withCrudCtx(function destroyGlobalDataSource(ctx: CrudTestContext) {
debug('Disconnecting the shared datasource instance.');
return ctx.dataSource.disconnect();
}),
);

let testFiles = [];

Expand Down
11 changes: 10 additions & 1 deletion packages/repository-tests/src/crud/transactions.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export function transactionSuite(
>;
let tx: Transaction | undefined;
let ds: juggler.DataSource;
let ds2: juggler.DataSource;

before(
withCrudCtx(async function setupRepository(ctx: CrudTestContext) {
ds = ctx.dataSource;
Expand All @@ -85,6 +87,13 @@ export function transactionSuite(
}
});

afterEach(async () => {
if (ds2) {
ds2.disconnect();
(ds2 as unknown) = undefined;
}
});

it('retrieves model instance once transaction is committed', async () => {
tx = await repo.beginTransaction(IsolationLevel.READ_COMMITTED);
const created = await repo.create(
Expand Down Expand Up @@ -149,7 +158,7 @@ export function transactionSuite(
const ds2Options = Object.assign({}, dataSourceOptions);
ds2Options.name = 'anotherDataSource';
ds2Options.database = ds2Options.database + '_new';
const ds2 = new juggler.DataSource(ds2Options);
ds2 = new juggler.DataSource(ds2Options);
const anotherRepo = new repositoryClass(Product, ds2);
await ds2.automigrate(Product.name);

Expand Down

0 comments on commit c574303

Please sign in to comment.