Skip to content

Commit

Permalink
refactor: dont manipulate console global while testing internal errors
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Feb 1, 2023
1 parent 2e6eb13 commit bc3195a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 73 deletions.
25 changes: 0 additions & 25 deletions src/__tests__/__snapshots__/use.ts.snap

This file was deleted.

48 changes: 0 additions & 48 deletions src/__tests__/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
async () => {
const { url, server } = await startTServer();

// errors musts be reported to the console
const consoleErrorFn = jest.fn();
console.error = consoleErrorFn;

const client = await createTClient(url);

const emittedError = new Error("I'm a teapot");
Expand All @@ -407,14 +403,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
expect(event.code).toBe(CloseCode.InternalServerError); // CloseCode.InternalServerError: Internal server error
expect(event.reason).toBe(emittedError.message);
expect(event.wasClean).toBeTruthy(); // because the server reported the error

expect(consoleErrorFn).toBeCalledTimes(1);
expect(consoleErrorFn.mock.calls[0][0]).toMatchSnapshot();
expect(consoleErrorFn.mock.calls[0][1]).toBe(emittedError);

console.error = () => {
// silence again
};
});
},
);
Expand All @@ -423,10 +411,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
skipUWS('should limit the server emitted error message size', async () => {
const { url, server, waitForClient } = await startTServer();

// errors musts be reported to the console
const consoleErrorFn = jest.fn();
console.error = consoleErrorFn;

const client = await createTClient(url);
client.ws.send(
stringifyMessage<MessageType.ConnectionInit>({
Expand All @@ -446,14 +430,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
expect(event.code).toBe(CloseCode.InternalServerError);
expect(event.reason).toBe('Internal server error');
expect(event.wasClean).toBeTruthy(); // because the server reported the error

expect(consoleErrorFn).toBeCalledTimes(1);
expect(consoleErrorFn.mock.calls[0][0]).toMatchSnapshot();
expect(consoleErrorFn.mock.calls[0][1]).toBe(emittedError);

console.error = () => {
// silence again
};
});
});

Expand All @@ -463,10 +439,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
async () => {
const { url, waitForClient } = await startTServer();

// errors musts be reported to the console
const consoleErrorFn = jest.fn();
console.error = consoleErrorFn;

const client = await createTClient(url);

const emittedError = new Error("I'm a teapot");
Expand All @@ -479,14 +451,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
expect(event.code).toBe(CloseCode.InternalServerError); // CloseCode.InternalServerError: Internal server error
expect(event.reason).toBe(emittedError.message);
expect(event.wasClean).toBeTruthy(); // because the server reported the error

expect(consoleErrorFn).toBeCalledTimes(1);
expect(consoleErrorFn.mock.calls[0][0]).toMatchSnapshot();
expect(consoleErrorFn.mock.calls[0][1]).toBe(emittedError);

console.error = () => {
// silence again
};
});
},
);
Expand All @@ -495,10 +459,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
skipUWS('should limit the socket emitted error message size', async () => {
const { url, waitForClient } = await startTServer();

// errors musts be reported to the console
const consoleErrorFn = jest.fn();
console.error = consoleErrorFn;

const client = await createTClient(url);
client.ws.send(
stringifyMessage<MessageType.ConnectionInit>({
Expand All @@ -518,14 +478,6 @@ for (const { tServer, skipUWS, startTServer } of tServers) {
expect(event.code).toBe(CloseCode.InternalServerError);
expect(event.reason).toBe('Internal server error');
expect(event.wasClean).toBeTruthy(); // because the server reported the error

expect(consoleErrorFn).toBeCalledTimes(1);
expect(consoleErrorFn.mock.calls[0][0]).toMatchSnapshot();
expect(consoleErrorFn.mock.calls[0][1]).toBe(emittedError);

console.error = () => {
// silence again
};
});
});

Expand Down

0 comments on commit bc3195a

Please sign in to comment.