Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/jest-koa-mocks

Package Overview
Dependencies
Maintainers
19
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/jest-koa-mocks - npm Package Compare versions

Comparing version 2.3.3 to 2.3.4

49

build/ts/create-mock-context/create-mock-context.js

@@ -1,24 +0,20 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var url_1 = require("url");
var stream_1 = tslib_1.__importDefault(require("stream"));
var node_mocks_http_1 = tslib_1.__importDefault(require("node-mocks-http"));
var koa_1 = tslib_1.__importDefault(require("koa"));
var create_mock_cookies_1 = tslib_1.__importDefault(require("../create-mock-cookies"));
function createContext(options) {
if (options === void 0) { options = {}; }
var app = new koa_1.default();
var cookies = options.cookies, method = options.method, statusCode = options.statusCode, session = options.session, requestBody = options.requestBody, _a = options.rawBody, rawBody = _a === void 0 ? '' : _a, _b = options.url, url = _b === void 0 ? '' : _b, _c = options.host, host = _c === void 0 ? 'test.com' : _c, _d = options.encrypted, encrypted = _d === void 0 ? false : _d, _e = options.throw, throwFn = _e === void 0 ? jest.fn() : _e, _f = options.redirect, redirect = _f === void 0 ? jest.fn() : _f, _g = options.headers, headers = _g === void 0 ? {} : _g, _h = options.state, state = _h === void 0 ? {} : _h, _j = options.customProperties, customProperties = _j === void 0 ? {} : _j;
var extensions = tslib_1.__assign(tslib_1.__assign({}, customProperties), { throw: throwFn, session: session,
redirect: redirect,
state: state });
var protocolFallback = encrypted ? 'https' : 'http';
var urlObject = new url_1.URL(url, protocolFallback + "://" + host);
var req = node_mocks_http_1.default.createRequest({
import { URL } from 'url';
import stream from 'stream';
import httpMocks from 'node-mocks-http';
import Koa from 'koa';
import createMockCookies from '../create-mock-cookies';
export default function createContext(options = {}) {
const app = new Koa();
const { cookies, method, statusCode, session, requestBody, rawBody = '', url = '', host = 'test.com', encrypted = false, throw: throwFn = jest.fn(), redirect = jest.fn(), headers = {}, state = {}, customProperties = {}, } = options;
const extensions = Object.assign(Object.assign({}, customProperties), { throw: throwFn, session,
redirect,
state });
const protocolFallback = encrypted ? 'https' : 'http';
const urlObject = new URL(url, `${protocolFallback}://${host}`);
const req = httpMocks.createRequest({
url: urlObject.toString(),
method: method,
statusCode: statusCode,
session: session,
headers: tslib_1.__assign({
method,
statusCode,
session,
headers: Object.assign({
// Koa determines protocol based on the `Host` header.

@@ -29,3 +25,3 @@ Host: urlObject.host }, headers),

// MockRequest doesn't set a fake socket itself, so we create one here.
req.socket = new stream_1.default.Duplex();
req.socket = new stream.Duplex();
Object.defineProperty(req.socket, 'encrypted', {

@@ -35,3 +31,3 @@ writable: false,

});
var res = node_mocks_http_1.default.createResponse();
const res = httpMocks.createResponse();
// Koa sets a default status code of 404, not the node default of 200

@@ -43,5 +39,5 @@ // https://github.com/koajs/koa/blob/master/docs/api/response.md#responsestatus

res.set = undefined;
var context = app.createContext(req, res);
const context = app.createContext(req, res);
Object.assign(context, extensions);
context.cookies = create_mock_cookies_1.default(cookies);
context.cookies = createMockCookies(cookies);
// ctx.request.body is a common enough custom property for middleware to add that it's handy to just support it by default

@@ -52,2 +48,1 @@ context.request.body = requestBody;

}
exports.default = createContext;

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var create_mock_context_1 = tslib_1.__importDefault(require("./create-mock-context"));
tslib_1.__exportStar(require("./create-mock-context"), exports);
exports.default = create_mock_context_1.default;
import createMockContext from './create-mock-context';
export * from './create-mock-context';
export default createMockContext;

@@ -1,21 +0,16 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function createMockCookies(cookies, secure) {
if (cookies === void 0) { cookies = {}; }
if (secure === void 0) { secure = true; }
var cookieEntries = Object.keys(cookies).map(function (key) { return [key, cookies[key]]; });
var requestStore = new Map(cookieEntries);
var responseStore = new Map(cookieEntries);
export default function createMockCookies(cookies = {}, secure = true) {
const cookieEntries = Object.keys(cookies).map(key => [key, cookies[key]]);
const requestStore = new Map(cookieEntries);
const responseStore = new Map(cookieEntries);
return {
set: jest.fn(function (key, value) {
set: jest.fn((key, value) => {
return responseStore.set(key, value);
}),
get: jest.fn(function (key) {
get: jest.fn(key => {
return requestStore.get(key);
}),
requestStore: requestStore,
responseStore: responseStore,
secure: secure,
requestStore,
responseStore,
secure,
};
}
exports.default = createMockCookies;

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var create_mock_cookies_1 = tslib_1.__importDefault(require("./create-mock-cookies"));
tslib_1.__exportStar(require("./create-mock-cookies"), exports);
exports.default = create_mock_cookies_1.default;
import createMockCookies from './create-mock-cookies';
export * from './create-mock-cookies';
export default createMockCookies;

@@ -1,6 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var create_mock_context_1 = require("./create-mock-context");
Object.defineProperty(exports, "createMockContext", { enumerable: true, get: function () { return create_mock_context_1.default; } });
var create_mock_cookies_1 = require("./create-mock-cookies");
Object.defineProperty(exports, "createMockCookies", { enumerable: true, get: function () { return create_mock_cookies_1.default; } });
export { default as createMockContext } from './create-mock-context';
export { default as createMockCookies } from './create-mock-cookies';

@@ -8,4 +8,12 @@ # Changelog

## [2.3.2] - 2021-03-03
<!-- ## Unreleased -->
## 2.3.4 - 2021-04-13
### Changed
- Removed dependency on tslib, as we no-longer compile with `tsc`. [#1829](https://github.com/Shopify/quilt/pull/1829)
## 2.3.2 - 2021-03-03
### Fixed

@@ -15,3 +23,3 @@

## [2.3.0] - 2020-12-18
## 2.3.0 - 2020-12-18

@@ -22,7 +30,7 @@ ### Added

## [2.2.4] - 2020-10-20
## 2.2.4 - 2020-10-20
- Updated `tslib` dependency to `^1.14.1`. [#1657](https://github.com/Shopify/quilt/pull/1657)
## [2.2.0] - 2019-12-19
## 2.2.0 - 2019-12-19

@@ -33,3 +41,3 @@ ### Added

## [2.1.7] - 2019-10-23
## 2.1.7 - 2019-10-23

@@ -40,3 +48,3 @@ ### Fixed

## [2.1.0] - 2019-01-18
## 2.1.0 - 2019-01-18

@@ -51,8 +59,8 @@ ### Fixed

## [2.0.15] - 2019-01-11
## 2.0.15 - 2019-01-11
- Fix setting custom state in mock context [#467](https://github.com/Shopify/quilt/pull/467)
## [2.0.14] - 2019-01-09
## 2.0.14 - 2019-01-09
- Start of Changelog
{
"name": "@shopify/jest-koa-mocks",
"version": "2.3.3",
"version": "2.3.4",
"license": "MIT",

@@ -8,5 +8,2 @@ "description": "Utilities to easily stub Koa context and cookies",

"types": "index.d.ts",
"scripts": {
"build": "tsc --p tsconfig.json"
},
"publishConfig": {

@@ -28,4 +25,3 @@ "access": "public",

"koa": "^2.5.0",
"node-mocks-http": "^1.5.8",
"tslib": "^1.14.1"
"node-mocks-http": "^1.5.8"
},

@@ -32,0 +28,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc