UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

1 lines 7.81 kB
(()=>{"use strict";var e={"./istanbul-lib-coverage/index.js"(e,t,a){let{FileCoverage:r}=a("./istanbul-lib-coverage/lib/file-coverage.js"),{CoverageMap:s}=a("./istanbul-lib-coverage/lib/coverage-map.js"),{CoverageSummary:i}=a("./istanbul-lib-coverage/lib/coverage-summary.js");e.exports={createCoverageSummary:e=>e&&e instanceof i?e:new i(e),createCoverageMap:e=>e&&e instanceof s?e:new s(e),createFileCoverage:e=>e&&e instanceof r?e:new r(e)},e.exports.classes={FileCoverage:r}},"./istanbul-lib-coverage/lib/coverage-map.js"(e,t,a){let{FileCoverage:r}=a("./istanbul-lib-coverage/lib/file-coverage.js"),{CoverageSummary:s}=a("./istanbul-lib-coverage/lib/coverage-summary.js");function maybeConstruct(e,t){return e instanceof t?e:new t(e)}function loadMap(e){let t=Object.create(null);return e&&Object.entries(e).forEach(([e,a])=>{t[e]=maybeConstruct(a,r)}),t}let CoverageMap=class CoverageMap{constructor(e){e instanceof CoverageMap?this.data=e.data:this.data=loadMap(e)}merge(e){Object.values(maybeConstruct(e,CoverageMap).data).forEach(e=>{this.addFileCoverage(e)})}filter(e){Object.keys(this.data).forEach(t=>{e(t)||delete this.data[t]})}toJSON(){return this.data}files(){return Object.keys(this.data)}fileCoverageFor(e){let t=this.data[e];if(!t)throw Error(`No file coverage available for: ${e}`);return t}addFileCoverage(e){let t=new r(e),{path:a}=t;this.data[a]?this.data[a].merge(t):this.data[a]=t}getCoverageSummary(){let e=new s;return Object.values(this.data).forEach(t=>{e.merge(t.toSummary())}),e}};e.exports={CoverageMap}},"./istanbul-lib-coverage/lib/coverage-summary.js"(e,t,a){let r=a("./istanbul-lib-coverage/lib/percent.js"),s=a("./istanbul-lib-coverage/lib/data-properties.js");function blankSummary(){let empty=()=>({total:0,covered:0,skipped:0,pct:"Unknown"});return{lines:empty(),statements:empty(),functions:empty(),branches:empty(),branchesTrue:empty()}}function assertValidSummary(e){if(!(e&&e.lines&&e.statements&&e.functions&&e.branches))throw Error("Invalid summary coverage object, missing keys, found:"+Object.keys(e).join(","))}let CoverageSummary=class CoverageSummary{constructor(e){e?e instanceof CoverageSummary?this.data=e.data:this.data=e:this.data=blankSummary(),assertValidSummary(this.data)}merge(e){return["lines","statements","branches","functions","branchesTrue"].forEach(t=>{e[t]&&(this[t].total+=e[t].total,this[t].covered+=e[t].covered,this[t].skipped+=e[t].skipped,this[t].pct=r(this[t].covered,this[t].total))}),this}toJSON(){return this.data}isEmpty(){return 0===this.lines.total}};s(CoverageSummary,["lines","statements","functions","branches","branchesTrue"]),e.exports={CoverageSummary}},"./istanbul-lib-coverage/lib/data-properties.js"(e){e.exports=function(e,t){t.forEach(t=>{Object.defineProperty(e.prototype,t,{enumerable:!0,get(){return this.data[t]}})})}},"./istanbul-lib-coverage/lib/file-coverage.js"(e,t,a){let r=a("./istanbul-lib-coverage/lib/percent.js"),s=a("./istanbul-lib-coverage/lib/data-properties.js"),{CoverageSummary:i}=a("./istanbul-lib-coverage/lib/coverage-summary.js");function emptyCoverage(e,t){let a={path:e,statementMap:{},fnMap:{},branchMap:{},s:{},f:{},b:{}};return t&&(a.bT={}),a}function assertValidObject(e){if(!(e&&e.path&&e.statementMap&&e.fnMap&&e.branchMap&&e.s&&e.f&&e.b))throw Error("Invalid file coverage object, missing keys, found:"+Object.keys(e).join(","))}let keyFromLoc=({start:e,end:t})=>`${e.line}|${e.column}|${t.line}|${t.column}`,isObj=e=>!!e&&"object"==typeof e,isLineCol=e=>isObj(e)&&"number"==typeof e.line&&"number"==typeof e.column,isLoc=e=>isObj(e)&&isLineCol(e.start)&&isLineCol(e.end),getLoc=e=>isLoc(e)?e:isLoc(e.loc)?e.loc:null,findNearestContainer=(e,t)=>{let a=getLoc(e);if(!a)return null;let r=null,s=null,i=null;for(let[e,o]of Object.entries(t)){let t=getLoc(o);if(!t)continue;let n=[a.start.line-t.start.line,a.start.column-t.start.column,t.end.line-a.end.line,t.end.column-a.end.column];if(n[0]<0||n[2]<0||0===n[0]&&n[1]<0||0===n[2]&&n[3]<0)continue;if(null===r){s=n,r=o,i=e;continue}let l=n[0]<s[0]||0===n[0]&&n[1]<s[1],c=n[2]<s[2]||0===n[2]&&n[3]<s[3];(l||c)&&(s=n,r=o,i=e)}return i},addHits=(e,t)=>"number"==typeof e&&"number"==typeof t?e+t:Array.isArray(e)&&Array.isArray(t)?e.map((e,a)=>(e||0)+(t[a]||0)):null,addNearestContainerHits=(e,t,a,r)=>{let s=findNearestContainer(e,a);return s?addHits(t,r[s]):t},mergeProp=(e,t,a,r,s=keyFromLoc)=>{let i={};for(let[a,r]of Object.entries(e)){let e=t[a];i[s(e)]=[r,e]}let o={};for(let[e,t]of Object.entries(a)){let a=r[e];o[s(a)]=[t,a]}let n={};for(let[e,t]of Object.entries(i)){let s=t[0],i=t[1],l=o[e];s=l?addHits(s,l[0]):addNearestContainerHits(i,s,r,a),n[e]=[s,i]}for(let[a,r]of Object.entries(o)){let s=r[0],i=r[1];n[a]||(s=addNearestContainerHits(i,s,t,e),n[a]=[s,i])}let l={},c={};return Object.values(n).forEach(([e,t],a)=>{l[a]=e,c[a]=t}),[l,c]};let FileCoverage=class FileCoverage{constructor(e,t=!1){if(!e)throw Error("Coverage must be initialized with a path or an object");if("string"==typeof e)this.data=emptyCoverage(e,t);else if(e instanceof FileCoverage)this.data=e.data;else if("object"==typeof e)this.data=e;else throw Error("Invalid argument to coverage constructor");assertValidObject(this.data)}getLineCoverage(){let e=this.data.statementMap,t=this.data.s,a=Object.create(null);return Object.entries(t).forEach(([t,r])=>{if(!e[t])return;let{line:s}=e[t].start,i=a[s];(void 0===i||i<r)&&(a[s]=r)}),a}getUncoveredLines(){let e=this.getLineCoverage(),t=[];return Object.entries(e).forEach(([e,a])=>{0===a&&t.push(e)}),t}getBranchCoverageByLine(){let e=this.branchMap,t=this.b,a={};return Object.entries(e).forEach(([e,r])=>{let s=r.line||r.loc.start.line,i=t[e];a[s]=a[s]||[],a[s].push(...i)}),Object.entries(a).forEach(([e,t])=>{let r=t.filter(e=>e>0),s=r.length/t.length*100;a[e]={covered:r.length,total:t.length,coverage:s}}),a}toJSON(){return this.data}merge(e){if(!0===e.all)return;if(!0===this.all){this.data=e.data;return}let[t,a]=mergeProp(this.s,this.statementMap,e.s,e.statementMap);this.data.s=t,this.data.statementMap=a;let keyFromLocationsProp=e=>keyFromLoc(e.locations[0]);[t,a]=mergeProp(this.f,this.fnMap,e.f,e.fnMap,e=>keyFromLoc(e.loc)),this.data.f=t,this.data.fnMap=a,[t,a]=mergeProp(this.b,this.branchMap,e.b,e.branchMap,keyFromLocationsProp),this.data.b=t,this.data.branchMap=a,this.bT&&e.bT&&([t,a]=mergeProp(this.bT,this.branchMap,e.bT,e.branchMap,keyFromLocationsProp),this.data.bT=t)}computeSimpleTotals(e){let t=this[e];"function"==typeof t&&(t=t.call(this));let a={total:Object.keys(t).length,covered:Object.values(t).filter(e=>!!e).length,skipped:0};return a.pct=r(a.covered,a.total),a}computeBranchTotals(e){let t=this[e],a={total:0,covered:0,skipped:0};return Object.values(t).forEach(e=>{a.covered+=e.filter(e=>e>0).length,a.total+=e.length}),a.pct=r(a.covered,a.total),a}resetHits(){let e=this.s,t=this.f,a=this.b,r=this.bT;Object.keys(e).forEach(t=>{e[t]=0}),Object.keys(t).forEach(e=>{t[e]=0}),Object.keys(a).forEach(e=>{a[e].fill(0)}),r&&Object.keys(r).forEach(e=>{r[e].fill(0)})}toSummary(){let e={};return e.lines=this.computeSimpleTotals("getLineCoverage"),e.functions=this.computeSimpleTotals("f","fnMap"),e.statements=this.computeSimpleTotals("s","statementMap"),e.branches=this.computeBranchTotals("b"),this.bT&&(e.branchesTrue=this.computeBranchTotals("bT")),new i(e)}};s(FileCoverage,["path","statementMap","fnMap","branchMap","s","f","b","bT","all"]),e.exports={FileCoverage,findNearestContainer,addHits,addNearestContainerHits}},"./istanbul-lib-coverage/lib/percent.js"(e){e.exports=function(e,t){return t>0?Math.floor(1e5*e/t/10)/100:100}}},t={};function __webpack_require__(a){var r=t[a];if(void 0!==r)return r.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,__webpack_require__),s.exports}var a=__webpack_require__("./istanbul-lib-coverage/index.js");module.exports=a})();