UNPKG

3.11 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15Object.defineProperty(exports, "__esModule", { value: true });
16// TODO: Move mock-tracer to its own NPM package once it is complete and tested.
17var opentracing = require("../index");
18var mock_report_1 = require("./mock_report");
19var mock_span_1 = require("./mock_span");
20/**
21 * OpenTracing Tracer implementation designed for use in unit tests.
22 */
23var MockTracer = /** @class */ (function (_super) {
24 __extends(MockTracer, _super);
25 //------------------------------------------------------------------------//
26 // MockTracer-specific
27 //------------------------------------------------------------------------//
28 function MockTracer() {
29 var _this = _super.call(this) || this;
30 _this._spans = [];
31 return _this;
32 }
33 //------------------------------------------------------------------------//
34 // OpenTracing implementation
35 //------------------------------------------------------------------------//
36 MockTracer.prototype._startSpan = function (name, fields) {
37 // _allocSpan is given it's own method so that derived classes can
38 // allocate any type of object they want, but not have to duplicate
39 // the other common logic in startSpan().
40 var span = this._allocSpan();
41 span.setOperationName(name);
42 this._spans.push(span);
43 if (fields.references) {
44 for (var _i = 0, _a = fields.references; _i < _a.length; _i++) {
45 var ref = _a[_i];
46 span.addReference(ref);
47 }
48 }
49 // Capture the stack at the time the span started
50 span._startStack = new Error().stack;
51 return span;
52 };
53 MockTracer.prototype._inject = function (span, format, carrier) {
54 throw new Error('NOT YET IMPLEMENTED');
55 };
56 MockTracer.prototype._extract = function (format, carrier) {
57 throw new Error('NOT YET IMPLEMENTED');
58 };
59 MockTracer.prototype._allocSpan = function () {
60 return new mock_span_1.default(this);
61 };
62 /**
63 * Discard any buffered data.
64 */
65 MockTracer.prototype.clear = function () {
66 this._spans = [];
67 };
68 /**
69 * Return the buffered data in a format convenient for making unit test
70 * assertions.
71 */
72 MockTracer.prototype.report = function () {
73 return new mock_report_1.default(this._spans);
74 };
75 return MockTracer;
76}(opentracing.Tracer));
77exports.MockTracer = MockTracer;
78exports.default = MockTracer;
79//# sourceMappingURL=mock_tracer.js.map
\No newline at end of file