Use real cls-hooked in tests instead of NamespaceMock

https://github.com/Jeff-Lewis/cls-hooked/issues/17#issuecomment-510168720

Note: uses undocumented methods ns.enter(context) and ns.exit(context)
This commit is contained in:
Jerko Steiner 2019-08-26 11:14:08 +07:00
parent e2c8fca29b
commit 772c3f6682
2 changed files with 9 additions and 3 deletions

View File

@ -39,7 +39,11 @@ export class TestUtils<T extends IRoutes> {
let connection!: Connection
let queryRunner: QueryRunner
let context: any
beforeEach(async () => {
context = namespace.createContext();
(namespace as any).enter(context)
connection = await database.connect()
queryRunner = connection.createQueryRunner()
await queryRunner.connect()
@ -56,7 +60,8 @@ export class TestUtils<T extends IRoutes> {
await queryRunner.release()
namespace.set(CORRELATION_ID, undefined)
namespace.set(ENTITY_MANAGER, undefined)
await connection.close()
await connection.close();
(namespace as any).exit(context)
})
}

View File

@ -1,13 +1,14 @@
import {Bootstrap} from './application/Bootstrap'
import {IAPIDef} from '@rondo.dev/common'
import {NamespaceMock, TestUtils} from './test-utils'
import {TestUtils} from './test-utils'
import {config} from './config'
import {createNamespace} from 'cls-hooked'
export const exit = jest.fn()
const bootstrap = new Bootstrap(
config,
new NamespaceMock(),
createNamespace('test'),
exit,
)