Skip to content

Commit e94cb27

Browse files
committed
fix tests for node 24
1 parent 990995b commit e94cb27

12 files changed

+81
-76
lines changed

test/881.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { expect } from 'chai';
22
import * as request from 'supertest';
3+
import * as express from 'express';
4+
import * as path from 'path';
5+
import * as http from 'http';
6+
import * as OpenApiValidator from '../src';
37

48
describe('multi-spec', () => {
5-
let app = null;
9+
let app: any = null;
610

711
before(async () => {
812
// Set up the express app
913
app = createServer();
1014
});
1115

1216
after(() => {
13-
app.server.close();
17+
if (app && app.server) (app as any).server.close();
1418
});
1519

1620
it('create campaign should return 200', async () =>
@@ -32,11 +36,6 @@ describe('multi-spec', () => {
3236
});
3337

3438
function createServer() {
35-
const express = require('express');
36-
const path = require('path');
37-
const http = require('http');
38-
const OpenApiValidator = require('../src');
39-
4039
const app = express();
4140
app.use(express.urlencoded({ extended: false }));
4241
app.use(express.text());
@@ -116,6 +115,6 @@ function createServer() {
116115
});
117116
}
118117

119-
app.server = server;
118+
(app as any).server = server;
120119
return app;
121120
}

test/common/app.mw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function createApp(
1515
apiRouter = undefined,
1616
) {
1717
var app = express();
18-
(<any>app).basePath = '/v1';
18+
(app as any).basePath = '/v1';
1919

2020
app.use(express.json());
2121
app.use(express.json({ type: 'application/*+json' }));

test/default.export.fn.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { expect } from 'chai';
44
import * as request from 'supertest';
55
import * as path from 'path';
66
import {OpenAPIV3} from "../src/framework/types";
7+
import { Server } from 'http';
78

89
describe('default export resolver', () => {
9-
let server = null;
10+
let server: Server;
1011
let app = express();
1112

13+
1214
before(async () => {
1315
app.use(
1416
OpenApiValidator.middleware({
15-
apiSpec: <OpenAPIV3.DocumentV3>{
17+
apiSpec: {
1618
openapi: '3.0.0',
1719
info: { version: '1.0.0', title: 'test bug OpenApiValidator' },
1820
paths: {
@@ -25,7 +27,7 @@ describe('default export resolver', () => {
2527
}
2628
},
2729
},
28-
},
30+
} as OpenAPIV3.DocumentV3,
2931
operationHandlers: path.join(__dirname, 'resources'),
3032
}),
3133
);

test/headers.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { expect } from 'chai';
33
import * as request from 'supertest';
44
import { createApp } from './common/app';
55
import * as packageJson from '../package.json';
6+
import { AppWithServer } from './common/app.common';
67

78
describe(packageJson.name, () => {
8-
let app = null;
9+
let app: AppWithServer;
910

1011
/**
1112
* Required to create app for each step, since 'buildMiddleware' is cached by media-type in contentType.
@@ -22,7 +23,7 @@ describe(packageJson.name, () => {
2223
});
2324

2425
afterEach(() => {
25-
(<any>app).server.close();
26+
app.server.close();
2627
});
2728

2829
it('should throw 400 if required header is missing', async () =>

test/invalid.apispec.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('invalid api spec', () => {
1212
apiSpec,
1313
});
1414
await request(app).get('/dev/hello/echo').expect(500);
15-
app.server.close();
15+
app.server!.close();
1616
});
1717
it('should fail gracefully when validateApiSpec is false', async () => {
1818
const apiSpec = createApiSpec();
@@ -21,7 +21,7 @@ describe('invalid api spec', () => {
2121
validateApiSpec: false,
2222
});
2323
await request(app).get('/dev/hello/echo').expect(500);
24-
app.server.close();
24+
app.server!.close();
2525
});
2626
});
2727

@@ -32,17 +32,19 @@ async function createApp(
3232

3333
app.use(OpenApiValidator.middleware(opts));
3434
app.use(
35-
express.Router().get('/dev/hello/echo', (req, res) => {
36-
res.status(200).send((<any>req.params).value);
37-
}),
35+
express
36+
.Router()
37+
.get('/dev/hello/echo', (req: express.Request, res: express.Response) => {
38+
res.status(200).send(req.params.value);
39+
}),
3840
);
3941

4042
await startServer(app, 3001);
4143
return app;
4244
}
4345

4446
function createApiSpec(): OpenAPIV3.DocumentV3 {
45-
return <any>{
47+
return {
4648
openapi: '3.0.3',
4749
info: {
4850
title: 'The API',
@@ -69,7 +71,7 @@ function createApiSpec(): OpenAPIV3.DocumentV3 {
6971
summary: 'Responds with the request.',
7072
description: '',
7173
responses: { '200': { description: 'OK' } },
72-
parameters: { q: 'string' }, // <-- THE INCORRECT BIT
74+
parameters: { q: 'string' } as any, // <-- THE INCORRECT BIT
7375
tags: ['dev/hello'],
7476
},
7577
},

test/multi.spec.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { expect } from 'chai';
22
import * as request from 'supertest';
3+
import * as express from 'express';
4+
import * as path from 'path';
5+
import * as http from 'http';
6+
import * as OpenApiValidator from '../src';
37

48
describe('multi-spec', () => {
5-
let app = null;
9+
let app: any = null;
610

711
before(async () => {
812
// Set up the express app
913
app = createServer();
1014
});
1115

1216
after(() => {
13-
app.server.close();
17+
if (app && app.server) (app as any).server.close();
1418
});
1519

1620
it('create campaign should return 200', async () =>
@@ -32,11 +36,6 @@ describe('multi-spec', () => {
3236
});
3337

3438
function createServer() {
35-
const express = require('express');
36-
const path = require('path');
37-
const http = require('http');
38-
const OpenApiValidator = require('../src');
39-
4039
const app = express();
4140
app.use(express.urlencoded({ extended: false }));
4241
app.use(express.text());
@@ -115,6 +114,6 @@ function createServer() {
115114
});
116115
}
117116

118-
app.server = server;
117+
(app as any).server = server;
119118
return app;
120119
}

test/multipart.disabled.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe(packageJson.name, () => {
3737
);
3838
});
3939
after(() => {
40-
(<any>app).server.close();
40+
app.server.close();
4141
});
4242
describe(`multipart disabled`, () => {
4343
it('should throw 400 when required multipart file field', async () =>

test/multipart.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('a multipart request', () => {
4444
fileNames.length = 0;
4545
});
4646
after(() => {
47-
(<any>app).server.close();
47+
app.server.close();
4848
});
4949

5050
describe('that contains $refs', () => {
@@ -129,7 +129,7 @@ describe('a multipart request', () => {
129129

130130
const imgStream = fs.createReadStream(testImage);
131131
imgStream.on('end', () => req.end(done));
132-
imgStream.pipe(<any>req, { end: false });
132+
imgStream.pipe(req as any, { end: false });
133133
});
134134

135135
it('should validate multipart file and metadata', async () => {
@@ -162,7 +162,7 @@ describe('when request does not use parsers', () => {
162162
let app;
163163

164164
after(() => {
165-
(<any>app).server.close();
165+
app.server.close();
166166
});
167167

168168
before(async () => {

test/openapi.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { expect } from 'chai';
33
import * as request from 'supertest';
44
import { createApp } from './common/app';
55
import * as packageJson from '../package.json';
6+
import { AppWithServer } from './common/app.common';
67

78
describe(packageJson.name, () => {
8-
const apps = [];
9-
let basePath = null;
9+
const apps: AppWithServer[] = [];
10+
let basePath;
1011

1112
before(() => {
1213
const apiSpecPath = path.join('test', 'resources', 'openapi.yaml');
@@ -33,7 +34,7 @@ describe(packageJson.name, () => {
3334
]).then(([a1, a2]) => {
3435
apps.push(a1);
3536
apps.push(a2);
36-
basePath = (<any>a1).basePath;
37+
basePath = a1.basePath;
3738
});
3839
});
3940

test/operation.handler.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as resolvers from '../src/resolvers';
77
import { createApp } from './common/app';
88
import { OpenApiValidatorOpts } from '../src/framework/types';
99
import * as pkg from '../package.json';
10+
import { AppWithServer } from './common/app.common';
1011

1112
const expressVersion = pkg.devDependencies.express;
1213

@@ -20,7 +21,7 @@ describe('operation handler', () => {
2021
const mwf = OpenApiValidator.middleware;
2122
app.use(mwf({ apiSpec }));
2223

23-
expect((<any>mwf)._oav)
24+
expect((mwf as any)._oav)
2425
.to.have.property('options')
2526
.to.deep.include({ operationHandlers: false });
2627

@@ -38,7 +39,7 @@ describe('operation handler', () => {
3839
const mwf = OpenApiValidator.middleware;
3940
app.use(mwf({ apiSpec }));
4041

41-
expect((<any>mwf)._oav)
42+
expect((mwf as any)._oav)
4243
.to.have.property('options')
4344
.to.deep.include({ operationHandlers: false });
4445
});
@@ -55,7 +56,7 @@ describe('operation handler', () => {
5556

5657
app.use(oav);
5758

58-
expect((<any>mwf)._oav)
59+
expect((mwf as any)._oav)
5960
.to.have.property('options')
6061
.to.deep.include({
6162
operationHandlers: {
@@ -87,7 +88,7 @@ describe('operation handler', () => {
8788

8889
app.use(oav);
8990

90-
expect((<any>mwf)._oav)
91+
expect((mwf as any)._oav)
9192
.to.have.property('options')
9293
.to.deep.include({ operationHandlers: handler });
9394

@@ -96,8 +97,8 @@ describe('operation handler', () => {
9697
});
9798

9899
describe('custom operation handler', () => {
99-
let app = null;
100-
let basePath = null;
100+
let app: AppWithServer;
101+
let basePath;
101102
const apiSpec = path.join(
102103
__dirname,
103104
'resources/eov-operations.modulepath.yaml',

0 commit comments

Comments
 (0)