refactor: Enable stricter test linting

This commit is contained in:
Joachim Van Herwegen
2023-10-27 15:53:52 +02:00
parent 6248ed0938
commit 7a007dc466
48 changed files with 179 additions and 155 deletions

View File

@@ -34,9 +34,10 @@ describe('A WebSocketServerConfigurator', (): void => {
// Clearing the logger mock
jest.clearAllMocks();
server = new EventEmitter() as any;
webSocket = new EventEmitter() as any;
webSocket.send = jest.fn();
webSocket.close = jest.fn();
webSocket = {
send: jest.fn(),
close: jest.fn(),
} as any;
upgradeRequest = new EventEmitter() as any;

View File

@@ -222,7 +222,8 @@ describe('A StaticAssetHandler', (): void => {
it('does not handle a request to a known folder URL with parent path segments.', async(): Promise<void> => {
const request = { method: 'GET', url: '/foo/bar/folder/../def.css' };
const response = createResponse({ eventEmitter: EventEmitter });
await expect(handler.canHandle({ request, response } as any)).rejects.toThrow();
await expect(handler.canHandle({ request, response } as any))
.rejects.toThrow('No static resource configured at /foo/bar/folder/../def.css');
});
it('caches responses when the expires option is set.', async(): Promise<void> => {

View File

@@ -1,4 +1,3 @@
import { EventEmitter } from 'events';
import type { WebSocket } from 'ws';
import { BasicRepresentation } from '../../../../../src/http/representation/BasicRepresentation';
import type { NotificationChannel } from '../../../../../src/server/notifications/NotificationChannel';
@@ -20,9 +19,10 @@ describe('A WebSocket2023Emitter', (): void => {
let emitter: WebSocket2023Emitter;
beforeEach(async(): Promise<void> => {
webSocket = new EventEmitter() as any;
webSocket.send = jest.fn();
webSocket.close = jest.fn();
webSocket = {
send: jest.fn(),
close: jest.fn(),
} as any;
socketMap = new WrappedSetMultiMap();
@@ -46,8 +46,9 @@ describe('A WebSocket2023Emitter', (): void => {
});
it('can send to multiple matching WebSockets.', async(): Promise<void> => {
const webSocket2: jest.Mocked<WebSocket> = new EventEmitter() as any;
webSocket2.send = jest.fn();
const webSocket2: jest.Mocked<WebSocket> = {
send: jest.fn(),
} as any;
socketMap.add(channel.id, webSocket);
socketMap.add(channel.id, webSocket2);
@@ -61,8 +62,9 @@ describe('A WebSocket2023Emitter', (): void => {
});
it('only sends to the matching WebSockets.', async(): Promise<void> => {
const webSocket2: jest.Mocked<WebSocket> = new EventEmitter() as any;
webSocket2.send = jest.fn();
const webSocket2: jest.Mocked<WebSocket> = {
send: jest.fn(),
} as any;
const channel2: NotificationChannel = {
...channel,
id: 'other',

View File

@@ -1,4 +1,3 @@
import { EventEmitter } from 'events';
import type { WebSocket } from 'ws';
import type { HttpRequest } from '../../../../../src/server/HttpRequest';
@@ -36,9 +35,10 @@ describe('A WebSocket2023Listener', (): void => {
let listener: WebSocket2023Listener;
beforeEach(async(): Promise<void> => {
webSocket = new EventEmitter() as any;
webSocket.send = jest.fn();
webSocket.close = jest.fn();
webSocket = {
send: jest.fn(),
close: jest.fn(),
} as any;
upgradeRequest = { url: `/foo/123456` } as any;

View File

@@ -12,6 +12,7 @@ import type { SetMultiMap } from '../../../../../src/util/map/SetMultiMap';
import { WrappedSetMultiMap } from '../../../../../src/util/map/WrappedSetMultiMap';
import { flushPromises } from '../../../../util/Util';
/* eslint-disable jest/prefer-spy-on */
describe('A WebSocket2023Storer', (): void => {
const channel: NotificationChannel = {
id: 'id',