@skuba-lib/vitest-koa-mocks 2.0.0-vitest-koa-mocks-20251204022335 → 2.0.0-vitest-koa-mocks-20251204033835
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Context } from 'koa';
|
|
2
|
+
import { type RequestMethod } from 'node-mocks-http';
|
|
3
|
+
import { vi } from 'vitest';
|
|
4
|
+
import { type MockCookies } from '../createMockCookies/createMockCookies.js';
|
|
5
|
+
export interface MockContext extends Context {
|
|
6
|
+
cookies: MockCookies;
|
|
7
|
+
request: Context['request'] & {
|
|
8
|
+
body?: unknown;
|
|
9
|
+
rawBody?: string;
|
|
10
|
+
session?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface Options<CustomProperties extends object, RequestBody = undefined> {
|
|
14
|
+
url?: string;
|
|
15
|
+
method?: RequestMethod;
|
|
16
|
+
statusCode?: number;
|
|
17
|
+
session?: Record<string, unknown>;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
cookies?: Record<string, string>;
|
|
20
|
+
state?: Record<string, unknown>;
|
|
21
|
+
encrypted?: boolean;
|
|
22
|
+
host?: string;
|
|
23
|
+
requestBody?: RequestBody;
|
|
24
|
+
rawBody?: string;
|
|
25
|
+
throw?: ((status: number, message?: string) => never) | ReturnType<typeof vi.fn>;
|
|
26
|
+
redirect?: ((url: string) => void) | ReturnType<typeof vi.fn>;
|
|
27
|
+
customProperties?: CustomProperties;
|
|
28
|
+
}
|
|
29
|
+
export default function createContext<CustomProperties extends object, RequestBody = undefined>(options?: Options<CustomProperties, RequestBody>): MockContext;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context } from 'koa';
|
|
2
|
+
export type Cookies = Context['cookies'];
|
|
3
|
+
export interface MockCookies extends Cookies {
|
|
4
|
+
requestStore: Map<string, string>;
|
|
5
|
+
responseStore: Map<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export default function createMockCookies(cookies?: Record<string, string>, secure?: boolean): MockCookies;
|
package/lib/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skuba-lib/vitest-koa-mocks",
|
|
3
|
-
"version": "2.0.0-vitest-koa-mocks-
|
|
3
|
+
"version": "2.0.0-vitest-koa-mocks-20251204033835",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Vitest mocks for Koa",
|
|
6
6
|
"homepage": "https://github.com/seek-oss/skuba/tree/main/packages/vitest-koa-mocks#readme",
|