Skip to content

Commit

Permalink
Merge pull request #255 from myrotvorets/renovate/express-5.x
Browse files Browse the repository at this point in the history
chore(deps): update dependency @types/express to v5
  • Loading branch information
myrotvorets-team authored Dec 20, 2024
2 parents d167fa6 + 0f43456 commit e5cbecc
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 319 deletions.
447 changes: 154 additions & 293 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@
"./dist/src/*.d.mts",
"./dist/src/*.map"
],
"peerDependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"@myrotvorets/buffer-stream": "^1.4.1",
"@myrotvorets/eslint-config-myrotvorets-ts": "^3.0.0",
"@types/express": "^4.17.21",
"@types/express": "^5.0.0",
"@types/express-serve-static-core": "^5.0.0",
"@types/supertest": "^6.0.2",
"c8": "^10.1.2",
"eslint-formatter-gha": "^1.5.1",
"express": "^5.0.0",
"express": "^4.21.2",
"node-reporter-gha": "^2.0.4",
"node-reporter-sonarqube": "^1.0.1",
"supertest": "^7.0.0",
Expand Down
3 changes: 2 additions & 1 deletion test/date.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
import type { Express } from 'express';
Expand All @@ -18,7 +19,7 @@ await describe(':date', async () => {
afterEach(unmockDate);

const checker = (app: Express, stream: WritableBufferStream, expected: string): Promise<unknown> =>
request(app)
request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), expected));

Expand Down
4 changes: 3 additions & 1 deletion test/helpers/setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import express, { type Express, type RequestHandler } from 'express';
export let stream: WritableBufferStream; // NOSONAR
export let app: Express; // NOSONAR

export const genericHandler: RequestHandler = (_req, res) => res.json({ hello: 'world' });
export const genericHandler: RequestHandler = (_req, res) => {
res.json({ hello: 'world' });
};

export function beforeSuite(): void {
stream = new WritableBufferStream();
Expand Down
9 changes: 5 additions & 4 deletions test/logger.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import { app, beforeSuite, beforeTest, genericHandler, stream } from './helpers/setup.mjs';
import { requestLogger } from '../src/index.mjs';
Expand All @@ -24,7 +25,7 @@ await describe('RequestLogger', async () => {
const expectedURL = '/';
const expectedUA = 'WeirdBot/1.2.4';

await request(app)
await request(app as RequestListener)
.get(expectedURL)
.set('X-Forwarded-For', expectedIP)
.set('User-Agent', expectedUA)
Expand All @@ -48,7 +49,7 @@ await describe('RequestLogger', async () => {
const expectedIP = '192.168.1.1';
const expectedURL = '/';
const expectedUA = 'WeirdBot/1.2.4';
await request(app)
await request(app as RequestListener)
.get(expectedURL)
.set('X-Forwarded-For', expectedIP)
.set('User-Agent', expectedUA)
Expand All @@ -72,7 +73,7 @@ await describe('RequestLogger', async () => {
genericHandler,
);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), 'LOGGER says: 200'));
});
Expand All @@ -87,7 +88,7 @@ await describe('RequestLogger', async () => {
genericHandler,
);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString(), ''));
});
Expand Down
3 changes: 2 additions & 1 deletion test/mode.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
import type { Express } from 'express';
Expand All @@ -17,7 +18,7 @@ await describe('Operation Mode', async () => {
expectedURL: string,
expected: string,
): Promise<unknown> =>
request(app)
request(app as RequestListener)
.get(expectedURL)
.expect(() => equal(stream.toString().trimEnd(), expected));

Expand Down
3 changes: 2 additions & 1 deletion test/remote-user.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
import type { Express } from 'express';
Expand All @@ -12,7 +13,7 @@ await describe(':remote-user', async () => {
beforeEach(beforeTest);

const checker = (app: Express, stream: WritableBufferStream, expected: string): Promise<unknown> =>
request(app)
request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), expected));

