diff --git a/tests/basic/index.test.ts b/tests/basic/index.test.ts index 93aedec..af6dbab 100644 --- a/tests/basic/index.test.ts +++ b/tests/basic/index.test.ts @@ -4,7 +4,7 @@ import path from 'path' import { TypedData } from 'ydb-sdk' import extractMetadata from '../../src/metadata/extractMetadata' import generateSchema from '../../src/schema' -import database from '../database' +import { getDatabase } from '../database' import setupTable from '../setupTable' import accessTable from './tables/access' import userTable from './tables/user' @@ -13,8 +13,8 @@ import userData from './tables/user/data' const dirname = __dirname.split('/').pop() beforeAll(async () => { - const timeout = 4500 // Should be less then Jest timeout - await database.ready(timeout) + const database = await getDatabase() + await database.tableClient.withSession(async (session) => Promise.all([ setupTable(session, `${dirname}/user`, userTable, userData), @@ -24,6 +24,8 @@ beforeAll(async () => { }) afterAll(async () => { + const database = await getDatabase() + await database.tableClient.withSession(async (session) => Promise.all([ session.dropTable(`${dirname}/user`), @@ -31,10 +33,13 @@ afterAll(async () => { ]) ) await database.schemeClient.removeDirectory(dirname!) + + await database.destroy() }) describe('my database tests', () => { - test('should insert data into the database', async () => { + it('should insert data into the database', async () => { + const database = await getDatabase() const query = `SELECT * FROM \`${dirname}/user\` where id = 1` const result = await database.tableClient.withSessionRetry( async (session) => { @@ -45,7 +50,9 @@ describe('my database tests', () => { ) expect(result[0]['id']).toBe(1) }) - test('should generate correct schema', async () => { + + it('should generate correct schema', async () => { + const database = await getDatabase() const base = path.join(__dirname, './metadata') const metadata = await extractMetadata(base) const gotSchema = await generateSchema(database, metadata)