Skip to content

Commit d859b7f

Browse files
authored
fix: return HttpHandler from fromTraffic and fromOpenApi functions (#74)
1 parent eefab6c commit d859b7f

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/open-api/from-open-api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RequestHandler, HttpHandler, http } from 'msw'
1+
import { HttpHandler, http } from 'msw'
22
import type { OpenAPIV3, OpenAPIV2, OpenAPI } from 'openapi-types'
33
import { parse } from 'yaml'
44
import { normalizeSwaggerUrl } from './utils/normalize-swagger-url.js'
@@ -21,11 +21,11 @@ const supportedHttpMethods = Object.keys(
2121
*/
2222
export async function fromOpenApi(
2323
document: string | OpenAPI.Document | OpenAPIV3.Document | OpenAPIV2.Document,
24-
): Promise<Array<RequestHandler>> {
24+
): Promise<Array<HttpHandler>> {
2525
const parsedDocument =
2626
typeof document === 'string' ? parse(document) : document
2727
const specification = await dereference(parsedDocument)
28-
const requestHandlers: Array<RequestHandler> = []
28+
const requestHandlers: Array<HttpHandler> = []
2929

3030
if (typeof specification.paths === 'undefined') {
3131
return []

src/traffic/from-traffic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { invariant } from 'outvariant'
22
import type Har from 'har-format'
3-
import { RequestHandler, HttpHandler, cleanUrl, delay } from 'msw'
3+
import { HttpHandler, cleanUrl, delay } from 'msw'
44
import { matchesQueryParameters, toResponse } from './utils/har-utils.js'
55

66
export type MapEntryFunction = (entry: Har.Entry) => Har.Entry | undefined
@@ -16,7 +16,7 @@ export type MapEntryFunction = (entry: Har.Entry) => Har.Entry | undefined
1616
export function fromTraffic(
1717
archive: Har.Har,
1818
mapEntry?: MapEntryFunction,
19-
): Array<RequestHandler> {
19+
): Array<HttpHandler> {
2020
invariant(
2121
archive,
2222
'Failed to generate request handlers from traffic: expected an HAR object but got %s.',
@@ -29,7 +29,7 @@ export function fromTraffic(
2929
)
3030

3131
const requestIds = new Set<string>()
32-
const handlers: Array<RequestHandler> = []
32+
const handlers: Array<HttpHandler> = []
3333

3434
// Loop over the HAR entries from right to left.
3535
for (let i = archive.log.entries.length - 1; i >= 0; i--) {

test/oas/petstore.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// @vitest-environment happy-dom
2-
import { RequestHandler } from 'msw'
2+
import { HttpHandler } from 'msw'
33
import { fromOpenApi } from '../../src/open-api/from-open-api.js'
44
import { withHandlers } from '../../test/support/with-handlers.js'
5+
import petstoreSpecification from './fixtures/petstore.json' assert { type: 'json' }
56

6-
const petstoreSpecification = require('./fixtures/petstore.json')
7-
8-
let handlers: RequestHandler[]
7+
let handlers: Array<HttpHandler>
98

109
beforeAll(async () => {
11-
handlers = await fromOpenApi(petstoreSpecification)
10+
handlers = await fromOpenApi(petstoreSpecification as any)
1211
})
1312

1413
const entities = {

test/support/with-handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RequestHandler } from 'msw'
1+
import type { RequestHandler } from 'msw'
22
import { setupServer } from 'msw/node'
33

44
/**

tsconfig.test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"compilerOptions": {
99
"composite": true,
10+
"module": "preserve",
1011
"types": ["vitest/globals"],
1112
"lib": ["dom", "DOM.Iterable"]
1213
},

0 commit comments

Comments
 (0)