From 34945df22389d2f048b5814fa1fd96e5bf7581eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20M=C3=BCller?= Date: Mon, 11 Sep 2023 10:05:09 +0200 Subject: [PATCH] Fixed `process.exit` not exiting tested method --- apps/interpreter/src/examples-smoke-test.spec.ts | 5 +++-- libs/execution/test/utils.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/interpreter/src/examples-smoke-test.spec.ts b/apps/interpreter/src/examples-smoke-test.spec.ts index dc9ae0026..6baa108ca 100644 --- a/apps/interpreter/src/examples-smoke-test.spec.ts +++ b/apps/interpreter/src/examples-smoke-test.spec.ts @@ -7,6 +7,7 @@ import * as path from 'path'; import { clearBlockExecutorRegistry, clearConstraintExecutorRegistry, + processExitMockImplementation, } from '@jvalue/jayvee-execution/test'; import { PostgresLoaderExecutorMock, @@ -53,14 +54,14 @@ describe('jv example smoke tests', () => { beforeAll(() => { exitSpy = jest .spyOn(process, 'exit') - // eslint-disable-next-line @typescript-eslint/no-unused-vars - .mockImplementation((code?: number) => undefined as never); + .mockImplementation(processExitMockImplementation); httpExtractorMock = new HttpExtractorExecutorMock(); postgresLoaderMock = new PostgresLoaderExecutorMock(); sqliteLoaderMock = new SQLiteLoaderExecutorMock(); }); afterEach(() => { + exitSpy.mockClear(); httpExtractorMock.restore(); postgresLoaderMock.restore(); sqliteLoaderMock.restore(); diff --git a/libs/execution/test/utils.ts b/libs/execution/test/utils.ts index 90a3e0ca5..516f886a9 100644 --- a/libs/execution/test/utils.ts +++ b/libs/execution/test/utils.ts @@ -28,6 +28,13 @@ export function clearConstraintExecutorRegistry() { constraintExecutorRegistry.clear(); } +export function processExitMockImplementation(code?: number) { + if (code === undefined || code === 0) { + return undefined as never; + } + throw new Error(`process.exit: ${code}`); +} + export function getTestExecutionContext( locator: AstNodeLocator, document: LangiumDocument,