Skip to content

Commit

Permalink
Merge pull request #452 from jvalue/bugfix/process-exit-spy-fix
Browse files Browse the repository at this point in the history
Fixed `process.exit` not exiting tested method
  • Loading branch information
f3l1x98 authored Sep 28, 2023
2 parents 0191f6b + 34945df commit 1da1fe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/interpreter/src/examples-smoke-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as path from 'path';
import {
clearBlockExecutorRegistry,
clearConstraintExecutorRegistry,
processExitMockImplementation,
} from '@jvalue/jayvee-execution/test';
import {
PostgresLoaderExecutorMock,
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions libs/execution/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AstNode>,
Expand Down

0 comments on commit 1da1fe3

Please sign in to comment.