From fd8514b2f5cfcd320a0a97fdf62686eb1512e897 Mon Sep 17 00:00:00 2001 From: Dylan Praul Date: Tue, 20 Jul 2021 16:09:35 -0400 Subject: [PATCH] feat(core): internal stack integration with mocha runner Add mocha runner support to the internal stack. Closes #838 --- .../ng-mocks/src/lib/common/ng-mocks-stack.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libs/ng-mocks/src/lib/common/ng-mocks-stack.ts b/libs/ng-mocks/src/lib/common/ng-mocks-stack.ts index 464b4274b8..04024570f0 100644 --- a/libs/ng-mocks/src/lib/common/ng-mocks-stack.ts +++ b/libs/ng-mocks/src/lib/common/ng-mocks-stack.ts @@ -138,11 +138,30 @@ const installJestCircus = () => { return true; }; +// istanbul ignore next +const installMochaReporter = () => { + try { + mocha.setup({ + rootHooks: { + afterAll: stackPop, + beforeAll: () => stackPush('root'), + afterEach: stackPop, + beforeEach: () => stackPush('test'), + }, + }); + + return true; + } catch { + return false; + } +}; + const install = () => { if (!ngMocksUniverse.global.has('reporter-stack-install')) { let installed = false; installed = installJasmineReporter() || /* istanbul ignore next */ installed; installed = installJestCircus() || /* istanbul ignore next */ installed; + installed = installMochaReporter() || /* istanbul ignore next */ installed; // istanbul ignore if if (!installed) { messageCoreChecker();