@shopify/jest-koa-mocks
Advanced tools
Comparing version 0.0.0-snapshot-20230321053525 to 0.0.0-snapshot-20240620045713
@@ -34,3 +34,4 @@ 'use strict'; | ||
} = options; | ||
const extensions = { ...customProperties, | ||
const extensions = { | ||
...customProperties, | ||
throw: throwFn, | ||
@@ -41,3 +42,2 @@ session, | ||
}; | ||
const protocolFallback = encrypted ? 'https' : 'http'; | ||
const req = httpMocks__default["default"].createRequest({ | ||
@@ -53,14 +53,18 @@ url, | ||
} | ||
}); // Some functions we call in the implementations will perform checks for `req.encrypted`, which delegates to the socket. | ||
}); | ||
// Some functions we call in the implementations will perform checks for `req.encrypted`, which delegates to the socket. | ||
// MockRequest doesn't set a fake socket itself, so we create one here. | ||
req.socket = new stream__default["default"].Duplex(); | ||
Object.defineProperty(req.socket, 'encrypted', { | ||
writable: false, | ||
value: protocolFallback === 'https' | ||
value: encrypted | ||
}); | ||
const res = httpMocks__default["default"].createResponse(); // Koa sets a default status code of 404, not the node default of 200 | ||
const res = httpMocks__default["default"].createResponse(); | ||
// Koa sets a default status code of 404, not the node default of 200 | ||
// https://github.com/koajs/koa/blob/master/docs/api/response.md#responsestatus | ||
res.statusCode = 404; | ||
res.statusCode = 404; // This is to get around an odd behavior in the `cookies` library, where if `res.set` is defined, it will use an internal | ||
// This is to get around an odd behavior in the `cookies` library, where if `res.set` is defined, it will use an internal | ||
// node function to set headers, which results in them being set in the wrong place. | ||
@@ -71,4 +75,5 @@ | ||
Object.assign(context, extensions); | ||
context.cookies = createMockCookies["default"](cookies); // ctx.request.body is a common enough custom property for middleware to add that it's handy to just support it by default | ||
context.cookies = createMockCookies["default"](cookies); | ||
// ctx.request.body is a common enough custom property for middleware to add that it's handy to just support it by default | ||
context.request.body = requestBody; | ||
@@ -75,0 +80,0 @@ context.request.rawBody = rawBody; |
@@ -1,4 +0,4 @@ | ||
import { RequestMethod } from 'node-mocks-http'; | ||
import Koa, { Context } from 'koa'; | ||
import { MockCookies } from '../create-mock-cookies'; | ||
import type { RequestMethod } from 'node-mocks-http'; | ||
import type { Context } from 'koa'; | ||
import type { MockCookies } from '../create-mock-cookies'; | ||
export interface Dictionary<T> { | ||
@@ -31,3 +31,3 @@ [key: string]: T; | ||
} | ||
export default function createContext<CustomProperties extends object, RequestBody = undefined>(options?: Options<CustomProperties, RequestBody>): Koa.Context; | ||
export default function createContext<CustomProperties extends object, RequestBody = undefined>(options?: Options<CustomProperties, RequestBody>): Context; | ||
//# sourceMappingURL=create-mock-context.d.ts.map |
{ | ||
"name": "@shopify/jest-koa-mocks", | ||
"version": "0.0.0-snapshot-20230321053525", | ||
"version": "0.0.0-snapshot-20240620045713", | ||
"license": "MIT", | ||
@@ -23,3 +23,3 @@ "description": "Utilities to easily stub Koa context and cookies", | ||
"engines": { | ||
"node": "^14.17.0 || >=16.0.0" | ||
"node": ">=18.12.0" | ||
}, | ||
@@ -31,3 +31,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"@types/express": "^4.11.1", | ||
"@types/express": "^4.17.21", | ||
"@types/koa": "^2.0.0" | ||
@@ -34,0 +34,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
240
21416