114 lines
19 KiB
JavaScript
114 lines
19 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
|
|
const hook_1 = __importDefault(require("./hook"));
|
|
const parse_user_agent_1 = require("../../utils/parse-user-agent");
|
|
const test_run_tracker_1 = __importDefault(require("../test-run-tracker"));
|
|
const re_executable_promise_1 = __importDefault(require("../../utils/re-executable-promise"));
|
|
const runtime_1 = require("../../errors/runtime");
|
|
const types_1 = require("../../errors/types");
|
|
const DEFAULT_OPTIONS = {
|
|
logRequestHeaders: false,
|
|
logRequestBody: false,
|
|
stringifyRequestBody: false,
|
|
logResponseHeaders: false,
|
|
logResponseBody: false,
|
|
stringifyResponseBody: false,
|
|
};
|
|
const REQUEST_LOGGER_CLASS_NAME = 'RequestLogger';
|
|
class RequestLoggerImplementation extends hook_1.default {
|
|
constructor(requestFilterRuleInit, options) {
|
|
const effectiveOptions = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
RequestLoggerImplementation._assertLogOptions(effectiveOptions);
|
|
const configureResponseEventOptions = new testcafe_hammerhead_1.ConfigureResponseEventOptions(effectiveOptions.logResponseHeaders, effectiveOptions.logResponseBody);
|
|
super(requestFilterRuleInit, configureResponseEventOptions);
|
|
this._className = REQUEST_LOGGER_CLASS_NAME;
|
|
this._options = effectiveOptions;
|
|
this._internalRequests = {};
|
|
}
|
|
static _assertLogOptions(logOptions) {
|
|
if (!logOptions.logRequestBody && logOptions.stringifyRequestBody)
|
|
throw new runtime_1.APIError('RequestLogger', types_1.RUNTIME_ERRORS.requestHookConfigureAPIError, 'RequestLogger', 'Cannot stringify the request body because it is not logged. Specify { logRequestBody: true } in log options.');
|
|
if (!logOptions.logResponseBody && logOptions.stringifyResponseBody)
|
|
throw new runtime_1.APIError('RequestLogger', types_1.RUNTIME_ERRORS.requestHookConfigureAPIError, 'RequestLogger', 'Cannot stringify the response body because it is not logged. Specify { logResponseBody: true } in log options.');
|
|
}
|
|
async onRequest(event) {
|
|
const loggedReq = {
|
|
id: event._requestInfo.requestId,
|
|
testRunId: event._requestInfo.sessionId,
|
|
userAgent: (0, parse_user_agent_1.parseUserAgent)(event._requestInfo.userAgent).prettyUserAgent,
|
|
request: {
|
|
timestamp: Date.now(),
|
|
url: event._requestInfo.url,
|
|
method: event._requestInfo.method,
|
|
},
|
|
};
|
|
if (this._options.logRequestHeaders)
|
|
loggedReq.request.headers = Object.assign({}, event._requestInfo.headers);
|
|
if (this._options.logRequestBody)
|
|
loggedReq.request.body = this._options.stringifyRequestBody ? event._requestInfo.body.toString() : event._requestInfo.body;
|
|
this._internalRequests[loggedReq.id] = loggedReq;
|
|
}
|
|
async onResponse(event) {
|
|
const loggedReq = this._internalRequests[event.requestId];
|
|
// NOTE: If the 'clear' method is called during a long running request,
|
|
// we should not save a response part - request part has been already removed.
|
|
if (!loggedReq)
|
|
return;
|
|
loggedReq.response = {
|
|
statusCode: event.statusCode,
|
|
timestamp: Date.now(),
|
|
};
|
|
if (this._options.logResponseHeaders)
|
|
loggedReq.response.headers = Object.assign({}, event.headers);
|
|
if (this._options.logResponseBody) {
|
|
loggedReq.response.body = this._options.stringifyResponseBody && event.body
|
|
? event.body.toString()
|
|
: event.body;
|
|
}
|
|
}
|
|
_prepareInternalRequestInfo() {
|
|
const testRun = test_run_tracker_1.default.resolveContextTestRun();
|
|
let preparedRequests = Object.values(this._internalRequests);
|
|
if (testRun)
|
|
preparedRequests = preparedRequests.filter(r => r.testRunId === testRun.id);
|
|
return preparedRequests;
|
|
}
|
|
_getCompletedRequests() {
|
|
return this._prepareInternalRequestInfo().filter(r => r.response);
|
|
}
|
|
// API
|
|
contains(predicate) {
|
|
return re_executable_promise_1.default.fromFn(async () => {
|
|
return !!this._getCompletedRequests().find(predicate);
|
|
});
|
|
}
|
|
count(predicate) {
|
|
return re_executable_promise_1.default.fromFn(async () => {
|
|
return this._getCompletedRequests().filter(predicate).length;
|
|
});
|
|
}
|
|
clear() {
|
|
const testRun = test_run_tracker_1.default.resolveContextTestRun();
|
|
if (testRun) {
|
|
Object.keys(this._internalRequests).forEach(id => {
|
|
if (this._internalRequests[id].testRunId === testRun.id)
|
|
delete this._internalRequests[id];
|
|
});
|
|
}
|
|
else
|
|
this._internalRequests = {};
|
|
}
|
|
get requests() {
|
|
return this._prepareInternalRequestInfo();
|
|
}
|
|
}
|
|
function createRequestLogger(requestFilterRuleInit, logOptions) {
|
|
return new RequestLoggerImplementation(requestFilterRuleInit, logOptions);
|
|
}
|
|
exports.default = createRequestLogger;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVxdWVzdC1sb2dnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBpL3JlcXVlc3QtaG9va3MvcmVxdWVzdC1sb2dnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw2REFLNkI7QUFFN0Isa0RBQWlDO0FBQ2pDLG1FQUE4RDtBQUM5RCwyRUFBaUQ7QUFDakQsOEZBQW9FO0FBQ3BFLGtEQUFnRDtBQUNoRCw4Q0FBb0Q7QUFVcEQsTUFBTSxlQUFlLEdBQTBCO0lBQzNDLGlCQUFpQixFQUFNLEtBQUs7SUFDNUIsY0FBYyxFQUFTLEtBQUs7SUFDNUIsb0JBQW9CLEVBQUcsS0FBSztJQUM1QixrQkFBa0IsRUFBSyxLQUFLO0lBQzVCLGVBQWUsRUFBUSxLQUFLO0lBQzVCLHFCQUFxQixFQUFFLEtBQUs7Q0FDL0IsQ0FBQztBQXlCRixNQUFNLHlCQUF5QixHQUFHLGVBQWUsQ0FBQztBQUVsRCxNQUFNLDJCQUE0QixTQUFRLGNBQVc7SUFJakQsWUFBb0IscUJBQXVFLEVB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