Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed process.exit not exiting tested method #452

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading