Skip to content

Commit dd49b56

Browse files
author
ROUSSE Kevin
committed
refactor: update all node & express imports
1 parent 79eb3ba commit dd49b56

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/fixRequestBody.test.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Request } from 'express';
2-
import { ClientRequest, ServerResponse } from 'http';
1+
import express from 'express';
2+
import http from 'http';
33

44
import { fixRequestBody } from './fixRequestBody';
55

66
const fakeProxyRequest = () => {
7-
const proxyRequest = new ClientRequest('http://some-host');
7+
const proxyRequest = new http.ClientRequest('http://some-host');
88
proxyRequest.emit = jest.fn();
99

1010
return proxyRequest;
@@ -16,7 +16,12 @@ test('should not write when body is undefined', () => {
1616
jest.spyOn(proxyRequest, 'setHeader');
1717
jest.spyOn(proxyRequest, 'write');
1818

19-
fixRequestBody(proxyRequest, { body: undefined } as Request, {} as ServerResponse, {});
19+
fixRequestBody(
20+
proxyRequest,
21+
{ body: undefined } as express.Request,
22+
{} as http.ServerResponse,
23+
{}
24+
);
2025

2126
expect(proxyRequest.setHeader).not.toHaveBeenCalled();
2227
expect(proxyRequest.write).not.toHaveBeenCalled();
@@ -28,7 +33,7 @@ test('should not write when body is empty', () => {
2833
jest.spyOn(proxyRequest, 'setHeader');
2934
jest.spyOn(proxyRequest, 'write');
3035

31-
fixRequestBody(proxyRequest, { body: {} } as Request, {} as ServerResponse, {});
36+
fixRequestBody(proxyRequest, { body: {} } as express.Request, {} as http.ServerResponse, {});
3237

3338
expect(proxyRequest.setHeader).not.toHaveBeenCalled();
3439
expect(proxyRequest.write).not.toHaveBeenCalled();
@@ -43,8 +48,8 @@ test('should write when body is not empty and Content-Type is application/json',
4348

4449
fixRequestBody(
4550
proxyRequest,
46-
{ body: { someField: 'some value' } } as Request,
47-
{} as ServerResponse,
51+
{ body: { someField: 'some value' } } as express.Request,
52+
{} as http.ServerResponse,
4853
{}
4954
);
5055

@@ -62,8 +67,8 @@ test('should write when body is not empty and Content-Type is application/x-www-
6267

6368
fixRequestBody(
6469
proxyRequest,
65-
{ body: { someField: 'some value' } } as Request,
66-
{} as ServerResponse,
70+
{ body: { someField: 'some value' } } as express.Request,
71+
{} as http.ServerResponse,
6772
{}
6873
);
6974

src/stubServer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from 'express';
22
import fs from 'fs';
3-
import { IncomingHttpHeaders } from 'http';
3+
import http from 'http';
44

55
import { send } from './proxy';
66

@@ -14,7 +14,7 @@ type Stub = URL | StubFilename | GetStubFilenameFunction;
1414

1515
type Delay = { min: number; max: number };
1616

17-
type CommonConfig = { delay?: Delay; headers?: IncomingHttpHeaders };
17+
type CommonConfig = { delay?: Delay; headers?: http.IncomingHttpHeaders };
1818

1919
type Response = {
2020
[requestMethod in RequestMethod]?: Stub | (CommonConfig & { response: Stub });

0 commit comments

Comments
 (0)