msportalfx-mock
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -87,6 +87,6 @@ /// <reference types="node" /> | ||
* @param {MockFx.Finalization} finalization | ||
* @returns {Promise<void>} | ||
* @returns {Promise<MockFx.Context>} | ||
* @memberof MockFx | ||
*/ | ||
finalizeTest(finalization: MockFx.Finalization): Promise<void>; | ||
finalizeTest(finalization: MockFx.Finalization): Promise<MockFx.Context>; | ||
/** | ||
@@ -123,6 +123,6 @@ * Returns the mock plug-in client code to run in the browser | ||
* @param {MockFx.Context} context | ||
* @returns {Promise<void>} | ||
* @returns {Promise<MockFx.Context>} | ||
* @memberof MockFx | ||
*/ | ||
registerTest(context: MockFx.Context): Promise<void>; | ||
registerTest(context: MockFx.Context): Promise<MockFx.Context>; | ||
private app; | ||
@@ -404,3 +404,3 @@ private certificate; | ||
*/ | ||
matchRequest: (request: ExpressRequest, unmatchedRequests: MockFx.Request[], storedRequests: MockFx.Request[]) => Promise<MockFx.Request | undefined>; | ||
matchRequest: (request: ExpressRequest, unmatchedRequests: MockFx.Request[], storedRequests: MockFx.Request[], testContext?: MockFx.Context) => Promise<MockFx.Request | undefined>; | ||
/** | ||
@@ -407,0 +407,0 @@ * *Replay mode* |
@@ -248,3 +248,3 @@ "use strict"; | ||
* @param {MockFx.Finalization} finalization | ||
* @returns {Promise<void>} | ||
* @returns {Promise<MockFx.Context>} | ||
* @memberof MockFx | ||
@@ -286,3 +286,3 @@ */ | ||
logger_1.logger.finalizeTest(finalization); | ||
return [2 /*return*/]; | ||
return [2 /*return*/, testInstance.context]; | ||
} | ||
@@ -352,3 +352,3 @@ }); | ||
* @param {MockFx.Context} context | ||
* @returns {Promise<void>} | ||
* @returns {Promise<MockFx.Context>} | ||
* @memberof MockFx | ||
@@ -411,3 +411,3 @@ */ | ||
logger_1.logger.registerTest(fullContext); | ||
return [2 /*return*/]; | ||
return [2 /*return*/, fullContext]; | ||
} | ||
@@ -500,5 +500,7 @@ }); | ||
* description: "successful operation" | ||
* schema: | ||
* $ref: "#/definitions/Context" | ||
*/ | ||
this.app.post("/mock/finalizeTest", express.json(), function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var body, error_3; | ||
var body, context, error_3; | ||
return __generator(this, function (_a) { | ||
@@ -525,4 +527,4 @@ switch (_a.label) { | ||
case 1: | ||
_a.sent(); | ||
res.sendStatus(200); | ||
context = _a.sent(); | ||
res.send(context); | ||
return [3 /*break*/, 3]; | ||
@@ -615,2 +617,4 @@ case 2: | ||
* description: "successful operation" | ||
* schema: | ||
* $ref: "#/definitions/Context" | ||
*/ | ||
@@ -645,4 +649,4 @@ this.app.post("/mock/registerTest", express.json(), function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
case 1: | ||
_a.sent(); | ||
res.sendStatus(200); | ||
context = _a.sent(); | ||
res.send(context); | ||
return [3 /*break*/, 3]; | ||
@@ -649,0 +653,0 @@ case 2: |
@@ -7,3 +7,3 @@ /// <reference types="node" /> | ||
log: (level: MockFx.LogLevel, message: string) => void; | ||
error: (error: Error) => void; | ||
error: (error: Error, testContext?: MockFx.Context) => void; | ||
telemetry: (telemetry: MockFx.Telemetry) => void; | ||
@@ -20,3 +20,3 @@ finalizeStage: (data: MockFx.Stage) => void; | ||
warn(message: string): void; | ||
error(error: Error): void; | ||
error(error: Error, testContext?: MockFx.Context): void; | ||
telemetry(telemetry: MockFx.Telemetry): void; | ||
@@ -23,0 +23,0 @@ finalizeStage(data: MockFx.Stage): void; |
@@ -34,4 +34,4 @@ "use strict"; | ||
}; | ||
Logger.prototype.error = function (error) { | ||
this.emit("error" /* Error */, error); | ||
Logger.prototype.error = function (error, testContext) { | ||
this.emit("error" /* Error */, error, testContext); | ||
}; | ||
@@ -38,0 +38,0 @@ Logger.prototype.telemetry = function (telemetry) { |
@@ -48,2 +48,3 @@ "use strict"; | ||
var LocationReducer_1 = require("./reducers/LocationReducer"); | ||
var helpers_2 = require("../helpers"); | ||
var insightsRegex = /\/providers\/microsoft.insights\//i; | ||
@@ -69,6 +70,13 @@ var timestampRegex = /\d\d\d\d-\d\d-\d\dT\d\d(%3A|:)\d\d(%3A|:)\d\d(\.\d\d\d)?Z/ig; | ||
} | ||
function checkRequest(request, normalizedUrl, mockRequest) { | ||
return normalizedUrl === mockRequest.metadata.normalizedUrl && | ||
request.method === mockRequest.method && | ||
request.headers.commandname === mockRequest.metadata.command; | ||
function checkRequest(request, normalizedUrl, mockRequest, context) { | ||
if (request.method === mockRequest.method && | ||
request.headers.commandname === mockRequest.metadata.command) { | ||
if (normalizedUrl === mockRequest.metadata.normalizedUrl) { | ||
return true; | ||
} | ||
else { | ||
helpers_2.logErrorIfRequestsDifferOnlyInApiVersion(normalizedUrl, mockRequest.metadata.normalizedUrl, "Proxied request and mock request have same method (" + request.method + ") and commandName (" + request.headers.commandname + ")", context); | ||
} | ||
} | ||
return false; | ||
} | ||
@@ -122,7 +130,7 @@ function createARMTarget(_a) { | ||
}); }, | ||
matchRequest: function (req, unmatchedRequests, storedRequests) { return __awaiter(_this, void 0, void 0, function () { | ||
matchRequest: function (req, unmatchedRequests, storedRequests, context) { return __awaiter(_this, void 0, void 0, function () { | ||
var normalizedUrl, matchedRequest, lastIndex, mockRequest, i, request; | ||
return __generator(this, function (_a) { | ||
normalizedUrl = getNormalizedUrl(req.originalUrl); | ||
matchedRequest = unmatchedRequests.find(function (mockRequest) { return checkRequest(req, normalizedUrl, mockRequest); }); | ||
matchedRequest = unmatchedRequests.find(function (mockRequest) { return checkRequest(req, normalizedUrl, mockRequest, context); }); | ||
// If no unmatched request, look through the previously matched requests | ||
@@ -137,3 +145,3 @@ // and find the last one that matches and return that again if no subsequent | ||
// Skip requests until we get to the last matched request | ||
if (mockRequest.matched && checkRequest(req, normalizedUrl, mockRequest)) { | ||
if (mockRequest.matched && checkRequest(req, normalizedUrl, mockRequest, context)) { | ||
matchedRequest = mockRequest; | ||
@@ -140,0 +148,0 @@ break; |
@@ -70,3 +70,3 @@ "use strict"; | ||
unmatchedRequests = this.requests.filter(function (request) { return !request.matched; }); | ||
return [4 /*yield*/, this.definition.matchRequest(req, unmatchedRequests, this.requests)]; | ||
return [4 /*yield*/, this.definition.matchRequest(req, unmatchedRequests, this.requests, this.context)]; | ||
case 3: | ||
@@ -73,0 +73,0 @@ matchedRequest = (_d.sent()); |
{ | ||
"name": "msportalfx-mock", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "msportalfx-mock", | ||
@@ -5,0 +5,0 @@ "main": "./lib/src/app.js", |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
651530
176
11131