UNPKG

@shopify/react-server

Version:
47 lines (46 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var get_port_1 = tslib_1.__importDefault(require("get-port")); var TestRack = /** @class */ (function () { function TestRack() { this.servers = []; } TestRack.prototype.unmountAll = function () { this.servers.forEach(function (server) { return server.close(); }); }; TestRack.prototype.mount = function (mountFunction, options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var port, ip, server; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, get_port_1.default()]; case 1: port = _a.sent(); ip = 'http://localhost'; server = mountFunction({ port: port, ip: ip }); this.servers.push(server); return [2 /*return*/, { request: function () { return fetch(ip + ":" + port, options).then(function (response) { return response; }); }, }]; } }); }); }; return TestRack; }()); exports.TestRack = TestRack; function mockMiddleware(_, next) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, next()]; case 1: _a.sent(); return [2 /*return*/]; } }); }); } exports.mockMiddleware = mockMiddleware;