100 lines
14 KiB
JavaScript
100 lines
14 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 callsite_1 = __importDefault(require("callsite"));
|
|
const events_1 = require("events");
|
|
const TRACKING_MARK_RE = /^\$\$testcafe_test_run\$\$(\S+)\$\$$/;
|
|
const STACK_CAPACITY = 5000;
|
|
class TestRunTracker extends events_1.EventEmitter {
|
|
constructor() {
|
|
super();
|
|
this.enabled = false;
|
|
this.activeTestRuns = {};
|
|
}
|
|
_createContextSwitchingFunctionHook(ctxSwitchingFn, patchedArgsCount) {
|
|
const tracker = this;
|
|
return function () {
|
|
const testRunId = tracker.getContextTestRunId();
|
|
if (testRunId) {
|
|
for (let i = 0; i < patchedArgsCount; i++) {
|
|
if (typeof arguments[i] === 'function')
|
|
arguments[i] = tracker.addTrackingMarkerToFunction(testRunId, arguments[i]);
|
|
}
|
|
}
|
|
// @ts-ignore
|
|
return ctxSwitchingFn.apply(this, arguments);
|
|
};
|
|
}
|
|
_getStackFrames() {
|
|
// NOTE: increase stack capacity to seek deep stack entries
|
|
const savedLimit = Error.stackTraceLimit;
|
|
Error.stackTraceLimit = STACK_CAPACITY;
|
|
const frames = (0, callsite_1.default)();
|
|
Error.stackTraceLimit = savedLimit;
|
|
return frames;
|
|
}
|
|
getMarkedFnName(testRunId) {
|
|
return `$$testcafe_test_run$$${testRunId}$$`;
|
|
}
|
|
ensureEnabled() {
|
|
if (!this.enabled) {
|
|
global.setTimeout = this._createContextSwitchingFunctionHook(global.setTimeout, 1);
|
|
global.setInterval = this._createContextSwitchingFunctionHook(global.setInterval, 1);
|
|
global.setImmediate = this._createContextSwitchingFunctionHook(global.setImmediate, 1);
|
|
process.nextTick = this._createContextSwitchingFunctionHook(process.nextTick, 1);
|
|
global.Promise.prototype.then = this._createContextSwitchingFunctionHook(global.Promise.prototype.then, 2);
|
|
global.Promise.prototype.catch = this._createContextSwitchingFunctionHook(global.Promise.prototype.catch, 1);
|
|
this.enabled = true;
|
|
}
|
|
}
|
|
addTrackingMarkerToFunction(testRunId, fn, context) {
|
|
const markerFactoryBody = `
|
|
return function ${this.getMarkedFnName(testRunId)} () {
|
|
context = context || this;
|
|
switch (arguments.length) {
|
|
case 0: return fn.call(context);
|
|
case 1: return fn.call(context, arguments[0]);
|
|
case 2: return fn.call(context, arguments[0], arguments[1]);
|
|
case 3: return fn.call(context, arguments[0], arguments[1], arguments[2]);
|
|
case 4: return fn.call(context, arguments[0], arguments[1], arguments[2], arguments[3]);
|
|
default: return fn.apply(context, arguments);
|
|
}
|
|
};
|
|
`;
|
|
return new Function('fn', 'context', markerFactoryBody)(fn, context);
|
|
}
|
|
getContextTestRunId() {
|
|
const frames = this._getStackFrames();
|
|
// OPTIMIZATION: we start traversing from the bottom of the stack,
|
|
// because we'll more likely encounter a marker there.
|
|
// Async/await and Promise machinery executes lots of intrinsics
|
|
// on timers (where we have a marker). And, since a timer initiates a new
|
|
// stack, the marker will be at the very bottom of it.
|
|
for (let i = frames.length - 1; i >= 0; i--) {
|
|
const fnName = frames[i].getFunctionName();
|
|
const match = fnName && fnName.match(TRACKING_MARK_RE);
|
|
if (match)
|
|
return match[1];
|
|
}
|
|
return null;
|
|
}
|
|
resolveContextTestRun() {
|
|
const testRunId = this.getContextTestRunId();
|
|
if (testRunId)
|
|
return this.activeTestRuns[testRunId];
|
|
return null;
|
|
}
|
|
addActiveTestRun(testRun) {
|
|
this.activeTestRuns[testRun.id] = testRun;
|
|
testRun.onAny((eventName, eventData) => this.emit(eventName, { testRun, data: eventData }));
|
|
}
|
|
removeActiveTestRun(id) {
|
|
delete this.activeTestRuns[id];
|
|
}
|
|
}
|
|
// Tracker
|
|
exports.default = new TestRunTracker();
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1ydW4tdHJh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ICBjb250ZXh0ID0gY29udGV4dCB8fCB0aGlzO1xuICAgICAgICAgICAgICAgIHN3aXRjaCAoYXJndW1lbnRzLmxlbmd0aCkge1xuICAgICAgICAgICAgICAgICAgICBjYXNlIDA6IHJldHVybiBmbi5jYWxsKGNvbnRleHQpO1xuICAgICAgICAgICAgICAgICAgICBjYXNlIDE6IHJldHVybiBmbi5jYWxsKGNvbnRleHQsIGFyZ3VtZW50c1swXSk7XG4gICAgICAgICAgICAgICAgICAgIGNhc2UgMjogcmV0dXJuIGZuLmNhbGwoY29udGV4dCwgYXJndW1lbnRzWzBdLCBhcmd1bWVudHNbMV0pO1xuICAgICAgICAgICAgICAgICAgICBjYXNlIDM6IHJldHVybiBmbi5jYWxsKGNvbnRleHQsIGFyZ3VtZW50c1swXSwgYXJndW1lbnRzWzFdLCBhcmd1bWVudHNbMl0pO1xuICAgICAgICAgICAgICAgICAgICBjYXNlIDQ6IHJldHVybiBmbi5jYWxsKGNvbnRleHQsIGFyZ3VtZW50c1swXSwgYXJndW1lbnRzWzFdLCBhcmd1bWVudHNbMl0sIGFyZ3VtZW50c1szXSk7XG4gICAgICAgICAgICAgICAgICAgIGRlZmF1bHQ6IHJldHVybiBmbi5hcHBseShjb250ZXh0LCBhcmd1bWVudHMpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH07XG4gICAgICAgIGA7XG5cbiAgICAgICAgcmV0dXJuIG5ldyBGdW5jdGlvbignZm4nLCAnY29udGV4dCcsIG1hcmtlckZhY3RvcnlCb2R5KShmbiwgY29udGV4dCk7XG4gICAgfVxuXG4gICAgcHVibGljIGdldENvbnRleHRUZXN0UnVuSWQgKCk6IHN0cmluZyB8IG51bGwge1xuICAgICAgICBjb25zdCBmcmFtZXMgPSB0aGlzLl9nZXRTdGFja0ZyYW1lcygpO1xuXG4gICAgICAgIC8vIE9QVElNSVpBVElPTjogd2Ugc3RhcnQgdHJhdmVyc2luZyBmcm9tIHRoZSBib3R0b20gb2YgdGhlIHN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