@testream/vitest-reporter 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.mjs +1 -1
- package/package.json +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -9,4 +9,4 @@ ${i.snippet}`).join(`
|
|
|
9
9
|
`)return r;r++}return e.length}function $(e,t){let r=e[t];for(let n=t+1;n<e.length;n++){let i=e[n];if(i==="\\"){n++;continue}if(i===r)return n}return e.length-1}function ee(e,t){for(let r=t;r<e.length;r++)if(e[r]===`
|
|
10
10
|
`)return r;return e.length-1}function te(e,t){for(let r=t;r<e.length-1;r++)if(e[r]==="*"&&e[r+1]==="/")return r+1;return e.length-1}function ht(e,t){for(let r=t;r<e.length;r++){let n=e[r];if(!/\s/.test(n))return n!=="."&&n!=="("}return!1}function mt(e){let t=[0];for(let r=0;r<e.length;r++)e[r]===`
|
|
11
11
|
`&&t.push(r+1);return t}function Tt(e,t){let r=0;for(let n=0;n<e.length&&!(e[n]>t);n++)r=n;return r+1}function gt(e,t){let r=e.lastIndexOf(`
|
|
12
|
-
`,t-1)+1,n=e.slice(r,t).trimStart();return n.startsWith("//")||n.startsWith("*")}function Rt(e,t,r){if(!e.startsWith(r,t))return!1;let n=t===0?"":e[t-1],i=e[t+r.length]??"";return!Z(n)&&!Z(i)}function Z(e){return/[A-Za-z0-9_$]/.test(e)}function m(e){return(e??"").trim().replace(/\s+/g," ")}function bt(e){if(!e)return"";let t=e.split(">").map(i=>i.trim()).filter(Boolean);if(t.length===0)return"";let n=t[0].includes(".")?t.slice(1):t;return m(n.join(" "))}function yt(e,t){let r=D.default.relative(t,e);return r.length>0&&!r.startsWith("..")&&!D.default.isAbsolute(r)}});var ne=R(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.createTestLocationCollector=It;function It(){let e=new Map;return{add(t,r){if(!t||!Ct(r))return;let n=e.get(t)??[];n.push(r),e.set(t,n)},applyToReport(t){let r=new Map([...e.entries()].map(([n,i])=>[n,[...i]]));for(let n of t.results.tests){let o=r.get(n.name)?.shift();o&&(n.filePath??(n.filePath=o.filePath),n.line??(n.line=o.line))}}}}function Ct(e){return!!e.filePath&&Number.isInteger(e.line)&&e.line>0}});var k=R(d=>{"use strict";var _t=d&&d.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ut=d&&d.__exportStar||function(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&_t(t,e,r)};Object.defineProperty(d,"__esModule",{value:!0});d.createTestLocationCollector=d.enrichReportWithJsTestNameSourceSnippets=d.resolveSourceSnippetOptions=d.enrichReportWithSourceSnippets=d.ensureReportId=d.mapAttachmentsToTestResults=d.uploadArtifacts=d.uploadTestRun=d.detectCIContext=void 0;Ut(G(),d);var Et=M();Object.defineProperty(d,"detectCIContext",{enumerable:!0,get:function(){return Et.detectCIContext}});var N=Y();Object.defineProperty(d,"uploadTestRun",{enumerable:!0,get:function(){return N.uploadTestRun}});Object.defineProperty(d,"uploadArtifacts",{enumerable:!0,get:function(){return N.uploadArtifacts}});Object.defineProperty(d,"mapAttachmentsToTestResults",{enumerable:!0,get:function(){return N.mapAttachmentsToTestResults}});Object.defineProperty(d,"ensureReportId",{enumerable:!0,get:function(){return N.ensureReportId}});var ie=E();Object.defineProperty(d,"enrichReportWithSourceSnippets",{enumerable:!0,get:function(){return ie.enrichReportWithSourceSnippets}});Object.defineProperty(d,"resolveSourceSnippetOptions",{enumerable:!0,get:function(){return ie.resolveSourceSnippetOptions}});var St=re();Object.defineProperty(d,"enrichReportWithJsTestNameSourceSnippets",{enumerable:!0,get:function(){return St.enrichReportWithJsTestNameSourceSnippets}});var Nt=ne();Object.defineProperty(d,"createTestLocationCollector",{enumerable:!0,get:function(){return Nt.createTestLocationCollector}})});var O=V(k());import*as L from"node:fs/promises";import*as ae from"node:path";function Bt(e){switch(e){case"passed":return"passed";case"failed":return"failed";case"skipped":return"skipped";default:return"pending"}}function wt(e){let t=[],r=e.parent;for(;r?.type==="suite";)t.unshift(r.name),r=r.parent;return t.join(" > ")}function oe(e){let t=[];for(let r of e)r.type==="test"?t.push(r):r.type==="suite"&&t.push(...oe(r.children));return t}function Lt(e){if(!e||e.length===0)return{message:void 0,trace:void 0};let t=e[0],r=t?.message,n=t?.stackTrace??t?.stack;return{message:r,trace:typeof n=="string"?n:void 0}}function Ot(e,t,r){let n=e.result(),i=e.diagnostic(),o=n.state,a=Bt(o),u=Math.round(i?.duration??0),s=i?.startTime??r,c=s+u,p=i?.retryCount??0,l=i?.flaky??!1,f=wt(e),{message:h,trace:g}=Lt(n.errors);return{ctrfTest:{name:e.name,status:a,duration:u,start:s,stop:c,rawStatus:o,tags:[],type:t.testType||"unit",filePath:e.module.moduleId,line:e.location?.line,retries:p,flaky:l,steps:[],suite:f||void 0,stdout:[],stderr:[],message:h,trace:g},suiteName:f}}function se(e,t,r){let n=Date.now(),i=[],o=new Set;for(let s of e){let c=oe(s.children);for(let p of c){let{ctrfTest:l,suiteName:f}=Ot(p,t,r);f&&o.add(f),i.push(l)}}let a={tests:i.length,passed:i.filter(s=>s.status==="passed").length,failed:i.filter(s=>s.status==="failed").length,skipped:i.filter(s=>s.status==="skipped").length,pending:i.filter(s=>s.status==="pending").length,other:i.filter(s=>s.status==="other").length,suites:o.size,start:r,stop:n};return{reportFormat:"CTRF",specVersion:"0.0.1",timestamp:new Date(r).toISOString(),generatedBy:"@testream/vitest-reporter",extra:{branch:t.branch,commitSha:t.commitSha},results:{tool:{name:"vitest"},summary:a,tests:i,environment:{...t.testEnvironment?{testEnvironment:t.testEnvironment}:{},...t.appName?{appName:t.appName}:{},...t.appVersion?{appVersion:t.appVersion}:{},...t.buildName?{buildName:t.buildName}:{},...t.buildNumber?{buildNumber:t.buildNumber}:{},...t.buildUrl?{buildUrl:t.buildUrl}:{}}}}}var T=V(k()),B=class{constructor(t){if(!t.apiKey)throw new Error("ReportUploader requires an apiKey");this.config={apiKey:t.apiKey,branch:t.branch,commitSha:t.commitSha,repositoryUrl:t.repositoryUrl,failOnUploadError:t.failOnUploadError??!1,buildName:t.buildName,buildNumber:t.buildNumber,buildUrl:t.buildUrl,testEnvironment:t.testEnvironment,appName:t.appName,appVersion:t.appVersion,testType:t.testType}}async uploadReport(t){try{let r=await(0,T.uploadTestRun)({report:t,apiKey:this.config.apiKey,commitSha:this.config.commitSha,branch:this.config.branch,repositoryUrl:this.config.repositoryUrl,buildName:this.config.buildName,buildNumber:this.config.buildNumber,buildUrl:this.config.buildUrl,testEnvironment:this.config.testEnvironment,appName:this.config.appName,appVersion:this.config.appVersion,testType:this.config.testType});if(!r.success){if(this.config.failOnUploadError)throw new Error(r.error||"Upload failed");return r}let n=0;if(!r.alreadyExists&&r.testRunId&&r.testResults){let i=(0,T.mapAttachmentsToTestResults)(t.results.tests,r.testResults);i.length>0&&(n=await(0,T.uploadArtifacts)({reportId:r.reportId,apiKey:this.config.apiKey,testResults:i}))}return{...r,artifactCount:n}}catch(r){let n=r instanceof Error?r.message:String(r);if(this.config.failOnUploadError)throw new Error(`Failed to upload report: ${n}`);return{success:!1,reportId:(0,T.ensureReportId)(t),error:n}}}};var w=class{constructor(t){this.uploader=null;this.startTimestamp=0;if(this.config={uploadEnabled:!0,outputFile:"ctrf-report.json",outputDir:"ctrf",failOnUploadError:!1,testType:"unit",...t},this.config.uploadEnabled&&!this.config.apiKey)throw new Error("TestreamVitestReporter: apiKey is required when upload is enabled");let r=(0,O.detectCIContext)();!this.config.branch&&r.branch&&(this.config.branch=r.branch),!this.config.commitSha&&r.commitSha&&(this.config.commitSha=r.commitSha),!this.config.repositoryUrl&&r.repositoryUrl&&(this.config.repositoryUrl=r.repositoryUrl),!this.config.buildNumber&&r.buildNumber&&(this.config.buildNumber=r.buildNumber),!this.config.buildUrl&&r.buildUrl&&(this.config.buildUrl=r.buildUrl),this.reportPath=ae.join(this.config.outputDir,this.config.outputFile),this.config.uploadEnabled&&(this.uploader=new B(this.config))}onInit(t){t.config.includeTaskLocation!==!0&&(t.config.includeTaskLocation=!0)}onTestRunStart(t){this.startTimestamp=Date.now(),console.log(""),console.log("=".repeat(60)),console.log("Vitest Testream Reporter"),console.log("=".repeat(60)),this.config.uploadEnabled?(this.config.branch&&console.log(`Branch: ${this.config.branch}`),this.config.commitSha&&console.log(`Commit: ${this.config.commitSha.substring(0,7)}`),this.config.repositoryUrl&&console.log(`Repository: ${this.config.repositoryUrl}`)):console.log("Upload: Disabled"),console.log(`Report: ${this.reportPath}`),console.log("=".repeat(60)),console.log("")}async onTestRunEnd(t,r,n){let i=se(t,this.config,this.startTimestamp);await(0,O.enrichReportWithSourceSnippets)(i);try{await L.mkdir(this.config.outputDir,{recursive:!0}),await L.writeFile(this.reportPath,JSON.stringify(i,null,2))}catch(o){let a=o instanceof Error?o.message:String(o);console.error(`Failed to write CTRF report: ${a}`)}if(!this.config.uploadEnabled||!this.uploader){console.log(""),console.log("CTRF report generated"),console.log(` ${this.reportPath}`);return}console.log(""),console.log("=".repeat(60)),console.log("Uploading Test Results"),console.log("=".repeat(60));try{let o=await this.uploader.uploadReport(i);o.success?(console.log("=".repeat(60)),console.log("Upload Complete"),console.log("=".repeat(60)),console.log("")):(console.error("Upload completed with errors"),o.error&&console.error(`Error: ${o.error}`),o.errorCode&&console.error(`Error code: ${o.errorCode}`),console.error(""))}catch(o){let a=o instanceof Error?o.message:String(o);if(console.error(""),console.error("=".repeat(60)),console.error("Upload Failed"),console.error("=".repeat(60)),console.error(`Error: ${a}`),console.error(""),this.config.failOnUploadError)throw o}}};export{w as TestreamVitestReporter,w as default};
|
|
12
|
+
`,t-1)+1,n=e.slice(r,t).trimStart();return n.startsWith("//")||n.startsWith("*")}function Rt(e,t,r){if(!e.startsWith(r,t))return!1;let n=t===0?"":e[t-1],i=e[t+r.length]??"";return!Z(n)&&!Z(i)}function Z(e){return/[A-Za-z0-9_$]/.test(e)}function m(e){return(e??"").trim().replace(/\s+/g," ")}function bt(e){if(!e)return"";let t=e.split(">").map(i=>i.trim()).filter(Boolean);if(t.length===0)return"";let n=t[0].includes(".")?t.slice(1):t;return m(n.join(" "))}function yt(e,t){let r=D.default.relative(t,e);return r.length>0&&!r.startsWith("..")&&!D.default.isAbsolute(r)}});var ne=R(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.createTestLocationCollector=It;function It(){let e=new Map;return{add(t,r){if(!t||!Ct(r))return;let n=e.get(t)??[];n.push(r),e.set(t,n)},applyToReport(t){let r=new Map([...e.entries()].map(([n,i])=>[n,[...i]]));for(let n of t.results.tests){let o=r.get(n.name)?.shift();o&&(n.filePath??(n.filePath=o.filePath),n.line??(n.line=o.line))}}}}function Ct(e){return!!e.filePath&&Number.isInteger(e.line)&&e.line>0}});var k=R(d=>{"use strict";var _t=d&&d.__createBinding||(Object.create?(function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}):(function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]})),Ut=d&&d.__exportStar||function(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&_t(t,e,r)};Object.defineProperty(d,"__esModule",{value:!0});d.createTestLocationCollector=d.enrichReportWithJsTestNameSourceSnippets=d.resolveSourceSnippetOptions=d.enrichReportWithSourceSnippets=d.ensureReportId=d.mapAttachmentsToTestResults=d.uploadArtifacts=d.uploadTestRun=d.detectCIContext=void 0;Ut(G(),d);var Et=M();Object.defineProperty(d,"detectCIContext",{enumerable:!0,get:function(){return Et.detectCIContext}});var N=Y();Object.defineProperty(d,"uploadTestRun",{enumerable:!0,get:function(){return N.uploadTestRun}});Object.defineProperty(d,"uploadArtifacts",{enumerable:!0,get:function(){return N.uploadArtifacts}});Object.defineProperty(d,"mapAttachmentsToTestResults",{enumerable:!0,get:function(){return N.mapAttachmentsToTestResults}});Object.defineProperty(d,"ensureReportId",{enumerable:!0,get:function(){return N.ensureReportId}});var ie=E();Object.defineProperty(d,"enrichReportWithSourceSnippets",{enumerable:!0,get:function(){return ie.enrichReportWithSourceSnippets}});Object.defineProperty(d,"resolveSourceSnippetOptions",{enumerable:!0,get:function(){return ie.resolveSourceSnippetOptions}});var St=re();Object.defineProperty(d,"enrichReportWithJsTestNameSourceSnippets",{enumerable:!0,get:function(){return St.enrichReportWithJsTestNameSourceSnippets}});var Nt=ne();Object.defineProperty(d,"createTestLocationCollector",{enumerable:!0,get:function(){return Nt.createTestLocationCollector}})});var O=V(k());import*as L from"node:fs/promises";import*as ae from"node:path";function Bt(e){switch(e){case"passed":return"passed";case"failed":return"failed";case"skipped":return"skipped";default:return"pending"}}function wt(e){let t=[],r=e.parent;for(;r?.type==="suite";)t.unshift(r.name),r=r.parent;return t.join(" > ")}function oe(e){let t=[];for(let r of e)r.type==="test"?t.push(r):r.type==="suite"&&t.push(...oe(r.children));return t}function Lt(e){if(!e||e.length===0)return{message:void 0,trace:void 0};let t=e[0],r=t?.message,n=t?.stackTrace??t?.stack;return{message:r,trace:typeof n=="string"?n:void 0}}function Ot(e,t,r){let n=e.result(),i=e.diagnostic(),o=n.state,a=Bt(o),u=Math.round(i?.duration??0),s=i?.startTime??r,c=s+u,p=i?.retryCount??0,l=i?.flaky??!1,f=wt(e),{message:h,trace:g}=Lt(n.errors);return{ctrfTest:{name:e.name,status:a,duration:u,start:s,stop:c,rawStatus:o,tags:[],type:t.testType||"unit",filePath:e.module.moduleId,line:e.location?.line,retries:p,flaky:l,steps:[],suite:f||void 0,stdout:[],stderr:[],message:h,trace:g},suiteName:f}}function se(e,t,r){let n=Date.now(),i=[],o=new Set;for(let s of e){let c=oe(s.children);for(let p of c){let{ctrfTest:l,suiteName:f}=Ot(p,t,r);f&&o.add(f),i.push(l)}}let a={tests:i.length,passed:i.filter(s=>s.status==="passed").length,failed:i.filter(s=>s.status==="failed").length,skipped:i.filter(s=>s.status==="skipped").length,pending:i.filter(s=>s.status==="pending").length,other:i.filter(s=>s.status==="other").length,suites:o.size,start:r,stop:n};return{reportFormat:"CTRF",specVersion:"0.0.1",timestamp:new Date(r).toISOString(),generatedBy:"@testream/vitest-reporter",extra:{branch:t.branch,commitSha:t.commitSha},results:{tool:{name:"vitest"},summary:a,tests:i,environment:{...t.testEnvironment?{testEnvironment:t.testEnvironment}:{},...t.appName?{appName:t.appName}:{},...t.appVersion?{appVersion:t.appVersion}:{},...t.buildName?{buildName:t.buildName}:{},...t.buildNumber?{buildNumber:t.buildNumber}:{},...t.buildUrl?{buildUrl:t.buildUrl}:{}}}}}var T=V(k()),B=class{constructor(t){if(!t.apiKey)throw new Error("ReportUploader requires an apiKey");this.config={apiKey:t.apiKey,branch:t.branch,commitSha:t.commitSha,repositoryUrl:t.repositoryUrl,failOnUploadError:t.failOnUploadError??!1,buildName:t.buildName,buildNumber:t.buildNumber,buildUrl:t.buildUrl,testEnvironment:t.testEnvironment,appName:t.appName,appVersion:t.appVersion,testType:t.testType}}async uploadReport(t){try{let r=await(0,T.uploadTestRun)({report:t,apiKey:this.config.apiKey,commitSha:this.config.commitSha,branch:this.config.branch,repositoryUrl:this.config.repositoryUrl,buildName:this.config.buildName,buildNumber:this.config.buildNumber,buildUrl:this.config.buildUrl,testEnvironment:this.config.testEnvironment,appName:this.config.appName,appVersion:this.config.appVersion,testType:this.config.testType});if(!r.success){if(this.config.failOnUploadError)throw new Error(r.error||"Upload failed");return r}let n=0;if(!r.alreadyExists&&r.testRunId&&r.testResults){let i=(0,T.mapAttachmentsToTestResults)(t.results.tests,r.testResults);i.length>0&&(n=await(0,T.uploadArtifacts)({reportId:r.reportId,apiKey:this.config.apiKey,testResults:i}))}return{...r,artifactCount:n}}catch(r){let n=r instanceof Error?r.message:String(r);if(this.config.failOnUploadError)throw new Error(`Failed to upload report: ${n}`);return{success:!1,reportId:(0,T.ensureReportId)(t),error:n}}}};var w=class{constructor(t){this.uploader=null;this.startTimestamp=0;if(this.config={uploadEnabled:!0,outputFile:"ctrf-report.json",outputDir:"ctrf",failOnUploadError:!1,testType:"unit",...t},this.config.uploadEnabled&&!this.config.apiKey)throw new Error("TestreamVitestReporter: apiKey is required when upload is enabled");let r=(0,O.detectCIContext)();!this.config.branch&&r.branch&&(this.config.branch=r.branch),!this.config.commitSha&&r.commitSha&&(this.config.commitSha=r.commitSha),!this.config.repositoryUrl&&r.repositoryUrl&&(this.config.repositoryUrl=r.repositoryUrl),!this.config.buildNumber&&r.buildNumber&&(this.config.buildNumber=r.buildNumber),!this.config.buildUrl&&r.buildUrl&&(this.config.buildUrl=r.buildUrl),this.reportPath=ae.join(this.config.outputDir,this.config.outputFile),this.config.uploadEnabled&&(this.uploader=new B(this.config))}onInit(t){t.config.includeTaskLocation!==!0&&(t.config.includeTaskLocation=!0)}onTestRunStart(t){this.startTimestamp=Date.now(),console.log(""),console.log("=".repeat(60)),console.log("Vitest Testream Reporter"),console.log("=".repeat(60)),this.config.uploadEnabled?(this.config.branch&&console.log(`Branch: ${this.config.branch}`),this.config.commitSha&&console.log(`Commit: ${this.config.commitSha.substring(0,7)}`),this.config.repositoryUrl&&console.log(`Repository: ${this.config.repositoryUrl}`)):console.log("Upload: Disabled"),console.log(`Report: ${this.reportPath}`),console.log("=".repeat(60)),console.log("")}async onTestRunEnd(t,r,n){let i=se(t,this.config,this.startTimestamp);await(0,O.enrichReportWithSourceSnippets)(i);try{await L.mkdir(this.config.outputDir,{recursive:!0}),await L.writeFile(this.reportPath,JSON.stringify(i,null,2))}catch(o){let a=o instanceof Error?o.message:String(o);console.error(`Failed to write CTRF report: ${a}`)}if(!this.config.uploadEnabled||!this.uploader){console.log(""),console.log("CTRF report generated"),console.log(` ${this.reportPath}`);return}console.log(""),console.log("=".repeat(60)),console.log("Uploading Test Results"),console.log("=".repeat(60));try{let o=await this.uploader.uploadReport(i);o.success?(console.log("=".repeat(60)),console.log("Upload Complete"),console.log("=".repeat(60)),console.log("")):(console.error("Upload completed with errors"),o.error&&console.error(`Error: ${o.error}`),o.errorCode&&console.error(`Error code: ${o.errorCode}`),console.error(""))}catch(o){let a=o instanceof Error?o.message:String(o);if(console.error(""),console.error("=".repeat(60)),console.error("Upload Failed"),console.error("=".repeat(60)),console.error(`Error: ${a}`),console.error(""),this.config.failOnUploadError)throw o}}};export{w as TestreamVitestReporter,w as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testream/vitest-reporter",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Vitest reporter to upload test results to Testream",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@jira-test-manager/shared-types": "*",
|
|
51
51
|
"@vercel/ncc": "^0.38.1",
|
|
52
|
-
"esbuild": "^0.
|
|
52
|
+
"esbuild": "^0.28.0",
|
|
53
53
|
"vitest": "^3.0.0",
|
|
54
54
|
"@types/node": "^20.10.6",
|
|
55
55
|
"@typescript-eslint/eslint-plugin": "^6.17.0",
|