import { Connection , createConnection , getConnection , ConnectionOptions } from 'typeorm' ; import { TestEntityRelationEntity } from './test-entity-relation.entity' ; import { TestRelation } from './test-relation.entity' ; import { TestSoftDeleteEntity } from './test-soft-delete.entity' ; import { TestEntity } from './test.entity' ; import { seed } from './seeds' ; import { RelationOfTestRelationEntity } from './relation-of-test-relation.entity' ; export const CONNECTION_OPTIONS = { type : 'sqlite' , database : ':memory:' , dropSchema : true , entities : [ TestEntity , TestSoftDeleteEntity , TestRelation , TestEntityRelationEntity , RelationOfTestRelationEntity ] , synchronize : true , logging : false , } ; export function createTestConnection ( ) { return createConnection ( CONNECTION_OPTIONS ) ; } export function closeTestConnection ( ) { return getConnection ( ) . close ( ) ; } export function getTestConnection ( ) { return getConnection ( ) ; } const tables = [ 'test_entity' , 'relation_of_test_relation_entity' , 'test_relation' , 'test_entity_relation_entity' , 'test_soft_delete_entity' , 'test_entity_many_test_relations_test_relation' , ] ; export const truncate = async ( connection ) : Promise < void > => { await tables . reduce ( async ( prev , table ) => { await prev ; await connection . query ( `DELETE FROM ${ table }` ) ; } , Promise . resolve ( ) ) ; } ; export const refresh = async ( connection = getConnection ( ) ) : Promise < void > => { await truncate ( connection ) ; return seed ( connection ) ; } ;