@ctrl/sentry-tests 0.1.5 → 0.1.7
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/_chunks/collector-BrSszbTa.js +2 -0
- package/dist/_chunks/{delivery-BuX4NHe1.js → delivery-9Rj__R9x.js} +1 -1
- package/dist/_chunks/jest-collector-CP2wMJH5.js +2 -0
- package/dist/_chunks/{report-D0M3wzq7.js → report-CekWv1nz.js} +1 -1
- package/dist/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
- package/dist/index.js +1 -1
- package/dist/jest-runner.js +1 -1
- package/dist/jest.js +1 -1
- package/dist/vitest-runner.js +1 -1
- package/dist/vitest.js +1 -1
- package/package.json +24 -24
- package/dist/_chunks/collector-IMkR4PbK.js +0 -2
- package/dist/_chunks/jest-collector-DLqfVNzs.js +0 -2
- package/dist/_chunks/rolldown-runtime-H3fMLYWS.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./rolldown-runtime-BhWHdk3m.js";import{AsyncLocalStorage as e}from"node:async_hooks";import{randomBytes as t}from"node:crypto";import{channel as n,tracingChannel as r}from"node:diagnostics_channel";import{performance as i}from"node:perf_hooks";import{setTimeout as a}from"node:timers/promises";import{n as o,t as s}from"./channels-DmPSmlIK.js";const c=/* @__PURE__ */ new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`source`,`track`,`wbr`]),l=/* @__PURE__ */ new Set([`style`,`script`,`template`]);function pageHtml(e,t=2e5){let n=e?.body;if(n==null)return;let r=[],i=0,push=e=>(r.push(e),i+=e.length+1,i<t),write=(e,t)=>{let n=` `.repeat(t);if(e.nodeType===3){let t=(e.data??``).replace(/\s+/g,` `).trim();return t===``||push(n+escapeText(t))}if(e.nodeType!==1||e.localName===void 0)return!0;let r=`<${e.localName}${attributes(e)}`;if(c.has(e.localName))return push(`${n}${r} />`);let i=l.has(e.localName)?[]:childList(e);if(i.length===0)return push(`${n}${r}></${e.localName}>`);if(i.length===1&&i[0].nodeType===3){let t=(i[0].data??``).replace(/\s+/g,` `).trim();if(t.length<=80)return push(`${n}${r}>${escapeText(t)}</${e.localName}>`)}if(!push(`${n}${r}>`))return!1;for(let e of i)if(!write(e,t+1))return!1;return push(`${n}</${e.localName}>`)};try{write(n,0)||r.push(`<!-- truncated -->`)}catch{return}return r.join(`
|
|
2
|
+
`)}function childList(e){let t=[],n=e.childNodes;if(n===void 0)return t;for(let e=0;e<n.length;e++)(n[e].nodeType===1||n[e].nodeType===3)&&t.push(n[e]);return t}function attributes(e){let t=e.attributes;if(t===void 0)return``;let n=``;for(let e=0;e<t.length;e++)n+=` ${t[e].name}="${t[e].value.replaceAll(`&`,`&`).replaceAll(`"`,`"`)}"`;return n}function escapeText(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}const u=1e3,d=2e5,realNow=()=>(i.timeOrigin+i.now())/1e3;function spanIds(){let e=t(8),n=0;return()=>(e.writeUInt32BE(n++,4),e.toString(`hex`))}function createCollector(){let t=new e,i=Symbol(`sentry-tests.span`),c=spanIds(),l=null,f=emptyFile(),p={kept:0,limit:u,counts:f},m=/* @__PURE__ */ new Map,parent=()=>t.getStore()??l,open=(e,t,n={},r)=>{let i=parent(),a=realNow();return f.startedAt===0&&(f.startedAt=a),{span:{span_id:c(),parent_span_id:i?.span.span_id,op:e,description:t,start_timestamp:a,timestamp:0,status:`ok`,data:n},owner:r===void 0?i?.owner??p:m.get(r)}},openTraced=e=>{let t=parent();if(t===null)return;let n=t.owner;if(n.kept===n.limit)return n.counts.droppedSpans++,t;n.kept++;let r=open(e.op,e.description,e.data);return e[i]=r,r},closeTraced=e=>{let t=e[i];t!==void 0&&(e[i]=void 0,t.span.data=e.data,close(t,e.error!==void 0))},close=(e,t=!1)=>{e.span.timestamp=realNow(),t&&(e.span.status=`internal_error`),f.spans.push(e.span)},h={start(){},end(e){e.async&&e.error===void 0||closeTraced(e)},asyncStart(){},asyncEnd(e){closeTraced(e)},error(){}},g=o.map(e=>r(e));for(let e of g)e.start.bindStore(t,openTraced),e.subscribe(h);let _=n(s);return{open,close,run:(e,n)=>t.run(e,n),current:parent,enter(e){l=e},test(e){let t=f.tests[e];return t===void 0&&(t=f.tests[e]={spanIds:[],droppedSpans:0,failures:[]},m.set(t,{kept:0,limit:300,counts:t})),t},async captureFailure(e,t,n,r){let i={attachments:[],contexts:{}};if(typeof n==`object`&&n&&typeof n.message==`string`){let e=n;i.error={name:e.name,message:e.message,stack:e.stack}}let o=pageHtml(r,d);if(o!==void 0&&i.attachments.push({filename:`page.html`,contentType:`text/html`,data:o}),_.hasSubscribers){let e=[],o={test:t,error:n,document:r,attachments:[],contexts:i.contexts,waitUntil:t=>void e.push(t)};_.publish(o),e.length>0&&await Promise.race([Promise.allSettled(e),a(5e3,void 0,{ref:!1})]);for(let e of o.attachments)i.attachments.some(t=>t.filename===e.filename)||i.attachments.push({...e,data:e.data.slice(0,d)})}e.failures.push(i)},finish(){let e=f;return e.endedAt=realNow(),f=emptyFile(),p={kept:0,limit:u,counts:f},m.clear(),l=null,e},stop(){for(let e of g)e.unsubscribe(h),e.start.unbindStore(t)}}}function emptyFile(){return{startedAt:0,endedAt:0,spans:[],tests:Object.create(null),droppedSpans:0}}export{realNow as n,createCollector as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./rolldown-runtime-
|
|
1
|
+
import"./rolldown-runtime-BhWHdk3m.js";var Delivery=class{#e;#t;#n=[];#r=0;#i=[];#a=/* @__PURE__ */ new Set;#o={traces:0,failures:0,flaky:0};constructor(e,t){this.#e=e,this.#t=t}add(e){this.#o.traces+=e.traces,this.#o.failures+=e.failures,this.#o.flaky+=e.flaky;for(let t of e.envelopes)for(let e of this.#e.targets)this.#n.push([t,e]);this.#s()}async flush(){(this.#n.length>0||this.#r>0)&&await new Promise(e=>this.#i.push(e));let{traces:e,failures:t,flaky:n}=this.#o,r=[...this.#a];return this.#o={traces:0,failures:0,flaky:0},this.#a.clear(),e+t+n===0?null:`@ctrl/sentry-tests: ${[plural(e,`trace`),plural(t,`failed test`),plural(n,`flaky test`)].join(`, `)} → ${this.#e.targets.map(e=>e.label).join(` and `)}${r.length>0?`; not delivered: ${r.join(`; `)}`:``}`}#s(){for(;this.#r<6&&this.#n.length>0;){let[e,t]=this.#n.shift();this.#r++,this.#t(e,t).then(e=>{if(e!==null&&this.#a.add(e),this.#r--,this.#s(),this.#r===0&&this.#n.length===0)for(let e of this.#i.splice(0))e()})}}};function plural(e,t){return`${e} ${t}${e===1?``:`s`}`}export{Delivery as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./rolldown-runtime-BhWHdk3m.js";import{createHash as e}from"node:crypto";import{mkdirSync as t,writeFileSync as n}from"node:fs";import{join as r}from"node:path";import{n as i,t as a}from"./collector-BrSszbTa.js";const isJestsOwn=e=>/[\\/]jest-circus[\\/]/.test(e.asyncError?.stack?.split(`
|
|
2
|
+
`)[1]??``);function jestDataFile(t,n){return r(t,`${e(`sha1`).update(n).digest(`hex`)}.json`)}function circusTestName(e){let t=[e.name];for(let n=e.parent;n?.parent!==void 0;n=n.parent)t.unshift(n.name);return t.join(` > `)}function createJestCollector(e){let r=a(),o=[],s=/* @__PURE__ */ new WeakSet,push=e=>{o.push(e),r.enter(e)},pop=(e=!1)=>{let t=o.pop();t!==void 0&&r.close(t,e),r.enter(o.at(-1)??null)},c=null,endPhase=()=>{if(c===null)return;let{open:e,hooks:t,failed:n,end:r}=c;c=null,e.span.data.hooks=t,pop(n),r>0&&(e.span.timestamp=r)};return{async handleTestEvent(e){switch(e.name.startsWith(`hook_`)||endPhase(),e.name){case`setup`:push(r.open(`test.collect`,`collect`));break;case`run_start`:pop();break;case`run_describe_start`:e.describeBlock?.parent!==void 0&&push(r.open(`test.suite`,circusTestName(e.describeBlock)));break;case`run_describe_finish`:e.describeBlock?.parent!==void 0&&pop();break;case`test_start`:{let t=circusTestName(e.test),n=r.test(t),i=r.open(`test.case`,t,n.spanIds.length>0?{"test.retry":n.spanIds.length}:{},n);n.spanIds.push(i.span.span_id),push(i);break}case`test_done`:pop(e.test.errors.length>0);break;case`test_skip`:case`test_todo`:o.pop(),r.enter(o.at(-1)??null),r.test(circusTestName(e.test)).spanIds.pop();break;case`hook_start`:{let t=e.hook;if(isJestsOwn(t)){s.add(t);break}c?.type!==t.type&&(endPhase(),c={type:t.type,open:r.open(`test.hook`,t.type),hooks:0,failed:!1,end:0},push(c.open)),c.hooks++;break}case`hook_success`:c!==null&&!s.has(e.hook)&&(c.end=i());break;case`hook_failure`:c!==null&&!s.has(e.hook)&&(c.failed=!0,c.end=i()),e.test!==void 0&&e.hook?.type===`beforeEach`&&await capture(e.test,e.error);break;case`test_fn_start`:push(r.open(`test.fn`,e.test.name));break;case`test_fn_success`:pop();break;case`test_fn_failure`:pop(!0),await capture(e.test,e.error)}},finish(){let i=r.finish();r.stop();let a={testPath:e.testPath,collected:i};try{t(e.dir,{recursive:!0}),n(jestDataFile(e.dir,e.testPath),JSON.stringify(a))}catch{}}};function capture(t,n){let i=circusTestName(t);return r.captureFailure(r.test(i),i,n,e.getDocument())}}export{jestDataFile as n,createJestCollector as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"./rolldown-runtime-
|
|
1
|
+
import"./rolldown-runtime-BhWHdk3m.js";import{execFileSync as e}from"node:child_process";import{randomBytes as t,randomUUID as n}from"node:crypto";import{readFileSync as r}from"node:fs";import{isAbsolute as i,relative as a}from"node:path";import{fileURLToPath as o}from"node:url";import{stripVTControlCharacters as s}from"node:util";function parseDsn(e){let t;try{t=new URL(e)}catch{throw Error(`@ctrl/sentry-tests: invalid DSN ${JSON.stringify(e)}`)}let n=t.pathname.split(`/`).filter(Boolean),r=n.pop();if(!t.username||r===void 0)throw Error(`@ctrl/sentry-tests: invalid DSN ${JSON.stringify(e)} (expected https://<key>@<host>/<project>)`);let i=n.length>0?`/${n.join(`/`)}`:``,a=new URLSearchParams({sentry_key:t.username,sentry_version:`7`,sentry_client:`${c.name}/${c.version}`});return{dsn:e,url:`${t.protocol}//${t.host}${i}/api/${r}/envelope/?${a}`,host:t.host,projectId:r}}const c={name:`ctrl.sentry-tests`,version:`0.0.0`},uuid=()=>n().replaceAll(`-`,``),spanId=()=>t(8).toString(`hex`),l=new TextEncoder;function serializeEnvelope(e,t){let n=[],line=e=>n.push(l.encode(`${e}\n`));line(JSON.stringify({event_id:e.eventId,sent_at:(/* @__PURE__ */ new Date()).toISOString(),sdk:c,...t?{dsn:t.dsn}:{}}));for(let t of e.items){let e=l.encode(typeof t.payload==`string`?t.payload:JSON.stringify(t.payload)),r=t.type===`attachment`?{type:`attachment`,length:e.byteLength,filename:t.filename,content_type:t.contentType,attachment_type:`event.attachment`}:{type:t.type,length:e.byteLength};line(JSON.stringify(r)),n.push(e,l.encode(`
|
|
2
2
|
`))}let r=new Uint8Array(n.reduce((e,t)=>e+t.byteLength,0)),i=0;for(let e of n)r.set(e,i),i+=e.byteLength;return r}async function sendEnvelope(e,t){try{let n=await fetch(t.url,{method:`POST`,headers:{"content-type":`application/x-sentry-envelope`},body:serializeEnvelope(e,t.dsn),signal:AbortSignal.timeout(15e3)});return n.ok?null:`${t.label} answered ${n.status} ${(await n.text().catch(()=>``)).slice(0,200)}`.trim()}catch(e){return`${t.label}: ${e.message}`}}const u=/^\s*at (?:(?:async )?(.+?) \()?(.+?):(\d+):(\d+)\)?$/;function parseStack(e){if(!e)return[];let t=[];for(let n of e.split(`
|
|
3
3
|
`)){let e=u.exec(n);e!==null&&t.push({method:e[1],file:e[2],line:Number(e[3]),column:Number(e[4])})}return t.reverse()}const d=/* @__PURE__ */ new Map;function sourceLines(e){let t=d.get(e);if(t===void 0){try{t=r(e,`utf8`).split(`
|
|
4
4
|
`)}catch{t=null}d.set(e,t)}return t}const f=o(new URL(`../../`,import.meta.url));function toSentryFrames(e,t){return e.map(e=>{let n=e.file.startsWith(`file://`)?o(e.file):e.file,r=i(n),s=r&&!n.includes(`/node_modules/`)&&!n.startsWith(f),c={filename:r?a(t,n):n,abs_path:n,...e.method?{function:e.method}:{},...e.line===void 0?{}:{lineno:e.line},...e.column===void 0?{}:{colno:e.column},in_app:s},l=s&&e.line!==void 0?sourceLines(n):null;if(l!==null&&e.line>=1&&e.line<=l.length){let t=e.line-1;c.pre_context=l.slice(Math.max(0,t-5),t),c.context_line=l[t],c.post_context=l.slice(t+1,t+1+5)}return c})}function resolveOptions(e={},t=process.env){let n=[],r=e.dsn??t.SENTRY_DSN;if(r){let e=parseDsn(r);n.push({label:e.host,url:e.url,dsn:e})}let i=e.spotlight??spotlightFromEnv(t.SENTRY_SPOTLIGHT);return i&&n.push({label:`Spotlight`,url:i===!0?`http://localhost:8969/stream`:i,dsn:null}),n.length===0?null:{targets:n,environment:e.environment??t.SENTRY_ENVIRONMENT??(t.CI?`ci`:`local`),release:e.release??t.SENTRY_RELEASE??t.GITHUB_SHA??gitCommit(),traces:e.traces??!0,tracesSampleRate:sampleRate(e.tracesSampleRate??t.SENTRY_TRACES_SAMPLE_RATE),failures:e.failures??!0,flaky:e.flaky??!0,attachments:e.attachments??!0,tags:e.tags??{}}}function sampleRate(e){let t=typeof e==`string`?Number(e):e??1;return Number.isFinite(t)?Math.min(1,Math.max(0,t)):1}function spotlightFromEnv(e){return e===void 0||e===``||e===`0`||e.toLowerCase()===`false`?!1:e===`1`||e.toLowerCase()===`true`||e}function gitCommit(){try{return e(`git`,[`rev-parse`,`HEAD`],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim()||void 0}catch{return}}const p=1e3,m=`(file failed to load)`,h=`auto.test.sentry_tests`,g=/* @__PURE__ */ new Set([`test.case`,`test.fn`,`test.suite`,`test.collect`]);function buildReport(e,t){let n={envelopes:[],traces:0,failures:0,flaky:0},r=e.tests.filter(e=>e.state!==`skip`),i=e.outsideTests??[];if(r.length===0&&i.length===0)return n;let o=a(e.root,e.file),s=o===``||o.startsWith(`..`)?e.file:o,l=uuid(),u=spanId(),d={runner:e.runner,"test.file":tag(s),...e.project?{"test.project":tag(e.project)}:{},...t.tags},f={platform:`node`,environment:t.environment,...t.release?{release:t.release}:{},sdk:c,contexts:{runtime:{name:`node`,version:process.version}}},m=e.collected,g=[...m?.spans??[]].sort((e,t)=>e.start_timestamp-t.start_timestamp),_=new Map(g.map(e=>[e.span_id,e]));for(let e of r){let t=m?.tests[e.key],n=t?.spanIds.at(-1);if(t===void 0||n===void 0)continue;let r=_.get(n);r.status=e.state===`pass`?`ok`:`internal_error`,r.data={...r.data,"test.retries":e.retries,"test.flaky":e.flaky,...t.droppedSpans?{"spans.dropped":t.droppedSpans}:{}}}let v=/* @__PURE__ */ new Map,ownerOf=e=>{let t=v.get(e.span_id);if(t!==void 0)return t;let n=e.parent_span_id===void 0?void 0:_.get(e.parent_span_id);return t=e.op===`test.case`?e.span_id:n===void 0?null:ownerOf(n),v.set(e.span_id,t),t},y=[],b=/* @__PURE__ */ new Map;for(let e of g){let t=ownerOf(e);if(t===null)y.push(e);else{let n=b.get(t);n===void 0&&b.set(t,n=[]),n.push(e)}}let x=Math.max(0,y.length-p)+(m?.droppedSpans??0),S=[y.slice(0,p)];for(let e of b.values()){let t=e.slice(0,p);x+=e.length-t.length,S.at(-1).length+t.length>p&&S.at(-1).length>0&&S.push([]),S.at(-1).push(...t)}let C=/* @__PURE__ */ new Map,w=m!==null&&g.length>0&&t.traces&&(t.tracesSampleRate>=1||Math.random()<t.tracesSampleRate);w&&(S.forEach((t,i)=>{let a=i===0,o=a?u:spanId(),c=new Set(t.map(e=>e.span_id)),p=uuid(),g=t.map(e=>{let t=e.parent_span_id!==void 0&&c.has(e.parent_span_id)?e.parent_span_id:o;return C.set(e.span_id,t),{...e,trace_id:l,parent_span_id:t,origin:h}}),_=t.some(e=>e.op===`test.case`&&e.status!==`ok`);n.envelopes.push({eventId:p,items:[{type:`transaction`,payload:{...f,type:`transaction`,event_id:p,transaction:a?s:`${s} (part ${i+1} of ${S.length})`,transaction_info:{source:`custom`},...a?{start_timestamp:m.startedAt,timestamp:m.endedAt}:bounds(t),tags:d,contexts:{...f.contexts,trace:{trace_id:l,span_id:o,...a?{}:{parent_span_id:u},op:`test.file`,status:(a?r.some(e=>e.state===`fail`):_)?`internal_error`:`ok`,origin:h,...a&&x||S.length>1?{data:{...a&&x?{"spans.dropped":x}:{},...S.length>1?{"test.part":i+1,"test.parts":S.length}:{}}}:{}}},spans:g,...a&&e.environmentSetupMs!==void 0?{measurements:{environment_setup:{value:e.environmentSetupMs,unit:`millisecond`}}}:{}}}]})}),n.traces++);for(let i of r){let r=i.state===`fail`;if(!(r?t.failures:i.flaky&&t.flaky))continue;let a=m?.tests[i.key],o=r?a?.failures.at(-1):a?.failures[0],c=r?a?.spanIds.at(-1):a?.spanIds[0],u=r?i.errors.at(-1)??o?.error:o?.error??i.errors[0],p=u!==void 0&&!u.name&&o?.error?.name?{...u,name:o.error.name}:u,h=t.attachments?o?.attachments??[]:[],g=toException(p??{message:`Test failed`},e.root,h.map(e=>e.filename));r||(g.value=`${i.name} failed, then passed on retry ${i.retries}. The failed attempt:\n\n${g.type}: ${g.value}`,g.type=`FlakyTest`);let v=c===void 0?void 0:_.get(c),y=uuid(),x=[{type:`event`,payload:{...f,event_id:y,timestamp:v?.timestamp??Date.now()/1e3,level:r?`error`:`warning`,logger:`${e.runner}.test`,transaction:`${s} > ${i.name}`,fingerprint:[r?`sentry-tests.test-failure`:`sentry-tests.flaky-test`,s,i.name],exception:{values:[g]},tags:{...d,"test.name":tag(i.name),flaky:String(i.flaky),retries:String(i.retries)},contexts:{...f.contexts,...o?.contexts,...w&&c!==void 0?{trace:{trace_id:l,span_id:c,parent_span_id:C.get(c),op:`test.case`}}:{},test:{name:i.name,file:s,duration_ms:i.duration,retries:i.retries,flaky:i.flaky}},breadcrumbs:{values:breadcrumbs(c!==void 0&&b.get(c)||[],i.console??[])}}}];for(let e of h)x.push({type:`attachment`,filename:e.filename,contentType:e.contentType,payload:e.data});n.envelopes.push({eventId:y,items:x}),r?n.failures++:n.flaky++}if(t.failures)for(let{name:t,error:r}of i){let i=uuid();n.envelopes.push({eventId:i,items:[{type:`event`,payload:{...f,event_id:i,timestamp:Date.now()/1e3,level:`error`,logger:`${e.runner}.test`,transaction:`${s} > ${t}`,fingerprint:[`sentry-tests.test-failure`,s,t],exception:{values:[toException(r,e.root)]},tags:{...d,"test.name":tag(t),flaky:`false`,retries:`0`},contexts:{...f.contexts,test:{name:t,file:s}}}}]}),n.failures++}return n}function bounds(e){let t=1/0,n=0;for(let r of e)r.start_timestamp<t&&(t=r.start_timestamp),r.timestamp>n&&(n=r.timestamp);return{start_timestamp:t,timestamp:n}}function tag(e){return e.length>200?`${e.slice(0,199)}…`:e}const _=/\n\n(?:Ignored nodes: |Here are the accessible roles:|Accessibility snapshot of <body>|DOM of <body>|<body)/;function toException(e,t,n=[]){let r=s(e.message),i=n.length>0?_.exec(r):null;i!==null&&(r=`${r.slice(0,i.index)}\n\n(The page when the test failed is attached: ${n.join(`, `)}.)`);let a=r.length>8192?`${r.slice(0,8191)}…`:r,o=e.frames===void 0?parseStack(e.stack):[...e.frames].reverse();return{type:e.name||`Error`,value:a,mechanism:{type:`sentry-tests`,handled:!0},...o.length>0?{stacktrace:{frames:toSentryFrames(o,t)}}:{}}}function breadcrumbs(e,t){return[...e.filter(e=>!g.has(e.op)).map(e=>({type:`default`,category:e.op,message:`${e.description} (${spanDetails(e)})`,timestamp:e.start_timestamp,level:e.status===`ok`?`info`:`error`})),...t.map(e=>({type:`default`,category:`console`,message:e.message.length>1e3?`${e.message.slice(0,999)}…`:e.message,timestamp:e.timestamp,level:e.stream===`stderr`?`error`:`info`}))].sort((e,t)=>e.timestamp-t.timestamp).slice(-100)}function spanDetails(e){let t=(e.timestamp-e.start_timestamp)*1e3,n=[`${t<10?t.toFixed(1):Math.round(t)} ms`],{checks:r,matches:i}=e.data;typeof r==`number`&&n.push(`${r} ${r===1?`check`:`checks`}`),typeof i==`number`&&n.push(`${i} ${i===1?`match`:`matches`}`);let a=e.data[`clock.skipped_ms`];return typeof a==`number`&&n.push(`${Math.round(a)} ms skipped`),n.join(`, `)}export{sendEnvelope as i,buildReport as n,resolveOptions as r,m as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name as t};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t}from"./_chunks/report-
|
|
1
|
+
import{n as e,r as t}from"./_chunks/report-CekWv1nz.js";import{n,t as r}from"./_chunks/channels-DmPSmlIK.js";export{r as FAILURE_CHANNEL,n as SPAN_CHANNELS,e as buildReport,t as resolveOptions};
|
package/dist/jest-runner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_chunks/rolldown-runtime-
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{createRequire as e}from"node:module";import{t}from"./_chunks/jest-collector-CP2wMJH5.js";const n=e(import.meta.url)(`jest-circus/runner`).default;async function sentryTestsRunner(...e){let r=process.env.SENTRY_TESTS_DIR;if(!r)return n(...e);let[,,i,,a]=e,o=t({dir:r,testPath:a,getDocument:()=>i.global?.document}),s=i.handleTestEvent;i.handleTestEvent=async function(e,t){await s?.call(this,e,t),await o.handleTestEvent(e)};try{return await n(...e)}finally{o.finish()}}export{sentryTestsRunner as default};
|
package/dist/jest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_chunks/rolldown-runtime-
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{mkdtempSync as e,readFileSync as t,rmSync as n}from"node:fs";import{tmpdir as r}from"node:os";import{join as i}from"node:path";import{i as a,n as o,r as s,t as c}from"./_chunks/report-CekWv1nz.js";import{t as l}from"./_chunks/delivery-9Rj__R9x.js";import{n as u}from"./_chunks/jest-collector-CP2wMJH5.js";var SentryTestsReporter=class{options;#e;#t=null;#n=null;#r=!1;constructor(t={},o={}){if(this.#e=t.rootDir??process.cwd(),this.options=s(o),this.options===null)return;this.#n=new l(this.options,a);let c=e(i(r(),`sentry-tests-`));this.#t=c,process.env.SENTRY_TESTS_DIR=c,process.once(`exit`,()=>n(c,{recursive:!0,force:!0}))}onTestResult(e,t){if(this.options===null||this.#n===null)return;let n=this.#i(e.path);n!==null&&(this.#r=!0);let r=t.testResults.map(e=>{let t=[...e.ancestorTitles,e.title].join(` > `),n=e.invocations??1,r=e.status===`passed`?`pass`:e.status===`failed`?`fail`:`skip`;return{key:t,name:t,state:r,duration:e.duration??0,retries:n-1,flaky:r===`pass`&&n>1,errors:r===`fail`?[jestError(e)]:[]}}),i=e.context?.config?.displayName,a=typeof i==`string`?i:i?.name,s=t.testExecError;this.#n.add(o({runner:`jest`,root:e.context?.config?.rootDir??this.#e,file:t.testFilePath,...a?{project:a}:{},tests:r,collected:n?.collected??null,...s?{outsideTests:[{name:c,error:{message:s.message,stack:s.stack??void 0}}]}:{}},this.options))}async onRunComplete(){if(this.#n===null)return;let e=await this.#n.flush();e!==null&&process.stderr.write(`${e}${this.#r?``:` (no traces: add testRunner: "@ctrl/sentry-tests/jest-runner")`}\n`)}getLastError(){}#i(e){if(this.#t===null)return null;let r=u(this.#t,e);try{let e=JSON.parse(t(r,`utf8`));return n(r,{force:!0}),e}catch{return null}}};function jestError(e){let t=e.failureDetails[0];if(t!==void 0&&typeof t.message==`string`){let n=typeof t.stack==`string`?t.stack:e.failureMessages[0];return{name:typeof t.name==`string`?t.name:void 0,message:t.message,stack:n}}let n=e.failureMessages[0]??`Test failed`,r=n.search(/\n\s+at /);return{message:r<0?n:n.slice(0,r),stack:n}}export{SentryTestsReporter as default};
|
package/dist/vitest-runner.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_chunks/rolldown-runtime-
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{relative as e}from"node:path";import{TestRunner as t}from"vitest";import{n,t as r}from"./_chunks/collector-BrSszbTa.js";Error.stackTraceLimit<50&&(Error.stackTraceLimit=50);const i={"test.beforeEach":`beforeEach`,"test.afterEach":`afterEach`,"suite.beforeAll":`beforeAll`,"suite.afterAll":`afterAll`};function withSentry(t){let a=t.getSuiteHooks,o=t.prototype;return class SentryTestRunner extends t{#e;#t=/* @__PURE__ */ new Map;#n=/* @__PURE__ */ new Map;#r=/* @__PURE__ */ new WeakMap;#i=/* @__PURE__ */ new Map;#a;#o=0;constructor(...e){super(...e);let t=this.trace;this.trace=((e,n,r)=>this.#s(t,e,n,r))}onBeforeCollect(e){return this.#e=r(),o.onBeforeCollect?.call(this,e)}onAfterRunFiles(e){return this.#e.stop(),super.onAfterRunFiles(e)}onCollected(e){for(let t of e)this.#t.set(t.filepath,t),index(t,this.#n);return o.onCollected?.call(this,e)}onBeforeTryTask(e,t){return this.#o=t.retry,super.onBeforeTryTask(e,t)}async onTaskFinished(e){e.result?.state===`fail`&&await this.#e.captureFailure(this.#e.test(e.id),fullName(e),e.result.errors?.at(-1),globalThis.document),await o.onTaskFinished?.call(this,e)}async onAfterRunSuite(e){if(e===this.#a){let t=this.#e.finish(),n=this.#i.get(this.#a.filepath);n!==void 0&&t.spans.push(n),e.meta.sentryTests=t}return super.onAfterRunSuite(e)}#s(t,n,r,a){let call=()=>t(n,r,a),o=typeof r==`function`?{}:r,s=this.#e;switch(n){case`collect_spec`:{let t=String(o[`code.file.path`]),n=s.open(`test.collect`,`collect ${e(this.config.root,t)}`);return this.#l(n,call,()=>!1,()=>this.#i.set(t,n.span))}case`run.spec`:return this.#a=this.#t.get(String(o[`code.file.path`])),call();case`run.suite`:case`run.test`:{let e=this.#n.get(String(o[n===`run.suite`?`vitest.suite.id`:`vitest.test.id`]));if(e.mode===`skip`||e.mode===`todo`)return call();let t=o[`code.line.number`],r=typeof t==`number`?{"code.lineno":t}:{},i=n===`run.test`?s.test(e.id):void 0,a=s.open(n===`run.test`?`test.case`:`test.suite`,fullName(e),r,i);return i?.spanIds.push(a.span.span_id),this.#r.set(a,e),this.#l(a,call,()=>e.result?.state===`fail`)}case`test.callback`:{let e=s.open(`test.fn`,this.#r.get(s.current()).name,this.#o>0?{"test.retry":this.#o}:{});return this.#l(e,call,()=>!1)}}let c=i[n];if(c===void 0)return call();let l=this.#c(c);if(l===0)return call();let u={hooks:l};return this.#o>0&&(c===`beforeEach`||c===`afterEach`)&&(u[`test.retry`]=this.#o),this.#l(s.open(`test.hook`,c,u),call,()=>!1)}#c(e){let t=this.#e.current();if(e===`beforeAll`||e===`afterAll`){let n=t===null?this.#a:this.#r.get(t);return a(n)[e].length}let n=this.#r.get(t),r=0;for(let t=n.suite??n.file;t!==void 0;t=`filepath`in t?void 0:t.suite??t.file)r+=a(t)[e].length;return r}#l(e,t,r,i){let a=this.#e,end=t=>{if(i===void 0)return a.close(e,t);e.span.timestamp=n(),t&&(e.span.status=`internal_error`),i()},o;try{o=a.run(e,t)}catch(e){throw end(!0),e}return o instanceof Promise?o.then(e=>(end(r()),e),e=>{throw end(!0),e}):(end(r()),o)}}}function index(e,t){for(let n of e.tasks)t.set(n.id,n),n.type===`suite`&&index(n,t)}function fullName(e){let t=[e.name];for(let n=e.suite;n!==void 0&&n!==e.file;n=n.suite)t.unshift(n.name);return t.join(` > `)}var a=withSentry(t);export{a as default,withSentry};
|
package/dist/vitest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_chunks/rolldown-runtime-
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{fileURLToPath as e}from"node:url";import{i as t,n,r,t as i}from"./_chunks/report-CekWv1nz.js";import{t as a}from"./_chunks/delivery-9Rj__R9x.js";const o=e(new URL(import.meta.url.endsWith(`.ts`)?`./vitest-runner.ts`:`./vitest-runner.js`,import.meta.url)),s=/* @__PURE__ */ new WeakSet;function sentryTests(e={}){let t=r(e);return{name:`@ctrl/sentry-tests`,config(e){if(t===null)return;let n=e.test?.runner;if(n!==void 0)throw Error(`@ctrl/sentry-tests: the project has its own test runner (${n}). Build it with withSentry() from "@ctrl/sentry-tests/vitest-runner" and drop sentryTests() from the plugins, adding the reporter instead: reporters: ["default", "@ctrl/sentry-tests/vitest"].`);return{test:{runner:o}}},configureVitest({vitest:n}){t===null||s.has(n)||(s.add(n),n.config.reporters.push(new SentryReporter(e)))}}}var SentryReporter=class{options;#e=process.cwd();#t=null;#n;#r=/* @__PURE__ */ new Map;constructor(e={}){this.options=r(e),this.#n=this.options===null?null:new a(this.options,t)}onInit(e){this.#t=e,this.#e=e.config.root}onUserConsoleLog(e){if(this.options===null||e.taskId===void 0)return;let t=this.#r.get(e.taskId)??[];t.push({timestamp:e.time/1e3,stream:e.type,message:e.content.trimEnd()}),this.#r.set(e.taskId,t)}onTestModuleEnd(e){if(this.options===null||this.#n===null)return;let t=[...e.children.allTests()].map(e=>{let t=toTestCaseReport(e),n=this.#r.get(e.id);return n!==void 0&&(t.console=n,this.#r.delete(e.id)),t}),r=e.project.name;this.#n.add(n({runner:`vitest`,root:this.#e,file:e.moduleId,...r?{project:r}:{},tests:t,collected:e.meta().sentryTests??null,environmentSetupMs:e.diagnostic().environmentSetupDuration,outsideTests:[...e.errors().map(e=>({name:i,error:toErrorInfo(e)})),...[...e.children.allSuites()].flatMap(e=>e.errors().map(t=>({name:e.fullName,error:toErrorInfo(t)})))]},this.options))}async onTestRunEnd(){if(this.#n===null)return;let e=await this.#n.flush();e!==null&&(this.#t?.logger??console).log(e)}};function toTestCaseReport(e){let t=e.result(),n=e.diagnostic();return{key:e.id,name:e.fullName,state:t.state===`passed`?`pass`:t.state===`failed`?`fail`:`skip`,duration:n?.duration??0,retries:n?.retryCount??0,flaky:n?.flaky??!1,errors:(t.errors??[]).map(toErrorInfo)}}function toErrorInfo(e){return{name:e.name,message:e.message,stack:e.stack,...e.stacks?{frames:e.stacks.map(e=>({method:e.method,file:e.file,line:e.line,column:e.column}))}:{}}}export{SentryReporter,SentryReporter as default,sentryTests};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctrl/sentry-tests",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Test runs in Sentry for Vitest and Jest: each test file as a trace with spans for describe blocks, tests, hooks and test functions, failing tests as issues with the page attached, flaky tests as issues. No Sentry SDK.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sentry",
|
|
@@ -23,30 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
|
25
25
|
"type": "module",
|
|
26
|
-
"files": [
|
|
27
|
-
"dist",
|
|
28
|
-
"README.md",
|
|
29
|
-
"NOTICE",
|
|
30
|
-
"LICENSE"
|
|
31
|
-
],
|
|
32
26
|
"engines": {
|
|
33
27
|
"node": ">=26"
|
|
34
28
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"jest-circus": ">=30.0.0",
|
|
38
|
-
"vitest": ">=5.0.0"
|
|
39
|
-
},
|
|
40
|
-
"peerDependenciesMeta": {
|
|
41
|
-
"jest": {
|
|
42
|
-
"optional": true
|
|
43
|
-
},
|
|
44
|
-
"jest-circus": {
|
|
45
|
-
"optional": true
|
|
46
|
-
},
|
|
47
|
-
"vitest": {
|
|
48
|
-
"optional": true
|
|
49
|
-
}
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
50
31
|
},
|
|
51
32
|
"main": "./dist/index.js",
|
|
52
33
|
"types": "./dist/types/index.d.ts",
|
|
@@ -73,7 +54,26 @@
|
|
|
73
54
|
},
|
|
74
55
|
"./package.json": "./package.json"
|
|
75
56
|
},
|
|
76
|
-
"
|
|
77
|
-
"
|
|
57
|
+
"files": [
|
|
58
|
+
"dist",
|
|
59
|
+
"README.md",
|
|
60
|
+
"NOTICE",
|
|
61
|
+
"LICENSE"
|
|
62
|
+
],
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"jest": ">=30.0.0",
|
|
65
|
+
"jest-circus": ">=30.0.0",
|
|
66
|
+
"vitest": ">=5.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"jest": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"jest-circus": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"vitest": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import"./rolldown-runtime-H3fMLYWS.js";import{n as e,t}from"./channels-DmPSmlIK.js";import{randomBytes as n}from"node:crypto";import{AsyncLocalStorage as r}from"node:async_hooks";import{channel as i,tracingChannel as a}from"node:diagnostics_channel";import{performance as o}from"node:perf_hooks";import{setTimeout as s}from"node:timers/promises";const c=/* @__PURE__ */ new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`source`,`track`,`wbr`]),l=/* @__PURE__ */ new Set([`style`,`script`,`template`]);function pageHtml(e,t=2e5){let n=e?.body;if(n==null)return;let r=[],i=0,push=e=>(r.push(e),i+=e.length+1,i<t),write=(e,t)=>{let n=` `.repeat(t);if(e.nodeType===3){let t=(e.data??``).replace(/\s+/g,` `).trim();return t===``||push(n+escapeText(t))}if(e.nodeType!==1||e.localName===void 0)return!0;let r=`<${e.localName}${attributes(e)}`;if(c.has(e.localName))return push(`${n}${r} />`);let i=l.has(e.localName)?[]:childList(e);if(i.length===0)return push(`${n}${r}></${e.localName}>`);if(i.length===1&&i[0].nodeType===3){let t=(i[0].data??``).replace(/\s+/g,` `).trim();if(t.length<=80)return push(`${n}${r}>${escapeText(t)}</${e.localName}>`)}if(!push(`${n}${r}>`))return!1;for(let e of i)if(!write(e,t+1))return!1;return push(`${n}</${e.localName}>`)};try{write(n,0)||r.push(`<!-- truncated -->`)}catch{return}return r.join(`
|
|
2
|
-
`)}function childList(e){let t=[],n=e.childNodes;if(n===void 0)return t;for(let e=0;e<n.length;e++)(n[e].nodeType===1||n[e].nodeType===3)&&t.push(n[e]);return t}function attributes(e){let t=e.attributes;if(t===void 0)return``;let n=``;for(let e=0;e<t.length;e++)n+=` ${t[e].name}="${t[e].value.replaceAll(`&`,`&`).replaceAll(`"`,`"`)}"`;return n}function escapeText(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}const u=1e3,d=2e5,realNow=()=>(o.timeOrigin+o.now())/1e3;function spanIds(){let e=n(8),t=0;return()=>(e.writeUInt32BE(t++,4),e.toString(`hex`))}function createCollector(){let n=new r,o=Symbol(`sentry-tests.span`),c=spanIds(),l=null,f=emptyFile(),p={kept:0,limit:u,counts:f},m=/* @__PURE__ */ new Map,parent=()=>n.getStore()??l,open=(e,t,n={},r)=>{let i=parent(),a=realNow();return f.startedAt===0&&(f.startedAt=a),{span:{span_id:c(),parent_span_id:i?.span.span_id,op:e,description:t,start_timestamp:a,timestamp:0,status:`ok`,data:n},owner:r===void 0?i?.owner??p:m.get(r)}},openTraced=e=>{let t=parent();if(t===null)return;let n=t.owner;if(n.kept===n.limit)return n.counts.droppedSpans++,t;n.kept++;let r=open(e.op,e.description,e.data);return e[o]=r,r},closeTraced=e=>{let t=e[o];t!==void 0&&(e[o]=void 0,t.span.data=e.data,close(t,e.error!==void 0))},close=(e,t=!1)=>{e.span.timestamp=realNow(),t&&(e.span.status=`internal_error`),f.spans.push(e.span)},h={start(){},end(e){e.async&&e.error===void 0||closeTraced(e)},asyncStart(){},asyncEnd(e){closeTraced(e)},error(){}},g=e.map(e=>a(e));for(let e of g)e.start.bindStore(n,openTraced),e.subscribe(h);let _=i(t);return{open,close,run:(e,t)=>n.run(e,t),current:parent,enter(e){l=e},test(e){let t=f.tests[e];return t===void 0&&(t=f.tests[e]={spanIds:[],droppedSpans:0,failures:[]},m.set(t,{kept:0,limit:300,counts:t})),t},async captureFailure(e,t,n,r){let i={attachments:[],contexts:{}};if(typeof n==`object`&&n&&typeof n.message==`string`){let e=n;i.error={name:e.name,message:e.message,stack:e.stack}}let a=pageHtml(r,d);if(a!==void 0&&i.attachments.push({filename:`page.html`,contentType:`text/html`,data:a}),_.hasSubscribers){let e=[],a={test:t,error:n,document:r,attachments:[],contexts:i.contexts,waitUntil:t=>void e.push(t)};_.publish(a),e.length>0&&await Promise.race([Promise.allSettled(e),s(5e3,void 0,{ref:!1})]);for(let e of a.attachments)i.attachments.some(t=>t.filename===e.filename)||i.attachments.push({...e,data:e.data.slice(0,d)})}e.failures.push(i)},finish(){let e=f;return e.endedAt=realNow(),f=emptyFile(),p={kept:0,limit:u,counts:f},m.clear(),l=null,e},stop(){for(let e of g)e.unsubscribe(h),e.start.unbindStore(n)}}}function emptyFile(){return{startedAt:0,endedAt:0,spans:[],tests:Object.create(null),droppedSpans:0}}export{realNow as n,createCollector as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import"./rolldown-runtime-H3fMLYWS.js";import{n as e,t}from"./collector-IMkR4PbK.js";import{createHash as n}from"node:crypto";import{mkdirSync as r,writeFileSync as i}from"node:fs";import{join as a}from"node:path";const isJestsOwn=e=>/[\\/]jest-circus[\\/]/.test(e.asyncError?.stack?.split(`
|
|
2
|
-
`)[1]??``);function jestDataFile(e,t){return a(e,`${n(`sha1`).update(t).digest(`hex`)}.json`)}function circusTestName(e){let t=[e.name];for(let n=e.parent;n?.parent!==void 0;n=n.parent)t.unshift(n.name);return t.join(` > `)}function createJestCollector(n){let a=t(),o=[],s=/* @__PURE__ */ new WeakSet,push=e=>{o.push(e),a.enter(e)},pop=(e=!1)=>{let t=o.pop();t!==void 0&&a.close(t,e),a.enter(o.at(-1)??null)},c=null,endPhase=()=>{if(c===null)return;let{open:e,hooks:t,failed:n,end:r}=c;c=null,e.span.data.hooks=t,pop(n),r>0&&(e.span.timestamp=r)};return{async handleTestEvent(t){switch(t.name.startsWith(`hook_`)||endPhase(),t.name){case`setup`:push(a.open(`test.collect`,`collect`));break;case`run_start`:pop();break;case`run_describe_start`:t.describeBlock?.parent!==void 0&&push(a.open(`test.suite`,circusTestName(t.describeBlock)));break;case`run_describe_finish`:t.describeBlock?.parent!==void 0&&pop();break;case`test_start`:{let e=circusTestName(t.test),n=a.test(e),r=a.open(`test.case`,e,n.spanIds.length>0?{"test.retry":n.spanIds.length}:{},n);n.spanIds.push(r.span.span_id),push(r);break}case`test_done`:pop(t.test.errors.length>0);break;case`test_skip`:case`test_todo`:o.pop(),a.enter(o.at(-1)??null),a.test(circusTestName(t.test)).spanIds.pop();break;case`hook_start`:{let e=t.hook;if(isJestsOwn(e)){s.add(e);break}c?.type!==e.type&&(endPhase(),c={type:e.type,open:a.open(`test.hook`,e.type),hooks:0,failed:!1,end:0},push(c.open)),c.hooks++;break}case`hook_success`:c!==null&&!s.has(t.hook)&&(c.end=e());break;case`hook_failure`:c!==null&&!s.has(t.hook)&&(c.failed=!0,c.end=e()),t.test!==void 0&&t.hook?.type===`beforeEach`&&await capture(t.test,t.error);break;case`test_fn_start`:push(a.open(`test.fn`,t.test.name));break;case`test_fn_success`:pop();break;case`test_fn_failure`:pop(!0),await capture(t.test,t.error)}},finish(){let e=a.finish();a.stop();let t={testPath:n.testPath,collected:e};try{r(n.dir,{recursive:!0}),i(jestDataFile(n.dir,n.testPath),JSON.stringify(t))}catch{}}};function capture(e,t){let r=circusTestName(e);return a.captureFailure(a.test(r),r,t,n.getDocument())}}export{jestDataFile as n,createJestCollector as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"node:module";var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name as t};
|