Skip to content

Commit 75aa057

Browse files
author
Aiden
committed
bits and pieces
1 parent ea3a10f commit 75aa057

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"dependencies": {
2525
"fetch-mock": "^9.4.0",
26+
"mock-socket": "^9.0.3",
2627
"query-string": "^5.1.1",
2728
"xhr-mock": "^2.5.1"
2829
},

src/mocks.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import axios from 'axios';
22
import fetchMock from 'fetch-mock';
33
import 'isomorphic-fetch';
4-
import { Server as MockSever } from 'mock-socket';
54
import XHRMock, { proxy } from 'xhr-mock';
65
import {
76
extractScenarioFromLocation,

src/mocks.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,7 @@ export const injectMocks = (
4545
if (!mocks || mocks.length === 0) {
4646
throw new Error('Unable to instantiate mocks');
4747
}
48-
49-
const restMocks = mocks.filter(
50-
(m) => !['GRAPHQL', 'WEBSOCKET'].includes(m.method)
51-
) as HttpMock[];
52-
const graphQLMocks = mocks.filter(
53-
(m) => m.method === 'GRAPHQL'
54-
) as GraphQLMock[];
55-
56-
const webSocketMocks = mocks.filter(
57-
(m) => m.method === 'WEBSOCKET'
58-
) as WebSocketMock[];
48+
const { restMocks, graphQLMocks, webSocketMocks } = getMocksByType(mocks);
5949

6050
restMocks.forEach(handleRestMock);
6151
graphQLMocks.forEach(handleGraphQLMock);
@@ -87,16 +77,11 @@ export const reduceAllMocksForScenario = (
8777

8878
const mocks = defaultMocks.concat(scenarioMocks);
8979

90-
const initialHttpMocks = mocks.filter(
91-
(m) => !['GRAPHQL', 'WEBSOCKET'].includes(m.method)
92-
) as HttpMock[];
93-
const initialGraphQlMocks = mocks.filter(
94-
({ method }) => method === 'GRAPHQL'
95-
) as GraphQLMock[];
96-
97-
const initialWebsocketMocks = mocks.filter(
98-
(m) => m.method === 'WEBSOCKET'
99-
) as WebSocketMock[];
80+
const {
81+
restMocks: initialHttpMocks,
82+
graphQLMocks: initialGraphQlMocks,
83+
webSocketMocks: initialWebsocketMocks,
84+
} = getMocksByType(mocks);
10085

10186
const websocketMocksByUrl = initialWebsocketMocks.reduce<
10287
Record<string, WebSocketMock>
@@ -313,3 +298,17 @@ const handleWebsocketMock = ({ url, server }: WebSocketMock) => {
313298
*/
314299
const addDelay = (delay: number) =>
315300
new Promise((res) => setTimeout(res, delay));
301+
302+
const getMocksByType = (mocks: Mock[]) => {
303+
const restMocks = mocks.filter(
304+
(m) => !['GRAPHQL', 'WEBSOCKET'].includes(m.method)
305+
) as HttpMock[];
306+
const graphQLMocks = mocks.filter(
307+
(m) => m.method === 'GRAPHQL'
308+
) as GraphQLMock[];
309+
310+
const webSocketMocks = mocks.filter(
311+
(m) => m.method === 'WEBSOCKET'
312+
) as WebSocketMock[];
313+
return { restMocks, graphQLMocks, webSocketMocks };
314+
};

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"removeComments": true /* Do not emit comments to output. */,
88
"strict": true /* Enable all strict type-checking options. */,
99
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
10-
"noUnusedLocals": false /* Report errors on unused locals. */,
11-
"noUnusedParameters": false /* Report errors on unused parameters. */,
10+
"noUnusedLocals": true /* Report errors on unused locals. */,
11+
"noUnusedParameters": true /* Report errors on unused parameters. */,
1212
"lib": ["es2017", "dom"],
1313
"esModuleInterop": true
1414
},

yarn.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,13 @@ [email protected]:
34313431
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
34323432
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
34333433

3434+
mock-socket@^9.0.3:
3435+
version "9.0.3"
3436+
resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.0.3.tgz#4bc6d2aea33191e4fed5ec71f039e2bbeb95e414"
3437+
integrity sha512-SxIiD2yE/By79p3cNAAXyLQWTvEFNEzcAO7PH+DzRqKSFaplAPFjiQLmw8ofmpCsZf+Rhfn2/xCJagpdGmYdTw==
3438+
dependencies:
3439+
url-parse "^1.4.4"
3440+
34343441
mri@^1.1.4:
34353442
version "1.1.5"
34363443
resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.5.tgz#ce21dba2c69f74a9b7cf8a1ec62307e089e223e0"
@@ -3918,6 +3925,11 @@ [email protected], querystring@^0.2.0:
39183925
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
39193926
integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=
39203927

3928+
querystringify@^2.1.1:
3929+
version "2.2.0"
3930+
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6"
3931+
integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==
3932+
39213933
react-is@^16.12.0:
39223934
version "16.13.1"
39233935
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
@@ -4101,6 +4113,11 @@ require-main-filename@^2.0.0:
41014113
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
41024114
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
41034115

4116+
requires-port@^1.0.0:
4117+
version "1.0.0"
4118+
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
4119+
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
4120+
41044121
resolve-cwd@^3.0.0:
41054122
version "3.0.0"
41064123
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"
@@ -4739,6 +4756,14 @@ urix@^0.1.0:
47394756
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
47404757
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
47414758

4759+
url-parse@^1.4.4:
4760+
version "1.5.3"
4761+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862"
4762+
integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==
4763+
dependencies:
4764+
querystringify "^2.1.1"
4765+
requires-port "^1.0.0"
4766+
47424767
url@^0.11.0:
47434768
version "0.11.0"
47444769
resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1"

0 commit comments

Comments
 (0)