@gjsify/unit 0.3.19 → 0.3.21

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/lib/esm/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import{spy as e}from"./spy.js";import"@girs/gjs";import t from"node:assert";import{quitMainLoop as n}from"@gjsify/utils/main-loop";const r=globalThis?.imports?.mainloop;let i=0,a=0,o=0,s=``,c=0,l=``,u=[],d={testTimeout:5e3,suiteTimeout:3e4,runTimeout:12e4};var f=class extends Error{constructor(e,t){super(`Timeout: "${e}" exceeded ${t}ms`),this.name=`TimeoutError`}};async function p(e,t,n){if(t<=0)return e();let r,i=new Promise((e,i)=>{r=setTimeout(()=>i(new f(n,t)),t)}),a=Promise.resolve(e());a.catch(()=>{});try{return await Promise.race([a,i])}finally{clearTimeout(r)}}const m=e=>{d={...d,...e}};function h(){try{let e=globalThis.process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(d.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(d.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(d.runTimeout=r)}catch{}}const g=`\x1B[31m`,_=`\x1B[32m`,v=`\x1B[34m`,y=`\x1B[90m`,b=`\x1B[39m`,x=()=>globalThis.performance?.now?.()??Date.now(),S=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,C=typeof globalThis.process?.versions?.gjs!=`string`&&globalThis.document!==void 0?console.log:globalThis.print||console.log;var w=class e{actualValue;positive;not;constructor(t,n,r){this.actualValue=t,this.positive=n,r?this.not=r:this.not=new e(t,!n,this)}triggerResult(e,t){if(e&&!this.positive||!e&&this.positive){let e=Error(t);throw e.__testFailureCounted=!0,++a,e}}to(e){this.triggerResult(e(this.actualValue),` Expected callback to validate`)}toBe(e){this.triggerResult(this.actualValue===e,` Expected values to match using ===
1
+ import{spy as e}from"./spy.js";import"@girs/gjs";import t from"node:assert";import{quitMainLoop as n}from"@gjsify/utils/main-loop";const r=globalThis?.imports?.mainloop;let i=0,a=0,o=0,s=``,c=0,l=``,u=[],d={testTimeout:5e3,suiteTimeout:3e4,runTimeout:12e4};var TimeoutError=class extends Error{constructor(e,t){super(`Timeout: "${e}" exceeded ${t}ms`),this.name=`TimeoutError`}};async function withTimeout(e,t,n){if(t<=0)return e();let r,i=new Promise((e,i)=>{r=setTimeout(()=>i(new TimeoutError(n,t)),t)}),a=Promise.resolve(e());a.catch(()=>{});try{return await Promise.race([a,i])}finally{clearTimeout(r)}}const configure=e=>{d={...d,...e}};function applyEnvOverrides(){try{let e=globalThis.process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(d.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(d.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(d.runTimeout=r)}catch{}}const f=`\x1B[31m`,p=`\x1B[32m`,m=`\x1B[34m`,h=`\x1B[90m`,g=`\x1B[39m`,now=()=>globalThis.performance?.now?.()??Date.now(),formatDuration=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,_=typeof globalThis.process?.versions?.gjs!=`string`&&globalThis.document!==void 0?console.log:globalThis.print||console.log;var v=class MatcherFactory{actualValue;positive;not;constructor(e,t,n){this.actualValue=e,this.positive=t,n?this.not=n:this.not=new MatcherFactory(e,!t,this)}triggerResult(e,t){if(e&&!this.positive||!e&&this.positive){let e=Error(t);throw e.__testFailureCounted=!0,++a,e}}to(e){this.triggerResult(e(this.actualValue),` Expected callback to validate`)}toBe(e){this.triggerResult(this.actualValue===e,` Expected values to match using ===
2
2
  Expected: ${e} (${typeof e})\n Actual: ${this.actualValue} (${typeof this.actualValue})`)}toEqual(e){this.triggerResult(this.actualValue==e,` Expected values to match using ==
3
3
  Expected: ${e} (${typeof e})\n Actual: ${this.actualValue} (${typeof this.actualValue})`)}toStrictEqual(e){let n=!0,r=``;try{t.deepStrictEqual(this.actualValue,e)}catch(e){n=!1,r=e.message||``}this.triggerResult(n,` Expected values to be deeply strictly equal
4
4
  Expected: ${JSON.stringify(e)}\n Actual: ${JSON.stringify(this.actualValue)}`+(r?`\n ${r}`:``))}toEqualArray(e){let t=Array.isArray(this.actualValue)&&Array.isArray(e)&&this.actualValue.length===e.length;for(let n=0;n<this.actualValue.length&&(t=this.actualValue[n]==e[n],t);n++);this.triggerResult(t,` Expected array items to match using ==
5
5
  Expected: ${e} (${typeof e})\n Actual: ${this.actualValue} (${typeof this.actualValue})`)}toBeInstanceOf(e){this.triggerResult(this.actualValue instanceof e,` Expected value to be instance of ${e.name||e}\n Actual: ${this.actualValue?.constructor?.name||typeof this.actualValue}`)}toHaveLength(e){let t=this.actualValue?.length;this.triggerResult(t===e,` Expected length: ${e}\n Actual length: ${t}`)}toMatch(e){if(typeof this.actualValue.match!=`function`)throw Error(`You can not use toMatch on type ${typeof this.actualValue}`);this.triggerResult(!!this.actualValue.match(e),` Expected values to match using regular expression
6
6
  Expression: `+e+`
7
- Actual: `+this.actualValue)}toBeDefined(){this.triggerResult(this.actualValue!==void 0,` Expected value to be defined`)}toBeUndefined(){this.triggerResult(this.actualValue===void 0,` Expected value to be undefined`)}toBeNull(){this.triggerResult(this.actualValue===null,` Expected value to be null`)}toBeTruthy(){this.triggerResult(this.actualValue,` Expected value to be truthy`)}toBeFalsy(){this.triggerResult(!this.actualValue,` Expected value to be falsy`)}toContain(e){let t=this.actualValue,n;n=typeof t==`string`?t.includes(String(e)):t instanceof Array?t.indexOf(e)!==-1:!1,this.triggerResult(n,` Expected `+t+` to contain `+e)}toBeLessThan(e){this.triggerResult(this.actualValue<e,` Expected `+this.actualValue+` to be less than `+e)}toBeGreaterThan(e){this.triggerResult(this.actualValue>e,` Expected `+this.actualValue+` to be greater than `+e)}toBeGreaterThanOrEqual(e){this.triggerResult(this.actualValue>=e,` Expected ${this.actualValue} to be greater than or equal to ${e}`)}toBeLessThanOrEqual(e){this.triggerResult(this.actualValue<=e,` Expected ${this.actualValue} to be less than or equal to ${e}`)}toBeCloseTo(e,t){let n=10**t;this.triggerResult(Math.round(this.actualValue*n)/n===Math.round(e*n)/n,` Expected `+this.actualValue+` with precision `+t+` to be close to `+e)}toThrow(e){let t=``,n=!1,r=!0,i=!0;try{this.actualValue(),n=!1}catch(a){t=a.message||``,n=!0,typeof e==`function`?r=a instanceof e:typeof e==`string`?i=t.includes(e):e instanceof RegExp&&(i=e.test(t))}let a=this.actualValue.name||typeof this.actualValue==`function`?`[anonymous function]`:this.actualValue.toString();this.triggerResult(n,` Expected ${a} to ${this.positive?`throw`:`not throw`} an exception ${!this.positive&&t?`, but an error with the message "${t}" was thrown`:``}`),typeof e==`function`?this.triggerResult(r,` Expected Error type '${e.name}', but the error is not an instance of it`):e!==void 0&&this.triggerResult(i,` Expected error message to match ${e}\n Actual message: "${t}"`)}async toReject(e){let t=!1,n=``,r=!0,i=!0;try{await this.actualValue,t=!1}catch(a){t=!0,n=a?.message||String(a),typeof e==`function`?r=a instanceof e:typeof e==`string`?i=n.includes(e):e instanceof RegExp&&(i=e.test(n))}this.triggerResult(t,` Expected promise to ${this.positive?`reject`:`resolve`}${!this.positive&&n?`, but it rejected with "${n}"`:``}`),t&&typeof e==`function`?this.triggerResult(r,` Expected rejection type '${e.name}', but the error is not an instance of it`):t&&e!==void 0&&this.triggerResult(i,` Expected rejection message to match ${e}\n Actual message: "${n}"`)}async toResolve(){let e=!1,t=``;try{await this.actualValue,e=!0}catch(n){e=!1,t=n?.message||String(n)}this.triggerResult(e,` Expected promise to ${this.positive?`resolve`:`reject`}${e?``:`, but it rejected with "${t}"`}`)}};const T=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??d.suiteTimeout;C(`
8
- `+e);let i=l;l=e;let o=x();try{await p(t,r,`describe: ${e}`)}catch(e){if(e instanceof f)++a,C(` ${g}⏱ Suite timed out: ${e.message}${b}`);else throw e}l=i,C(` ${y}↳ ${S(x()-o)}${b}`),k=null,A=null};T.skip=async function(e,t){++o,C(`\n${v}- ${e} (skipped)${b}`)};const E=()=>{let e=globalThis.process?.env;if(e)return!!(e.DISPLAY||e.WAYLAND_DISPLAY);try{let e=globalThis?.imports?.gi?.GLib;if(e)return!!(e.getenv(`DISPLAY`)||e.getenv(`WAYLAND_DISPLAY`))}catch{}return!1},D=async function(e,t){if(e.includes(`Display`))return{matched:E()};let n=await z(),r=e.find(e=>n.includes(e));return!r||typeof t==`string`&&!n.includes(t)?{matched:!1}:{matched:!0,runtime:r,version:t}},O=async function(e,t,n){typeof e==`string`&&(e=[e]),typeof t==`function`&&(n=t,t=void 0);let{matched:r}=await D(e,t);if(!r){++o;return}C(`\nOn ${e.join(`, `)}${t?` `+t:``}`),await n()};let k,A;const j=function(e){k=e},M=function(e){A=e},N=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??d.testTimeout,i=x();try{typeof k==`function`&&await k(),await p(t,r,e),typeof A==`function`&&await A(),C(` ${_}✔${b} ${y}${e} (${S(x()-i)})${b}`)}catch(t){let n=x()-i;t.__testFailureCounted||++a,u.push({suite:l,test:e,message:t.message??String(t)}),C(` ${g}${t instanceof f?`⏱`:`❌`}${b} ${y}${e} (${S(n)})${b}`),C(`${g}${t.message}${b}`),t.stack&&C(t.stack)}};N.skip=async function(e,t){++o,C(` ${v}-${b} ${y}${e} (skipped)${b}`)};const P=function(e){return++i,new w(e,!0)},F=function(e,n){++i,e||++a;try{t(e,n)}catch(e){throw e.__testFailureCounted=!0,e}};F.strictEqual=function(e,n,r){++i;try{t.strictEqual(e,n,r)}catch(e){throw++a,e.__testFailureCounted=!0,e}},F.throws=function(e,...n){++i;let r;try{e()}catch(e){r=e}r||++a,t.throws(()=>{if(r)throw r},n[0],n[1])},F.deepStrictEqual=function(e,n,r){++i;try{t.deepStrictEqual(e,n,r)}catch(e){throw++a,e.__testFailureCounted=!0,e}};const I=async function(e){for(let t in e){let n=e[t];typeof n==`function`?await n():typeof n==`object`&&await I(n)}},L=()=>{let e=globalThis.document;e&&(globalThis.__gjsify_test_results={passed:i-a,failed:a,total:i,errors:u},e.documentElement.dataset.testsDone=`true`)},R=()=>{let e=c>0?x()-c:0,t=e>0?` ${y}(${S(e)})`:``;o&&C(`\n${v}✔ ${o} ignored test${o>1?`s`:``}${b}`),C(a?`\n${g}❌ ${a} of ${i} tests failed${t}${b}`:`\n${_}✔ ${i} completed${t}${b}`)},z=async()=>{if(s&&s!==`Unknown`)return s;if(globalThis.Deno?.version?.deno)return`Deno `+globalThis.Deno?.version?.deno;{let e=globalThis.process;if(!e)try{e=await import(`process`)}catch{}if(e?.versions?.gjs)return s=`Gjs `+e.versions.gjs,s;if(e?.versions?.node)return s=`Node.js `+e.versions.node,s}return globalThis.document===void 0?s||`Unknown`:(s=`Browser`,s)},B=async()=>{C(`\nRunning on ${await z()}`)},V=async(e,t)=>{if(h(),c=x(),t&&(typeof t==`number`?d.runTimeout=t:(t.timeout!==void 0&&(d.runTimeout=t.timeout),t.testTimeout!==void 0&&(d.testTimeout=t.testTimeout),t.suiteTimeout!==void 0&&(d.suiteTimeout=t.suiteTimeout))),B().then(async()=>{try{await p(()=>I(e),d.runTimeout,`entire test run`)}catch(e){if(e instanceof f)C(`\n${g}⏱ ${e.message}${b}`),++a;else throw e}}).then(async()=>{if(R(),L(),C(),n(),r?.quit(),!r){let e=+(a>0);try{(globalThis.process||await import(`process`)).exit(e)}catch{}}}),r?.run(),r){let e=+(a>0);try{globalThis.imports.system.exit(e)}catch{}}};var H={run:V,assert:F,expect:P,it:N,afterEach:M,beforeEach:j,on:O,describe:T,configure:m,print:C};export{M as afterEach,F as assert,j as beforeEach,m as configure,H as default,T as describe,P as expect,N as it,O as on,C as print,V as run,e as spy};
7
+ Actual: `+this.actualValue)}toBeDefined(){this.triggerResult(this.actualValue!==void 0,` Expected value to be defined`)}toBeUndefined(){this.triggerResult(this.actualValue===void 0,` Expected value to be undefined`)}toBeNull(){this.triggerResult(this.actualValue===null,` Expected value to be null`)}toBeTruthy(){this.triggerResult(this.actualValue,` Expected value to be truthy`)}toBeFalsy(){this.triggerResult(!this.actualValue,` Expected value to be falsy`)}toContain(e){let t=this.actualValue,n;n=typeof t==`string`?t.includes(String(e)):t instanceof Array?t.indexOf(e)!==-1:!1,this.triggerResult(n,` Expected `+t+` to contain `+e)}toBeLessThan(e){this.triggerResult(this.actualValue<e,` Expected `+this.actualValue+` to be less than `+e)}toBeGreaterThan(e){this.triggerResult(this.actualValue>e,` Expected `+this.actualValue+` to be greater than `+e)}toBeGreaterThanOrEqual(e){this.triggerResult(this.actualValue>=e,` Expected ${this.actualValue} to be greater than or equal to ${e}`)}toBeLessThanOrEqual(e){this.triggerResult(this.actualValue<=e,` Expected ${this.actualValue} to be less than or equal to ${e}`)}toBeCloseTo(e,t){let n=10**t;this.triggerResult(Math.round(this.actualValue*n)/n===Math.round(e*n)/n,` Expected `+this.actualValue+` with precision `+t+` to be close to `+e)}toThrow(e){let t=``,n=!1,r=!0,i=!0;try{this.actualValue(),n=!1}catch(a){t=a.message||``,n=!0,typeof e==`function`?r=a instanceof e:typeof e==`string`?i=t.includes(e):e instanceof RegExp&&(i=e.test(t))}let a=this.actualValue.name||typeof this.actualValue==`function`?`[anonymous function]`:this.actualValue.toString();this.triggerResult(n,` Expected ${a} to ${this.positive?`throw`:`not throw`} an exception ${!this.positive&&t?`, but an error with the message "${t}" was thrown`:``}`),typeof e==`function`?this.triggerResult(r,` Expected Error type '${e.name}', but the error is not an instance of it`):e!==void 0&&this.triggerResult(i,` Expected error message to match ${e}\n Actual message: "${t}"`)}async toReject(e){let t=!1,n=``,r=!0,i=!0;try{await this.actualValue,t=!1}catch(a){t=!0,n=a?.message||String(a),typeof e==`function`?r=a instanceof e:typeof e==`string`?i=n.includes(e):e instanceof RegExp&&(i=e.test(n))}this.triggerResult(t,` Expected promise to ${this.positive?`reject`:`resolve`}${!this.positive&&n?`, but it rejected with "${n}"`:``}`),t&&typeof e==`function`?this.triggerResult(r,` Expected rejection type '${e.name}', but the error is not an instance of it`):t&&e!==void 0&&this.triggerResult(i,` Expected rejection message to match ${e}\n Actual message: "${n}"`)}async toResolve(){let e=!1,t=``;try{await this.actualValue,e=!0}catch(n){e=!1,t=n?.message||String(n)}this.triggerResult(e,` Expected promise to ${this.positive?`resolve`:`reject`}${e?``:`, but it rejected with "${t}"`}`)}};const describe=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??d.suiteTimeout;_(`
8
+ `+e);let i=l;l=e;let o=now();try{await withTimeout(t,r,`describe: ${e}`)}catch(e){if(e instanceof TimeoutError)++a,_(` ${f}⏱ Suite timed out: ${e.message}${g}`);else throw e}l=i,_(` ${h}↳ ${formatDuration(now()-o)}${g}`),y=null,b=null};describe.skip=async function(e,t){++o,_(`\n${m}- ${e} (skipped)${g}`)};const hasDisplay=()=>{let e=globalThis.process?.env;if(e)return!!(e.DISPLAY||e.WAYLAND_DISPLAY);try{let e=globalThis?.imports?.gi?.GLib;if(e)return!!(e.getenv(`DISPLAY`)||e.getenv(`WAYLAND_DISPLAY`))}catch{}return!1},runtimeMatch=async function(e,t){if(e.includes(`Display`))return{matched:hasDisplay()};let n=await getRuntime(),r=e.find(e=>n.includes(e));return!r||typeof t==`string`&&!n.includes(t)?{matched:!1}:{matched:!0,runtime:r,version:t}},on=async function(e,t,n){typeof e==`string`&&(e=[e]),typeof t==`function`&&(n=t,t=void 0);let{matched:r}=await runtimeMatch(e,t);if(!r){++o;return}_(`\nOn ${e.join(`, `)}${t?` `+t:``}`),await n()};let y,b;const beforeEach=function(e){y=e},afterEach=function(e){b=e},it=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??d.testTimeout,i=now();try{typeof y==`function`&&await y(),await withTimeout(t,r,e),typeof b==`function`&&await b(),_(` ${p}✔${g} ${h}${e} (${formatDuration(now()-i)})${g}`)}catch(t){let n=now()-i;t.__testFailureCounted||++a,u.push({suite:l,test:e,message:t.message??String(t)}),_(` ${f}${t instanceof TimeoutError?`⏱`:`❌`}${g} ${h}${e} (${formatDuration(n)})${g}`),_(`${f}${t.message}${g}`),t.stack&&_(t.stack)}};it.skip=async function(e,t){++o,_(` ${m}-${g} ${h}${e} (skipped)${g}`)};const expect=function(e){return++i,new v(e,!0)},assert=function(e,n){++i,e||++a;try{t(e,n)}catch(e){throw e.__testFailureCounted=!0,e}};assert.strictEqual=function(e,n,r){++i;try{t.strictEqual(e,n,r)}catch(e){throw++a,e.__testFailureCounted=!0,e}},assert.throws=function(e,...n){++i;let r;try{e()}catch(e){r=e}r||++a,t.throws(()=>{if(r)throw r},n[0],n[1])},assert.deepStrictEqual=function(e,n,r){++i;try{t.deepStrictEqual(e,n,r)}catch(e){throw++a,e.__testFailureCounted=!0,e}};const runTests=async function(e){for(let t in e){let n=e[t];typeof n==`function`?await n():typeof n==`object`&&await runTests(n)}},browserSignalDone=()=>{let e=globalThis.document;e&&(globalThis.__gjsify_test_results={passed:i-a,failed:a,total:i,errors:u},e.documentElement.dataset.testsDone=`true`)},printResult=()=>{let e=c>0?now()-c:0,t=e>0?` ${h}(${formatDuration(e)})`:``;o&&_(`\n${m}✔ ${o} ignored test${o>1?`s`:``}${g}`),_(a?`\n${f}❌ ${a} of ${i} tests failed${t}${g}`:`\n${p}✔ ${i} completed${t}${g}`)},getRuntime=async()=>{if(s&&s!==`Unknown`)return s;if(globalThis.Deno?.version?.deno)return`Deno `+globalThis.Deno?.version?.deno;{let e=globalThis.process;if(!e)try{e=await import(`process`)}catch{}if(e?.versions?.gjs)return s=`Gjs `+e.versions.gjs,s;if(e?.versions?.node)return s=`Node.js `+e.versions.node,s}return globalThis.document===void 0?s||`Unknown`:(s=`Browser`,s)},printRuntime=async()=>{_(`\nRunning on ${await getRuntime()}`)},run=async(e,t)=>{if(applyEnvOverrides(),c=now(),t&&(typeof t==`number`?d.runTimeout=t:(t.timeout!==void 0&&(d.runTimeout=t.timeout),t.testTimeout!==void 0&&(d.testTimeout=t.testTimeout),t.suiteTimeout!==void 0&&(d.suiteTimeout=t.suiteTimeout))),printRuntime().then(async()=>{try{await withTimeout(()=>runTests(e),d.runTimeout,`entire test run`)}catch(e){if(e instanceof TimeoutError)_(`\n${f}⏱ ${e.message}${g}`),++a;else throw e}}).then(async()=>{if(printResult(),browserSignalDone(),_(),n(),r?.quit(),!r){let e=+(a>0);try{(globalThis.process||await import(`process`)).exit(e)}catch{}}}),r?.run(),r){let e=+(a>0);try{globalThis.imports.system.exit(e)}catch{}}};var x={run,assert,expect,it,afterEach,beforeEach,on,describe,configure,print:_};export{afterEach,assert,beforeEach,configure,x as default,describe,expect,it,on,_ as print,run,e as spy};
package/lib/esm/spy.js CHANGED
@@ -1 +1 @@
1
- function e(e){let n=[];function r(...t){let r;try{r=e?e.apply(this,t):void 0}catch(e){throw n.push({type:`throw`,this:this,arguments:t,throw:e}),e}return n.push({type:`return`,this:this,arguments:t,return:r}),r}return Object.defineProperties(r,{calls:t.calls(n),returnedCalls:t.returnedCalls,thrownCalls:t.thrownCalls,firstCall:t.firstCall,lastCall:t.lastCall,firstReturnedCall:t.firstReturnedCall,lastReturnedCall:t.lastReturnedCall,firstThrownCall:t.firstThrownCall,lastThrownCall:t.lastThrownCall,reset:t.reset,toString:t.toString(e)}),r}const t={calls(e){return{value:e,configurable:!0}},returnedCalls:{get:function(){return this.calls.filter(n)},configurable:!0},thrownCalls:{get:function(){return this.calls.filter(r)},configurable:!0},firstCall:{get:function(){return this.calls[0]||null},configurable:!0},lastCall:{get:function(){return this.calls[this.calls.length-1]||null},configurable:!0},firstReturnedCall:{get:function(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(n(t))return t}return null},configurable:!0},lastReturnedCall:{get:function(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(n(t))return t}return null},configurable:!0},firstThrownCall:{get:function(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(r(t))return t}return null},configurable:!0},lastThrownCall:{get:function(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(r(t))return t}return null},configurable:!0},reset:{value:function(){this.calls.length=0},configurable:!0},toString(e){return{value:function(){return`/* The spy of */ ${e?e.toString():`function(){}`}`},configurable:!0}}};function n(e){return e.type===`return`}function r(e){return e.type===`throw`}export{e as spy};
1
+ function spy(t){let n=[];function spy(...e){let r;try{r=t?t.apply(this,e):void 0}catch(t){throw n.push({type:`throw`,this:this,arguments:e,throw:t}),t}return n.push({type:`return`,this:this,arguments:e,return:r}),r}return Object.defineProperties(spy,{calls:e.calls(n),returnedCalls:e.returnedCalls,thrownCalls:e.thrownCalls,firstCall:e.firstCall,lastCall:e.lastCall,firstReturnedCall:e.firstReturnedCall,lastReturnedCall:e.lastReturnedCall,firstThrownCall:e.firstThrownCall,lastThrownCall:e.lastThrownCall,reset:e.reset,toString:e.toString(t)}),spy}const e={calls(e){return{value:e,configurable:!0}},returnedCalls:{get:function(){return this.calls.filter(isReturned)},configurable:!0},thrownCalls:{get:function(){return this.calls.filter(isThrown)},configurable:!0},firstCall:{get:function(){return this.calls[0]||null},configurable:!0},lastCall:{get:function(){return this.calls[this.calls.length-1]||null},configurable:!0},firstReturnedCall:{get:function(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(isReturned(t))return t}return null},configurable:!0},lastReturnedCall:{get:function(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(isReturned(t))return t}return null},configurable:!0},firstThrownCall:{get:function(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(isThrown(t))return t}return null},configurable:!0},lastThrownCall:{get:function(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(isThrown(t))return t}return null},configurable:!0},reset:{value:function(){this.calls.length=0},configurable:!0},toString(e){return{value:function(){return`/* The spy of */ ${e?e.toString():`function(){}`}`},configurable:!0}}};function isReturned(e){return e.type===`return`}function isThrown(e){return e.type===`throw`}export{spy};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/unit",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "description": "A BDD-style testing framework for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -43,13 +43,13 @@
43
43
  "devDependencies": {
44
44
  "@girs/gjs": "4.0.0-rc.14",
45
45
  "@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
46
- "@gjsify/cli": "^0.3.19",
46
+ "@gjsify/cli": "^0.3.21",
47
47
  "@types/node": "^25.6.2",
48
48
  "typescript": "^6.0.3"
49
49
  },
50
50
  "dependencies": {
51
- "@gjsify/assert": "^0.3.19",
52
- "@gjsify/process": "^0.3.19",
53
- "@gjsify/utils": "^0.3.19"
51
+ "@gjsify/assert": "^0.3.21",
52
+ "@gjsify/process": "^0.3.21",
53
+ "@gjsify/utils": "^0.3.21"
54
54
  }
55
55
  }