Skip to content

Commit

Permalink
Adapt tests to missing process.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed Nov 8, 2023
1 parent f20c275 commit ebc97c9
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions libs/interpreter-lib/src/parsing-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ describe('Validation of parsing-util', () => {
options?: ParseHelperOptions,
) => Promise<LangiumDocument<AstNode>>;

let exitSpy: jest.SpyInstance;

let services: JayveeServices;

const logger = new CachedLogger(true, undefined, false);
Expand All @@ -39,16 +37,6 @@ describe('Validation of parsing-util', () => {
);

beforeAll(async () => {
// Mock Process.exit
exitSpy = jest
.spyOn(process, 'exit')
.mockImplementation((code?: number) => {
if (code === undefined || code === 0) {
return undefined as never;
}
throw new Error(`process.exit: ${code}`);
});

// Create language services
services = createJayveeServices(NodeFileSystem).Jayvee;

Expand All @@ -64,7 +52,6 @@ describe('Validation of parsing-util', () => {
});

afterEach(() => {
exitSpy.mockClear();
logger.clearLogs();
});

Expand All @@ -81,7 +68,7 @@ describe('Validation of parsing-util', () => {

await parseAndValidateDocument(text);

expect(exitSpy).toHaveBeenCalledTimes(0);
expect(logger.getLogs().error.length).toEqual(0);
expect(logger.getLogs().info).toHaveLength(0);
expect(logger.getLogs().error).toHaveLength(0);
expect(logger.getLogs().debug).toHaveLength(0);
Expand All @@ -97,8 +84,7 @@ describe('Validation of parsing-util', () => {
try {
await parseAndValidateDocument(text);
} catch (e) {
expect(exitSpy).toHaveBeenCalledTimes(1);
expect(exitSpy).toHaveBeenCalledWith(1);
expect(logger.getLogs().error.length).toBeGreaterThanOrEqual(1);
expect(logger.getLogs().info).toHaveLength(0);
expect(logger.getLogs().error).toHaveLength(2 * 5); // 2 calls that get formated to 5 lines each
expect(logger.getLogs().debug).toHaveLength(0);
Expand All @@ -115,8 +101,7 @@ describe('Validation of parsing-util', () => {
try {
await parseAndValidateDocument(text);
} catch (e) {
expect(exitSpy).toHaveBeenCalledTimes(1);
expect(exitSpy).toHaveBeenCalledWith(1);
expect(logger.getLogs().error.length).toEqual(1);
expect(logger.getLogs().info).toHaveLength(0);
expect(logger.getLogs().error).toHaveLength(1);
expect(logger.getLogs().debug).toHaveLength(0);
Expand All @@ -138,7 +123,7 @@ describe('Validation of parsing-util', () => {
logger,
);

expect(exitSpy).toHaveBeenCalledTimes(0);
expect(logger.getLogs().error.length).toEqual(0);
expect(logger.getLogs().info).toHaveLength(0);
expect(logger.getLogs().error).toHaveLength(0);
expect(logger.getLogs().debug).toHaveLength(0);
Expand All @@ -158,7 +143,7 @@ describe('Validation of parsing-util', () => {
logger,
);
} catch (e) {
expect(exitSpy).toHaveBeenCalledTimes(1);
expect(logger.getLogs().error.length).toEqual(1);
expect(logger.getLogs().info).toHaveLength(0);
expect(logger.getLogs().error).toHaveLength(1);
expect(logger.getLogs().error[0]).toEqual(
Expand All @@ -184,7 +169,7 @@ describe('Validation of parsing-util', () => {
logger,
);
} catch (e) {
expect(exitSpy).toHaveBeenCalledTimes(1);
expect(logger.getLogs().error.length).toEqual(1);
expect(logger.getLogs().info).toHaveLength(0);
expect(logger.getLogs().error).toHaveLength(1);
expect(logger.getLogs().error[0]).toMatch(
Expand Down

0 comments on commit ebc97c9

Please sign in to comment.