Skip to content

Commit 60ce05c

Browse files
authored
Use correct interface (#912)
1 parent d3b4ecc commit 60ce05c

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

packages/app/universal-testing-utils/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Reusable testing utilities that are potentially relevant for both backend and fr
3434
import { buildRestContract } from '@lokalise/api-contracts'
3535
import { sendByContract } from '@lokalise/frontend-http-client'
3636
import { setupServer } from 'msw/node'
37-
import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest'
37+
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'
3838
import wretch, { type Wretch } from 'wretch'
3939
import { z } from 'zod/v4'
4040
import { MswHelper } from '@lokalise/universal-testing-utils'
@@ -59,7 +59,7 @@ describe('MswHelper', () => {
5959
const mswHelper = new MswHelper(BASE_URL)
6060
const wretchClient = wretch(BASE_URL)
6161

62-
beforeEach(() => { server.listen({ onUnhandledRequest: 'error' }) })
62+
beforeAll(() => { server.listen({ onUnhandledRequest: 'error' }) })
6363
afterEach(() => { server.resetHandlers() })
6464
afterAll(() => { server.close() })
6565

packages/app/universal-testing-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@lokalise/tsconfig": "^3.1.0",
5858
"@vitest/coverage-v8": "^4.0.15",
5959
"mockttp": "^4.2.1",
60-
"msw": "^2.11.1",
60+
"msw": "^2.13.2",
6161
"rimraf": "^6.0.1",
6262
"typescript": "5.9.3",
6363
"vitest": "^4.0.15",

packages/app/universal-testing-utils/src/MswHelper.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mapRouteToPath } from '@lokalise/api-contracts'
22
import { sendByContract } from '@lokalise/frontend-http-client'
33
import { setupServer } from 'msw/node'
4-
import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest'
4+
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'
55
import wretch from 'wretch'
66
import {
77
getContract,
@@ -25,7 +25,7 @@ describe('MswHelper', () => {
2525
const mswHelper = new MswHelper(BASE_URL)
2626
const wretchClient = wretch(BASE_URL)
2727

28-
beforeEach(() => {
28+
beforeAll(() => {
2929
server.listen({ onUnhandledRequest: 'error' })
3030
})
3131
afterEach(() => {

packages/app/universal-testing-utils/src/MswHelper.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
type JsonBodyType,
1818
type PathParams,
1919
} from 'msw'
20-
import type { SetupServerApi } from 'msw/node'
20+
import type { SetupServer } from 'msw/node'
2121
import type { ZodObject, z } from 'zod/v4'
2222
import { formatSseResponse, type SseMockEvent } from './MockttpHelper.ts'
2323

@@ -96,7 +96,7 @@ function joinURL(base: string, path: string): string {
9696
}
9797

9898
export type MockEndpointParams<PathParamsSchema extends z.Schema | undefined> = {
99-
server: SetupServerApi
99+
server: SetupServer
100100
contract:
101101
| CommonRouteDefinition<any, PathParamsSchema, any, any, any, any, any, any>
102102
| PayloadRouteDefinition<any, any, PathParamsSchema, any, any, any, any, any, any>
@@ -213,7 +213,7 @@ export class MswHelper {
213213
any,
214214
any
215215
>,
216-
server: SetupServerApi,
216+
server: SetupServer,
217217
params: PathParamsSchema extends z.Schema
218218
? MswDualModeMockParams<
219219
InferSchemaInput<PathParamsSchema>,
@@ -243,7 +243,7 @@ export class MswHelper {
243243
Events,
244244
any
245245
>,
246-
server: SetupServerApi,
246+
server: SetupServer,
247247
params: PathParamsSchema extends z.Schema
248248
? MswSseMockParams<
249249
InferSchemaInput<PathParamsSchema>,
@@ -280,14 +280,14 @@ export class MswHelper {
280280
boolean,
281281
any
282282
>,
283-
server: SetupServerApi,
283+
server: SetupServer,
284284
params: PathParamsSchema extends undefined
285285
? MockParamsNoPath<InferSchemaInput<ResponseBodySchema>>
286286
: MockParams<InferSchemaInput<PathParamsSchema>, InferSchemaInput<ResponseBodySchema>>,
287287
): void
288288

289289
// Implementation
290-
mockValidResponse(contract: any, server: SetupServerApi, params: any): void {
290+
mockValidResponse(contract: any, server: SetupServer, params: any): void {
291291
if ('isDualMode' in contract && contract.isDualMode) {
292292
const { resolvedPath, method } = this.resolveStreamingPath(contract, params.pathParams)
293293
const sseBody = formatSseResponse(params.events)
@@ -351,7 +351,7 @@ export class MswHelper {
351351
any,
352352
any
353353
>,
354-
server: SetupServerApi,
354+
server: SetupServer,
355355
params: MswDualModeMockParamsNoPath<
356356
InferSchemaInput<RequestQuerySchema>,
357357
InferSchemaInput<ResponseBodySchema>,
@@ -373,7 +373,7 @@ export class MswHelper {
373373
Events,
374374
any
375375
>,
376-
server: SetupServerApi,
376+
server: SetupServer,
377377
params: MswSseMockParamsNoPath<InferSchemaInput<RequestQuerySchema>, Events>,
378378
): void
379379

@@ -401,12 +401,12 @@ export class MswHelper {
401401
boolean,
402402
any
403403
>,
404-
server: SetupServerApi,
404+
server: SetupServer,
405405
params: MockParamsNoPath<InferSchemaInput<ResponseBodySchema>>,
406406
): void
407407

408408
// Implementation
409-
mockValidResponseWithAnyPath(contract: any, server: SetupServerApi, params: any): void {
409+
mockValidResponseWithAnyPath(contract: any, server: SetupServer, params: any): void {
410410
const pathParams = contract.requestPathParamsSchema
411411
? Object.keys((contract.requestPathParamsSchema as ZodObject<any>).shape).reduce(
412412
(acc, value) => {
@@ -438,7 +438,7 @@ export class MswHelper {
438438
any,
439439
any
440440
>,
441-
server: SetupServerApi,
441+
server: SetupServer,
442442
params: (PathParamsSchema extends z.Schema
443443
? MockWithImplementationParams<any, any, any>
444444
: MockWithImplementationParamsNoPath<any, any, any>) & {
@@ -476,14 +476,14 @@ export class MswHelper {
476476
boolean,
477477
any
478478
>,
479-
server: SetupServerApi,
479+
server: SetupServer,
480480
params: PathParamsSchema extends undefined
481481
? MockWithImplementationParamsNoPath<any, any, any>
482482
: MockWithImplementationParams<any, any, any>,
483483
): void
484484

485485
// Implementation
486-
mockValidResponseWithImplementation(contract: any, server: SetupServerApi, params: any): void {
486+
mockValidResponseWithImplementation(contract: any, server: SetupServer, params: any): void {
487487
if ('isDualMode' in contract && contract.isDualMode) {
488488
const { resolvedPath, method } = this.resolveStreamingPath(contract, params.pathParams)
489489
const sseBody = formatSseResponse(params.events)
@@ -539,7 +539,7 @@ export class MswHelper {
539539
any,
540540
any
541541
>,
542-
server: SetupServerApi,
542+
server: SetupServer,
543543
params: PathParamsSchema extends z.Schema
544544
? MswDualModeMockParams<
545545
InferSchemaInput<PathParamsSchema>,
@@ -555,14 +555,14 @@ export class MswHelper {
555555
contract:
556556
| CommonRouteDefinition<any, PathParamsSchema, any, any, any, any, any, any>
557557
| PayloadRouteDefinition<any, any, PathParamsSchema, any, any, any, any, any, any>,
558-
server: SetupServerApi,
558+
server: SetupServer,
559559
params: PathParamsSchema extends undefined
560560
? MockParamsNoPath<InferSchemaInput<any>>
561561
: MockParams<InferSchemaInput<PathParamsSchema>, InferSchemaInput<any>>,
562562
): void
563563

564564
// Implementation
565-
mockAnyResponse(contract: any, server: SetupServerApi, params: any): void {
565+
mockAnyResponse(contract: any, server: SetupServer, params: any): void {
566566
if ('isDualMode' in contract && contract.isDualMode) {
567567
const { resolvedPath, method } = this.resolveStreamingPath(contract, params.pathParams)
568568
const sseBody = formatSseResponse(params.events)
@@ -612,7 +612,7 @@ export class MswHelper {
612612
any,
613613
any
614614
>,
615-
server: SetupServerApi,
615+
server: SetupServer,
616616
params: (PathParamsSchema extends z.Schema
617617
? { pathParams: InferSchemaInput<PathParamsSchema> }
618618
: { pathParams?: undefined }) & {
@@ -638,7 +638,7 @@ export class MswHelper {
638638
Events,
639639
any
640640
>,
641-
server: SetupServerApi,
641+
server: SetupServer,
642642
params?: (PathParamsSchema extends z.Schema
643643
? { pathParams: InferSchemaInput<PathParamsSchema> }
644644
: { pathParams?: undefined }) &
@@ -649,7 +649,7 @@ export class MswHelper {
649649
): SseEventController<Events>
650650

651651
// Implementation
652-
mockSseStream(contract: any, server: SetupServerApi, params?: any): SseEventController<any> {
652+
mockSseStream(contract: any, server: SetupServer, params?: any): SseEventController<any> {
653653
const pathParams = params?.pathParams
654654
const { resolvedPath, method } = this.resolveStreamingPath(contract, pathParams)
655655
const encoder = new TextEncoder()

0 commit comments

Comments
 (0)