@gjsify/unit 0.18.0 → 0.20.0

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,10 +1,10 @@
1
- import"./_virtual/_rolldown/runtime.js";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 runtimeGlobals=()=>globalThis,r=runtimeGlobals().imports?.mainloop;let i=0,a=0,o=0,s=0;const c=[],noteStrayFailure=e=>{++a,c.push({suite:d,message:e}),p.push({suite:d,test:`<stray assertion outside any it()>`,message:e})};let l=``,u=0,d=``,p=[],m={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=>{m={...m,...e}};function applyEnvOverrides(){try{let e=runtimeGlobals().process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(m.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(m.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(m.runTimeout=r)}catch{}}const h=`\x1B[31m`,g=`\x1B[32m`,_=`\x1B[34m`,v=`\x1B[90m`,y=`\x1B[39m`,now=()=>runtimeGlobals().performance?.now?.()??Date.now(),formatDuration=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,b=typeof runtimeGlobals().process?.versions?.gjs!=`string`&&runtimeGlobals().document!==void 0?console.log:globalThis.print||console.log;function formatValue(e){switch(typeof e){case`symbol`:return e.toString();case`bigint`:return`${e}n`;case`string`:return e;case`function`:return e.name?`[Function ${e.name}]`:`[Function (anonymous)]`;case`object`:if(e===null)return`null`;try{return JSON.stringify(e)??String(e)}catch{return Object.prototype.toString.call(e)}default:return String(e)}}function matchesObject(e,t){return Object.is(e,t)?!0:typeof t!=`object`||!t?e===t:typeof e!=`object`||!e?!1:Array.isArray(t)?!Array.isArray(e)||e.length!==t.length?!1:t.every((t,n)=>matchesObject(e[n],t)):Array.isArray(e)?!1:Object.keys(t).every(n=>matchesObject(e[n],t[n]))}const x=[],S=[];function envBag(){return globalThis.process?.env}const C={fn(e){let t=[],f=function(...n){return t.push(n),e?e.apply(this,n):void 0};return f.mock={calls:t},f},stubGlobal(e,t){let n=globalThis;x.push({key:e,had:e in n,prev:n[e]}),n[e]=t},unstubAllGlobals(){let e=globalThis;for(let t=x.length-1;t>=0;t--){let n=x[t];n.had?e[n.key]=n.prev:delete e[n.key]}x.length=0},stubEnv(e,t){let n=envBag();n&&(S.push({key:e,had:e in n,prev:n[e]}),t===void 0?delete n[e]:n[e]=t)},unstubAllEnvs(){let e=envBag();if(e){for(let t=S.length-1;t>=0;t--){let n=S[t];n.had?e[n.key]=n.prev:delete e[n.key]}S.length=0}}};var w=class MatcherFactory{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,s===0&&noteStrayFailure(t),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"./_virtual/_rolldown/runtime.js";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 runtimeGlobals=()=>globalThis,r=typeof runtimeGlobals().process?.versions?.gjs==`string`?runtimeGlobals().imports?.mainloop:void 0;let i=0,a=0,o=0,s=0;const c=[],noteStrayFailure=e=>{++a,c.push({suite:d,message:e}),p.push({suite:d,test:`<stray assertion outside any it()>`,message:e})};let l=``,u=0,d=``,p=[],m={testTimeout:5e3,suiteTimeout:3e4,runTimeout:12e4},h=new Map;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=>{m={...m,...e}};function applyEnvOverrides(){try{let e=runtimeGlobals().process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(m.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(m.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(m.runTimeout=r)}catch{}}const g=`\x1B[31m`,_=`\x1B[32m`,v=`\x1B[34m`,y=`\x1B[90m`,b=`\x1B[39m`,now=()=>runtimeGlobals().performance?.now?.()??Date.now(),formatDuration=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,x=typeof runtimeGlobals().process?.versions?.gjs!=`string`&&runtimeGlobals().document!==void 0?console.log:globalThis.print||console.log;function formatValue(e){switch(typeof e){case`symbol`:return e.toString();case`bigint`:return`${e}n`;case`string`:return e;case`function`:return e.name?`[Function ${e.name}]`:`[Function (anonymous)]`;case`object`:if(e===null)return`null`;try{return JSON.stringify(e)??String(e)}catch{return Object.prototype.toString.call(e)}default:return String(e)}}function matchesObject(e,t){return Object.is(e,t)?!0:typeof t!=`object`||!t?e===t:typeof e!=`object`||!e?!1:Array.isArray(t)?!Array.isArray(e)||e.length!==t.length?!1:t.every((t,n)=>matchesObject(e[n],t)):Array.isArray(e)?!1:Object.keys(t).every(n=>matchesObject(e[n],t[n]))}const S=[],C=[];function envBag(){return globalThis.process?.env}const w={fn(e){let t=[],f=function(...n){return t.push(n),e?e.apply(this,n):void 0};return f.mock={calls:t},f},stubGlobal(e,t){let n=globalThis;S.push({key:e,had:e in n,prev:n[e]}),n[e]=t},unstubAllGlobals(){let e=globalThis;for(let t=S.length-1;t>=0;t--){let n=S[t];n.had?e[n.key]=n.prev:delete e[n.key]}S.length=0},stubEnv(e,t){let n=envBag();n&&(C.push({key:e,had:e in n,prev:n[e]}),t===void 0?delete n[e]:n[e]=t)},unstubAllEnvs(){let e=envBag();if(e){for(let t=C.length-1;t>=0;t--){let n=C[t];n.had?e[n.key]=n.prev:delete e[n.key]}C.length=0}}};var T=class MatcherFactory{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,s===0&&noteStrayFailure(t),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: ${formatValue(e)} (${typeof e})\n Actual: ${formatValue(this.actualValue)} (${typeof this.actualValue})`)}toEqual(e){this.triggerResult(this.actualValue==e,` Expected values to match using ==
3
3
  Expected: ${formatValue(e)} (${typeof e})\n Actual: ${formatValue(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}`:``))}toMatchObject(e){this.triggerResult(matchesObject(this.actualValue,e),` Expected value to match object (partial deep match)
5
5
  Expected: ${formatValue(e)}\n Actual: ${formatValue(this.actualValue)}`)}mockCalls(){return this.actualValue?.mock?.calls??[]}toHaveBeenCalled(){this.triggerResult(this.mockCalls().length>0,` Expected mock function to have been called`)}toHaveBeenCalledTimes(e){let t=this.mockCalls().length;this.triggerResult(t===e,` Expected mock to have been called ${e} time(s)\n Actual: ${t} time(s)`)}toHaveBeenCalledWith(...e){let n=this.mockCalls().some(n=>{try{return t.deepStrictEqual(n,e),!0}catch{return!1}});this.triggerResult(n,` Expected mock to have been called with ${formatValue(e)}`)}toEqualArray(e){let t=this.actualValue,n=Array.isArray(t)&&Array.isArray(e)&&t.length===e.length;for(let r=0;r<t.length&&(n=t[r]==e[r],n);r++);this.triggerResult(n,` Expected array items to match using ==
6
6
  Expected: ${formatValue(e)} (${typeof e})\n Actual: ${formatValue(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){let t=this.actualValue;if(typeof t.match!=`function`)throw Error(`You can not use toMatch on type ${typeof this.actualValue}`);this.triggerResult(!!t.match(e),` Expected values to match using regular expression
7
7
  Expression: `+formatValue(e)+`
8
- Actual: `+formatValue(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`)}toBeNaN(){this.triggerResult(Number.isNaN(this.actualValue),` Expected value to be NaN\n Actual: ${formatValue(this.actualValue)}`)}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 `+formatValue(t)+` to contain `+formatValue(e))}toBeLessThan(e){this.triggerResult(this.actualValue<e,` Expected `+formatValue(this.actualValue)+` to be less than `+e)}toBeGreaterThan(e){this.triggerResult(this.actualValue>e,` Expected `+formatValue(this.actualValue)+` to be greater than `+e)}toBeGreaterThanOrEqual(e){this.triggerResult(this.actualValue>=e,` Expected ${formatValue(this.actualValue)} to be greater than or equal to ${e}`)}toBeLessThanOrEqual(e){this.triggerResult(this.actualValue<=e,` Expected ${formatValue(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 `+formatValue(this.actualValue)+` with precision `+t+` to be close to `+e)}toThrow(e){let t=``,n=!1,r=!0,i=!0,a=this.actualValue;try{a(),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 o=this.actualValue?.name||typeof this.actualValue==`function`?`[anonymous function]`:String(this.actualValue);this.triggerResult(n,` Expected ${o} 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}"`}`)}get rejects(){return{toThrow:e=>this.toReject(e),toReject:e=>this.toReject(e)}}get resolves(){return{toResolve:()=>this.toResolve()}}};const describe=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??m.suiteTimeout;b(`
9
- `+e);let i=d;d=e;let o=now();try{await withTimeout(t,r,`describe: ${e}`)}catch(e){if(e instanceof TimeoutError)++a,b(` ${h}⏱ Suite timed out: ${e.message}${y}`);else throw e}d=i,b(` ${v}↳ ${formatDuration(now()-o)}${y}`),T=null,E=null};describe.skip=async function(e,t){++o,b(`\n${_}- ${e} (skipped)${y}`)};const hasDisplay=()=>{let e=runtimeGlobals().process?.env;if(e)return!!(e.DISPLAY||e.WAYLAND_DISPLAY);try{let e=runtimeGlobals().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}b(`\nOn ${e.join(`, `)}${t?` `+t:``}`),await n()};let T,E;const beforeEach=function(e){T=e},afterEach=function(e){E=e},it=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??m.testTimeout,i=now();++s;try{typeof T==`function`&&await T(),await withTimeout(t,r,e),typeof E==`function`&&await E(),b(` ${g}✔${y} ${v}${e} (${formatDuration(now()-i)})${y}`)}catch(t){let n=now()-i;++a,p.push({suite:d,test:e,message:t.message??String(t)}),b(` ${h}${t instanceof TimeoutError?`⏱`:`❌`}${y} ${v}${e} (${formatDuration(n)})${y}`),b(`${h}${t.message}${y}`),t.stack&&b(t.stack)}finally{--s}};it.skip=async function(e,t){++o,b(` ${_}-${y} ${v}${e} (skipped)${y}`)};const expect=function(e,t){return++i,new w(e,!0)},failAssertion=e=>{throw e.__testFailureCounted=!0,s===0&&noteStrayFailure(e?.message??String(e)),e},assert=function(e,n){++i;try{t(e,n)}catch(e){failAssertion(e)}};assert.strictEqual=function(e,n,r){++i;try{t.strictEqual(e,n,r)}catch(e){failAssertion(e)}},assert.throws=function(e,...n){++i;let r;try{e()}catch(e){r=e}try{t.throws(()=>{if(r)throw r},n[0],n[1])}catch(e){failAssertion(e)}},assert.deepStrictEqual=function(e,n,r){++i;try{t.deepStrictEqual(e,n,r)}catch(e){failAssertion(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=runtimeGlobals(),t=e.document;t&&(e.__gjsify_test_results={passed:i-a,failed:a,total:i,errors:p},t.documentElement.dataset.testsDone=`true`)},printResult=()=>{let e=u>0?now()-u:0,t=e>0?` ${v}(${formatDuration(e)})`:``,n=l?`[${l}] `:``;if(o&&b(`\n${_}✔ ${o} ignored test${o>1?`s`:``}${y}`),c.length){b(`\n${h}⚠ ${c.length} assertion${c.length>1?`s`:``} fired outside any it() (leaked from a settled test)${y}`);for(let e of c)b(` ${h}↳ ${e.message.trim().split(`
10
- `)[0]}${y}`)}b(a?`\n${h}❌ ${n}${a} of ${i} tests failed${t}${y}`:`\n${g}✔ ${n}${i} completed${t}${y}`)},getRuntime=async()=>{if(l&&l!==`Unknown`)return l;if(globalThis.Deno?.version?.deno)return`Deno `+globalThis.Deno?.version?.deno;{let e=globalThis.process;if(!e)try{e=await import(`node:process`)}catch{}if(e?.versions?.gjs)return l=`Gjs `+e.versions.gjs,l;if(e?.versions?.node)return l=`Node.js `+e.versions.node,l}return runtimeGlobals().document===void 0?l||`Unknown`:(l=`Browser`,l)},printRuntime=async()=>{b(`\nRunning on ${await getRuntime()}`)},run=async(e,t)=>{if(applyEnvOverrides(),u=now(),t&&(typeof t==`number`?m.runTimeout=t:(t.timeout!==void 0&&(m.runTimeout=t.timeout),t.testTimeout!==void 0&&(m.testTimeout=t.testTimeout),t.suiteTimeout!==void 0&&(m.suiteTimeout=t.suiteTimeout))),printRuntime().then(async()=>{try{await withTimeout(()=>runTests(e),m.runTimeout,`entire test run`)}catch(e){if(e instanceof TimeoutError)b(`\n${h}⏱ ${e.message}${y}`),++a;else throw e}}).then(async()=>{if(printResult(),browserSignalDone(),b(),n(),r?.quit(),!r){let e=+(a>0);try{(globalThis.process||await import(`node:process`)).exit(e)}catch{}}}),r?.run(),r){let e=+(a>0);try{runtimeGlobals().imports?.system?.exit(e)}catch{}}};var D={run,assert,expect,it,afterEach,beforeEach,on,describe,configure,print:b,vi:C};export{afterEach,assert,beforeEach,configure,D as default,describe,expect,formatValue,it,on,b as print,run,e as spy,C as vi};
8
+ Actual: `+formatValue(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`)}toBeNaN(){this.triggerResult(Number.isNaN(this.actualValue),` Expected value to be NaN\n Actual: ${formatValue(this.actualValue)}`)}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 `+formatValue(t)+` to contain `+formatValue(e))}toBeLessThan(e){this.triggerResult(this.actualValue<e,` Expected `+formatValue(this.actualValue)+` to be less than `+e)}toBeGreaterThan(e){this.triggerResult(this.actualValue>e,` Expected `+formatValue(this.actualValue)+` to be greater than `+e)}toBeGreaterThanOrEqual(e){this.triggerResult(this.actualValue>=e,` Expected ${formatValue(this.actualValue)} to be greater than or equal to ${e}`)}toBeLessThanOrEqual(e){this.triggerResult(this.actualValue<=e,` Expected ${formatValue(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 `+formatValue(this.actualValue)+` with precision `+t+` to be close to `+e)}toThrow(e){let t=``,n=!1,r=!0,i=!0,a=this.actualValue;try{a(),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 o=this.actualValue?.name||typeof this.actualValue==`function`?`[anonymous function]`:String(this.actualValue);this.triggerResult(n,` Expected ${o} 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}"`}`)}get rejects(){return{toThrow:e=>this.toReject(e),toReject:e=>this.toReject(e)}}get resolves(){return{toResolve:()=>this.toResolve()}}};const describe=async function(e,t,n){let r=typeof n==`number`?n:n?.timeout??m.suiteTimeout;x(`
9
+ `+e);let i=d;d=e;let o=now();try{await withTimeout(t,r,`describe: ${e}`)}catch(e){if(e instanceof TimeoutError)++a,x(` ${g}⏱ Suite timed out: ${e.message}${b}`);else throw e}d=i,x(` ${y}↳ ${formatDuration(now()-o)}${b}`),E=null,D=null};describe.skip=async function(e,t){++o,x(`\n${v}- ${e} (skipped)${b}`)};const hasDisplay=()=>{let e=runtimeGlobals().process?.env;if(e)return!!(e.DISPLAY||e.WAYLAND_DISPLAY);try{let e=runtimeGlobals().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}x(`\nOn ${e.join(`, `)}${t?` `+t:``}`),await n()};let E,D;const beforeEach=function(e){E=e},afterEach=function(e){D=e},it=async function(e,t,n){let r=h.get(e);if(r!==void 0){++o,x(` ${v}-${b} ${y}${e} (skipped: ${r})${b}`);return}let i=typeof n==`number`?n:n?.timeout??m.testTimeout,c=now();++s;try{typeof E==`function`&&await E(),await withTimeout(t,i,e),typeof D==`function`&&await D(),x(` ${_}✔${b} ${y}${e} (${formatDuration(now()-c)})${b}`)}catch(t){let n=now()-c;++a,p.push({suite:d,test:e,message:t.message??String(t)}),x(` ${g}${t instanceof TimeoutError?`⏱`:`❌`}${b} ${y}${e} (${formatDuration(n)})${b}`),x(`${g}${t.message}${b}`),t.stack&&x(t.stack)}finally{--s}};it.skip=async function(e,t){++o,x(` ${v}-${b} ${y}${e} (skipped)${b}`)};const expect=function(e,t){return++i,new T(e,!0)},failAssertion=e=>{throw e.__testFailureCounted=!0,s===0&&noteStrayFailure(e?.message??String(e)),e},assert=function(e,n){++i;try{t(e,n)}catch(e){failAssertion(e)}};assert.strictEqual=function(e,n,r){++i;try{t.strictEqual(e,n,r)}catch(e){failAssertion(e)}},assert.throws=function(e,...n){++i;let r;try{e()}catch(e){r=e}try{t.throws(()=>{if(r)throw r},n[0],n[1])}catch(e){failAssertion(e)}},assert.deepStrictEqual=function(e,n,r){++i;try{t.deepStrictEqual(e,n,r)}catch(e){failAssertion(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=runtimeGlobals(),t=e.document;t&&(e.__gjsify_test_results={passed:i-a,failed:a,total:i,errors:p},t.documentElement.dataset.testsDone=`true`)},printResult=()=>{let e=u>0?now()-u:0,t=e>0?` ${y}(${formatDuration(e)})`:``,n=l?`[${l}] `:``;if(o&&x(`\n${v}✔ ${o} ignored test${o>1?`s`:``}${b}`),c.length){x(`\n${g}⚠ ${c.length} assertion${c.length>1?`s`:``} fired outside any it() (leaked from a settled test)${b}`);for(let e of c)x(` ${g}↳ ${e.message.trim().split(`
10
+ `)[0]}${b}`)}x(a?`\n${g}❌ ${n}${a} of ${i} tests failed${t}${b}`:`\n${_}✔ ${n}${i} completed${t}${b}`)},getRuntime=async()=>{if(l&&l!==`Unknown`)return l;if(globalThis.Deno?.version?.deno)return`Deno `+globalThis.Deno?.version?.deno;{let e=globalThis.process;if(!e)try{e=await import(`node:process`)}catch{}if(e?.versions?.gjs)return l=`Gjs `+e.versions.gjs,l;if(e?.versions?.node)return l=`Node.js `+e.versions.node,l}return runtimeGlobals().document===void 0?l||`Unknown`:(l=`Browser`,l)},printRuntime=async()=>{x(`\nRunning on ${await getRuntime()}`)},run=async(e,t)=>{if(applyEnvOverrides(),u=now(),h=new Map,t&&(typeof t==`number`?m.runTimeout=t:(t.timeout!==void 0&&(m.runTimeout=t.timeout),t.testTimeout!==void 0&&(m.testTimeout=t.testTimeout),t.suiteTimeout!==void 0&&(m.suiteTimeout=t.suiteTimeout),t.skip&&(h=new Map(Object.entries(t.skip))))),printRuntime().then(async()=>{try{await withTimeout(()=>runTests(e),m.runTimeout,`entire test run`)}catch(e){if(e instanceof TimeoutError)x(`\n${g}⏱ ${e.message}${b}`),++a;else throw e}}).then(async()=>{if(printResult(),browserSignalDone(),x(),n(),r?.quit(),!r){let e=+(a>0);try{(globalThis.process||await import(`node:process`)).exit(e)}catch{}}}),r?.run(),r){let e=+(a>0);try{runtimeGlobals().imports?.system?.exit(e)}catch{}}};var O={run,assert,expect,it,afterEach,beforeEach,on,describe,configure,print:x,vi:w};export{afterEach,assert,beforeEach,configure,O as default,describe,expect,formatValue,it,on,x as print,run,e as spy,w as vi};
@@ -112,12 +112,14 @@ export declare const run: (namespaces: Namespaces, options?: {
112
112
  timeout?: number;
113
113
  testTimeout?: number;
114
114
  suiteTimeout?: number;
115
+ skip?: Record<string, string>;
115
116
  } | number) => Promise<void>;
116
117
  declare const _default: {
117
118
  run: (namespaces: Namespaces, options?: {
118
119
  timeout?: number;
119
120
  testTimeout?: number;
120
121
  suiteTimeout?: number;
122
+ skip?: Record<string, string>;
121
123
  } | number) => Promise<void>;
122
124
  assert: {
123
125
  (success: unknown, message?: string | Error): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/unit",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
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",
@@ -46,21 +46,21 @@
46
46
  "devDependencies": {
47
47
  "@girs/gjs": "^4.1.0",
48
48
  "@girs/glib-2.0": "^4.1.0",
49
- "@gjsify/cli": "^0.18.0",
49
+ "@gjsify/cli": "^0.20.0",
50
50
  "@types/node": "^25.9.2",
51
51
  "typescript": "^6.0.3"
52
52
  },
53
53
  "dependencies": {
54
- "@gjsify/abort-controller": "^0.18.0",
55
- "@gjsify/assert": "^0.18.0",
56
- "@gjsify/buffer": "^0.18.0",
57
- "@gjsify/dom-elements": "^0.18.0",
58
- "@gjsify/dom-exception": "^0.18.0",
59
- "@gjsify/node-globals": "^0.18.0",
60
- "@gjsify/process": "^0.18.0",
61
- "@gjsify/utils": "^0.18.0",
62
- "@gjsify/web-globals": "^0.18.0",
63
- "@gjsify/web-streams": "^0.18.0"
54
+ "@gjsify/abort-controller": "^0.20.0",
55
+ "@gjsify/assert": "^0.20.0",
56
+ "@gjsify/buffer": "^0.20.0",
57
+ "@gjsify/dom-elements": "^0.20.0",
58
+ "@gjsify/dom-exception": "^0.20.0",
59
+ "@gjsify/node-globals": "^0.20.0",
60
+ "@gjsify/process": "^0.20.0",
61
+ "@gjsify/utils": "^0.20.0",
62
+ "@gjsify/web-globals": "^0.20.0",
63
+ "@gjsify/web-streams": "^0.20.0"
64
64
  },
65
65
  "gjsify": {
66
66
  "tier": 1