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:
parent
e2c8fca29b
commit
772c3f6682
@ -39,7 +39,11 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
let connection!: Connection
|
let connection!: Connection
|
||||||
let queryRunner: QueryRunner
|
let queryRunner: QueryRunner
|
||||||
|
|
||||||
|
let context: any
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
context = namespace.createContext();
|
||||||
|
(namespace as any).enter(context)
|
||||||
connection = await database.connect()
|
connection = await database.connect()
|
||||||
queryRunner = connection.createQueryRunner()
|
queryRunner = connection.createQueryRunner()
|
||||||
await queryRunner.connect()
|
await queryRunner.connect()
|
||||||
@ -56,7 +60,8 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
namespace.set(CORRELATION_ID, undefined)
|
namespace.set(CORRELATION_ID, undefined)
|
||||||
namespace.set(ENTITY_MANAGER, undefined)
|
namespace.set(ENTITY_MANAGER, undefined)
|
||||||
await connection.close()
|
await connection.close();
|
||||||
|
(namespace as any).exit(context)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
import {Bootstrap} from './application/Bootstrap'
|
import {Bootstrap} from './application/Bootstrap'
|
||||||
import {IAPIDef} from '@rondo.dev/common'
|
import {IAPIDef} from '@rondo.dev/common'
|
||||||
import {NamespaceMock, TestUtils} from './test-utils'
|
import {TestUtils} from './test-utils'
|
||||||
import {config} from './config'
|
import {config} from './config'
|
||||||
|
import {createNamespace} from 'cls-hooked'
|
||||||
|
|
||||||
export const exit = jest.fn()
|
export const exit = jest.fn()
|
||||||
|
|
||||||
const bootstrap = new Bootstrap(
|
const bootstrap = new Bootstrap(
|
||||||
config,
|
config,
|
||||||
new NamespaceMock(),
|
createNamespace('test'),
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user