Expand Down
11 changes: 6 additions & 5 deletions test/req.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
import { app, beforeSuite, beforeTest, genericHandler, stream } from './helpers/setup.mjs';
Expand All @@ -16,15 +17,15 @@ await describe(':req', async () => {
await it('should handle the case when header is not available', async () => {
app.use(requestLogger({ format: ':req[x-ping]', stream }), genericHandler);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => checker(stream, '-'));
});

await it('should handle the case with no parameters', async () => {
app.use(requestLogger({ format: ':req', stream }), genericHandler);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => checker(stream, '-'));
});
Expand All @@ -33,7 +34,7 @@ await describe(':req', async () => {
app.use(requestLogger({ format: ':req[x-ping]', stream }), genericHandler);

const expected = 'pong';
await request(app)
await request(app as RequestListener)
.get('/')
.set('x-ping', expected)
.expect(() => checker(stream, expected));
Expand All @@ -42,7 +43,7 @@ await describe(':req', async () => {
await it('should handle the case when header is available, but empty', async () => {
app.use(requestLogger({ format: ':req[x-ping]', stream }), genericHandler);

await request(app)
await request(app as RequestListener)
.get('/')
.set('x-ping', '')
.expect(() => checker(stream, '-'));
Expand All @@ -58,7 +59,7 @@ await describe(':req', async () => {
genericHandler,
);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => checker(stream, 'pong, pong'));
});
Expand Down
3 changes: 2 additions & 1 deletion test/res.test.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { before, beforeEach, describe, it } from 'node:test';
import type { RequestListener } from 'node:http';
import { equal } from 'node:assert/strict';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
Expand All @@ -12,7 +13,7 @@ await describe(':res', async () => {
beforeEach(beforeTest);

const checker = (app: Express, stream: WritableBufferStream, expected: string): Promise<unknown> =>
request(app)
request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), expected));

Expand Down
3 changes: 2 additions & 1 deletion test/settokenhandler.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
import type { Express } from 'express';
Expand All @@ -14,7 +15,7 @@ await describe('setTokenHandler', async () => {
afterEach(() => setTokenHandler('test', undefined));

const checker = (app: Express, stream: WritableBufferStream, expected: string): Promise<unknown> =>
request(app)
request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), expected));

Expand Down
13 changes: 8 additions & 5 deletions test/total-time.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { before, beforeEach, describe, it } from 'node:test';
import { equal, match } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import { hrtime } from 'node:process';
import request from 'supertest';
import type { Response } from 'express';
Expand All @@ -18,7 +19,7 @@ await describe(':total-time', async () => {
await it('should log the total time', async () => {
app.use(requestLogger({ format: ':total-time', stream }), genericHandler);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => {
const line = stream.toString().trimEnd();
Expand All @@ -35,12 +36,14 @@ await describe(':total-time', async () => {
format: ':total-time',
stream,
}),
(_req, _res, next) => setTimeout(next, timeout),
(_req, _res, next) => {
setTimeout(next, timeout);
},
genericHandler,
);

const now = hrtime.bigint();
await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => {
const duration = +Number((hrtime.bigint() - now) / BigInt(1e6)).toFixed(3);
Expand All @@ -62,7 +65,7 @@ await describe(':total-time', async () => {
genericHandler,
);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), '-'));
});
Expand All @@ -80,7 +83,7 @@ await describe(':total-time', async () => {
genericHandler,
);

await request(app)
await request(app as RequestListener)
.get('/')
.expect(() => equal(stream.toString().trimEnd(), '-'));
});
Expand Down
3 changes: 2 additions & 1 deletion test/url.test.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { before, beforeEach, describe, it } from 'node:test';
import { equal } from 'node:assert/strict';
import type { RequestListener } from 'node:http';
import request from 'supertest';
import type { WritableBufferStream } from '@myrotvorets/buffer-stream';
import type { Express } from 'express';
Expand All @@ -12,7 +13,7 @@ await describe(':url', async () => {
beforeEach(beforeTest);

const checker = (app: Express, stream: WritableBufferStream, expectedURL: string): Promise<unknown> =>
request(app)
request(app as RequestListener)
.get(expectedURL)
.expect(() => equal(stream.toString().trimEnd(), expectedURL));

Expand Down

0 comments on commit e5cbecc

Please sign in to comment.