import { Given , setDefaultTimeout , Then } from "@cucumber/cucumber" ; import { TypeDBClient , TypeDBSession , TypeDBTransaction , TypeDBOptions } from "../../../dist" ; import assert = require ( "assert" ) ; interface OptionSetters { [ index ] : ( options : TypeDBOptions , value : string ) => void ; } export const THREAD_POOL_SIZE = 32 ; export let client ; export const sessions = [ ] ; export const sessionsToTransactions = new Map < TypeDBSession , TypeDBTransaction [ ] > ( ) ; export let sessionOptions ; export let transactionOptions ; export const optionSetters = { 'session-idle-timeout-millis' : ( options , value ) => options . sessionIdleTimeoutMillis = Number ( value ) , 'transaction-timeout-millis' : ( options , value ) => options . transactionTimeoutMillis = Number ( value ) } ; setDefaultTimeout ( 20000 ) ; export function tx ( ) { return sessionsToTransactions . get ( sessions [ 0 ] ) [ 0 ] ; } export function setClient ( value ) { client = value ; } export function setSessionOptions ( options ) { sessionOptions = options ; } export function setTransactionOptions ( options ) { transactionOptions = options ; } export async function afterAllBase ( ) { await client . close ( ) ; } export async function beforeBase ( ) { for ( const session of sessions ) { assert ( ! session . isOpen ( ) ) ; } const databases = await client . databases . all ( ) ; for ( const db of databases ) { await db . delete ( ) ; } sessions . length = 0 ; sessionsToTransactions . clear ( ) ; } export async function afterBase ( ) { for ( const session of sessions ) { await session . close ( ) ; } for ( const db of await client . databases . all ( ) ) { await db . delete ( ) ; } } Given ( 'connection has been opened' , ( ) => { assert ( client ) ; assert ( client . isOpen ( ) ) ; } ) ;