@gjsify/unit 0.64.1-next.240 → 0.64.1-next.244
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 +9 -9
- package/lib/types/index.d.ts +73 -0
- package/package.json +14 -14
package/lib/esm/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{canRealizeGl as e,canRealizeSurface as t}from"./capabilities.js";import{spy as n}from"./spy.js";import{createHeartbeat as r}from"./heartbeat.js";import"@girs/gjs";import i from"node:assert";import{runtimeName as a,runtimeVersion as o}from"@gjsify/runtime";import{hostOs as s}from"@gjsify/utils/core";import{quitMainLoop as c}from"@gjsify/utils/main-loop";const runtimeGlobals=()=>globalThis,l=typeof runtimeGlobals().process?.versions?.gjs==`string`?runtimeGlobals().imports?.mainloop:void 0;let u=0,d=0,p=0,m=0,h=0,g=!1,_=0;const
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{canRealizeGl as e,canRealizeSurface as t}from"./capabilities.js";import{spy as n}from"./spy.js";import{createHeartbeat as r}from"./heartbeat.js";import"@girs/gjs";import i from"node:assert";import{runtimeName as a,runtimeVersion as o}from"@gjsify/runtime";import{hostOs as s}from"@gjsify/utils/core";import{quitMainLoop as c}from"@gjsify/utils/main-loop";const runtimeGlobals=()=>globalThis,l=typeof runtimeGlobals().process?.versions?.gjs==`string`?runtimeGlobals().imports?.mainloop:void 0;let u=0,d=0,p=0,m=0,h=0,g=!1,_=``,v=0;const y=new Map,axisRecord=e=>{let t=y.get(e);return t||(t={matched:0,ignored:0,tests:0},y.set(e,t)),t};let b=0;const x=[],S=[],noteWarning=e=>{S.push({suite:D,message:e})},errorMessage=e=>e?.message??String(e);let C=!0;const probeCwd=()=>{let e=runtimeGlobals().process?.cwd;if(typeof e!=`function`)return!0;try{return e(),!0}catch{return!1}},noteIfCwdDestroyed=e=>{if(!C||probeCwd())return;C=!1,++m;let t="this test left the process in a deleted working directory — every later `process.cwd()`, including one inside a spawned child, now fails with ENOENT. A spec that `chdir`s into a temp dir must chdir BACK before removing it, and the whole run shares one process.";k.push({suite:D,test:e,message:t}),B(` ${F}❌ ${e} — ${t}${z}`)},noteStrayFailure=e=>{++m,x.push({suite:D,message:e}),k.push({suite:D,test:`<stray assertion outside any it()>`,message:e})},w=[],noteThrownAssertion=e=>{let t=w[w.length-1];t&&e instanceof Error&&t.add(e)},forgetThrownAssertion=e=>{if(e instanceof Error)for(let t of w)t.delete(e)};let T=``,E=0,D=``,O=``,k=[],A={testTimeout:5e3,suiteTimeout:3e4,runTimeout:12e4},j=r(void 0,0),M=new Map;var TimeoutError=class extends Error{constructor(e,t){super(`Timeout: "${e}" exceeded ${t}ms`),this.name=`TimeoutError`}};const N=[];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)});i.catch(()=>{});let a,o=new Promise((e,t)=>{a=t});o.catch(()=>{}),N.push(a);try{let t=Promise.resolve(e());return t.catch(()=>{}),await Promise.race([t,i,o])}finally{clearTimeout(r);let e=N.lastIndexOf(a);e!==-1&&N.splice(e,1)}}let P=!1;const installUncaughtHooks=()=>{if(P)return;let e=runtimeGlobals().process;if(typeof e?.on!=`function`||typeof e.versions?.gjs==`string`)return;P=!0;let handle=t=>n=>{let r=n?.__testFailureCounted===!0,i=(e.listenerCount?.(t)??1)-1;if(!r&&i>0){let e=n?.message??String(n),r=b>0?` during "${O}"`:``;noteWarning(`${t}: ${e}${r} — absorbed by a listener the spec installed itself`);return}let a=N[N.length-1];a?a(n):noteStrayFailure(n?.message??String(n))};e.on(`uncaughtException`,handle(`uncaughtException`)),e.on(`unhandledRejection`,handle(`unhandledRejection`))},configure=e=>{A={...A,...e}};function applyEnvOverrides(){try{let e=runtimeGlobals().process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(A.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(A.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(A.runTimeout=r)}catch{}}const F=`\x1B[31m`,I=`\x1B[32m`,L=`\x1B[34m`,R=`\x1B[90m`,z=`\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 isStructurallyEqual(e,t){try{return i.deepStrictEqual(e,t),!0}catch{return!1}}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 stringifyForMessage(e){try{return JSON.stringify(e)??String(e)}catch{return formatValue(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 V=[],H=[];function envBag(){return globalThis.process?.env}const U={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;V.push({key:e,had:e in n,prev:n[e]}),n[e]=t},unstubAllGlobals(){let e=globalThis;for(let t=V.length-1;t>=0;t--){let n=V[t];n.had?e[n.key]=n.prev:delete e[n.key]}V.length=0},stubEnv(e,t){let n=envBag();n&&(H.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=H.length-1;t>=0;t--){let n=H[t];n.had?e[n.key]=n.prev:delete e[n.key]}H.length=0}}};var W=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,b===0?noteStrayFailure(t):noteThrownAssertion(e),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){let t=this.actualValue==e,n=``;!t&&isStructurallyEqual(this.actualValue,e)&&(n="\n The two values are structurally equal but are not the same reference.\n `toEqual` compares with `==` — use `toStrictEqual` for deep equality."),this.triggerResult(t,` Expected values to match using ==
|
|
3
3
|
Expected: ${formatValue(e)} (${typeof e})\n Actual: ${formatValue(this.actualValue)} (${typeof this.actualValue})${n}`)}toStrictEqual(e){let t=!0,n=``;try{i.deepStrictEqual(this.actualValue,e)}catch(e){t=!1,n=e.message||``}this.triggerResult(t,` Expected values to be deeply strictly equal
|
|
4
|
-
Expected: ${
|
|
4
|
+
Expected: ${stringifyForMessage(e)}\n Actual: ${stringifyForMessage(this.actualValue)}`+(n?`\n ${n}`:``))}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 t=this.mockCalls().some(t=>{try{return i.deepStrictEqual(t,e),!0}catch{return!1}});this.triggerResult(t,` 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,forgetThrownAssertion(a),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,forgetThrownAssertion(a),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,forgetThrownAssertion(n),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??
|
|
9
|
-
`+e);let i=
|
|
10
|
-
`),_=u[0]??s,v=c&&s instanceof TimeoutError&&u.length===0?`⏱`:`❌`;
|
|
11
|
-
`)[0]}${
|
|
12
|
-
`)[0]}${
|
|
13
|
-
`)[0])}`);return e.length>n&&r.push(`::error title=${escape(`${t}more failures`)}::${e.length-n} further failure(s) — see the ✖ recap in the log`),r},formatFailureRecap=(e,t,n=``)=>{let r=[`\n${
|
|
14
|
-
`)[0];r.push(` ${
|
|
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,forgetThrownAssertion(a),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,forgetThrownAssertion(a),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,forgetThrownAssertion(n),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??A.suiteTimeout;B(`
|
|
9
|
+
`+e);let i=D;D=e;let a=now();J.push({before:[],after:[]});try{await withTimeout(t,r,`describe: ${e}`)}catch(t){if(t instanceof TimeoutError)++m,k.push({suite:e,test:`<suite timed out>`,message:t.message}),B(` ${F}⏱ Suite timed out: ${t.message}${z}`);else throw t}finally{J.pop()}D=i;let o=now()-a;B(` ${R}↳ ${formatDuration(o)}${z}`)};describe.skip=async function(e,t){++h,B(`\n${L}- ${e} (skipped)${z}`)};const envVar=e=>{let t=runtimeGlobals().process?.env;if(t)return t[e];let n=runtimeGlobals().imports?.gi?.GLib;return n?n.getenv(e)??void 0:void 0},displayEnv=()=>({DISPLAY:envVar(`DISPLAY`),WAYLAND_DISPLAY:envVar(`WAYLAND_DISPLAY`)}),hasDisplay=()=>t(s(),displayEnv());let G;const registerGlProbe=e=>{G=e};let K,q=``;const realizeGlContext=async()=>{if(K!==void 0)return K;if(!G)return K=!1,q=`no on('Gl') prober registered — import '@gjsify/unit/gl' to use this axis`,K;let{ok:e,failure:t}=await G();return K=e,q=t,e||noteWarning(`on('Gl') skipped: a display exists but no GL context realizes — ${t}`),K},hasGl=()=>e(s(),displayEnv(),realizeGlContext),runtimeMatch=async function(e,t){if(e.includes(`Display`))return{matched:hasDisplay(),runtime:`Display`};if(e.includes(`Gl`))return{matched:await hasGl(),runtime:`Gl`};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,runtime:i}=await runtimeMatch(e,t);if(!r){++h;for(let t of e)++axisRecord(t).ignored;return}B(`\nOn ${e.join(`, `)}${t?` `+t:``}`);let a=d;await n();let o=axisRecord(i??e[0]);++o.matched,o.tests+=d-a},J=[{before:[],after:[]}],currentHookFrame=()=>J[J.length-1],beforeEach=function(e){typeof e==`function`&¤tHookFrame().before.push(e)},afterEach=function(e){typeof e==`function`&¤tHookFrame().after.push(e)},runBeforeEachHooks=async()=>{for(let e of J)for(let t of e.before)await t()},runAfterEachHooks=async()=>{for(let e=J.length-1;e>=0;--e){let t=J[e];for(let e=t.after.length-1;e>=0;--e)await t.after[e]()}},it=async function(e,t,n){let r=M.get(e);if(r!==void 0){++h,B(` ${L}-${z} ${R}${e} (skipped: ${r})${z}`);return}let i=typeof n==`number`?n:n?.timeout??A.testTimeout,a=now();++d,++b,O=e;let o=new Set;w.push(o);let s,c=!1;try{await runBeforeEachHooks(),j.noteInFlight(D?`${D} › ${e}`:e,i),await withTimeout(t,i,e)}catch(e){c=!0,s=e,e instanceof Error&&o.delete(e)}finally{try{await runAfterEachHooks()}catch(t){c?noteWarning(`afterEach also threw while "${e}" was already failing: ${errorMessage(t)}`):(c=!0,s=t,t instanceof Error&&o.delete(t))}--b,w.pop(),noteIfCwdDestroyed(e),j.noteSettled()}let l=now()-a,u=s instanceof TimeoutError?[...o]:[];if(!c){B(` ${I}✔${z} ${R}${e} (${formatDuration(l)})${z}`);return}++p;let m=[];c&&m.push(s?.message??String(s));for(let e of u)m.push(`${e.message}\n ${R}↳ thrown from a callback OUTSIDE this test's awaited chain, so it could not reach the test boundary. Reject the promise from that callback (or await a helper that does) to surface it directly.${z}`);let g=m.join(`
|
|
10
|
+
`),_=u[0]??s,v=c&&s instanceof TimeoutError&&u.length===0?`⏱`:`❌`;k.push({suite:D,test:e,message:g}),B(` ${F}${v}${z} ${R}${e} (${formatDuration(l)})${z}`),B(`${F}${g}${z}`),_?.stack&&B(_.stack)};it.skip=async function(e,t){++h,B(` ${L}-${z} ${R}${e} (skipped)${z}`)};const getTestCounters=()=>({assertions:u,tests:d,failed:p,failedOutsideTests:m,ignored:h,xfail:v,warnings:S.length}),getAxisLedger=()=>{let e={};for(let[t,n]of y)e[t]={...n};return e};it.failing=async function(e,t,n,r){let i=typeof r==`number`?r:r?.timeout??A.testTimeout;if(typeof r==`object`&&r?.when===!1)return it(e,t,{timeout:i});let a=now();++d,++b,w.push(new Set);let o=!1;try{await runBeforeEachHooks(),await withTimeout(t,i,e)}catch{o=!0}finally{try{await runAfterEachHooks()}catch(t){noteWarning(`afterEach threw after the expected failure "${e}": ${errorMessage(t)}`)}--b,w.pop()}let s=now()-a;if(o){++v,B(` ${L}✗${z} ${R}${e} (expected failure — ${n})${z}`);return}++p,k.push({suite:D,test:e,message:`it.failing("${e}") PASSED — the expected failure no longer happens, so this marker is stale and must be removed (turn it back into a plain it()). It was marked expected-failing because: ${n}`}),B(` ${F}❌${z} ${R}${e} (${formatDuration(s)})${z}`),B(`${F}it.failing passed unexpectedly — remove the marker. Reason it carried: ${n}${z}`)};const expect=function(e,t){return++u,new W(e,!0)},failAssertion=e=>{throw e.__testFailureCounted=!0,b===0?noteStrayFailure(e?.message??String(e)):noteThrownAssertion(e),e},assert=function(e,t){++u;try{i(e,t)}catch(e){failAssertion(e)}};assert.strictEqual=function(e,t,n){++u;try{i.strictEqual(e,t,n)}catch(e){failAssertion(e)}},assert.throws=function(e,...t){++u;let n;try{e()}catch(e){n=e}try{i.throws(()=>{if(n)throw n},t[0],t[1])}catch(e){failAssertion(e)}},assert.deepStrictEqual=function(e,t,n){++u;try{i.deepStrictEqual(e,t,n)}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)}},browserResultsFor=e=>({passed:e.run-e.failed,failed:e.failed+e.outside+ +!!e.bodyThrew,incomplete:e.bodyThrew,total:e.run,assertions:e.assertions,errors:e.bodyThrew?[...e.errors,{suite:`<suite body>`,test:`<run incomplete>`,message:e.bodyMessage}]:e.errors}),browserSignalDone=()=>{let e=runtimeGlobals(),t=e.document;t&&(e.__gjsify_test_results=browserResultsFor({run:d,failed:p,outside:m,assertions:u,errors:k,bodyThrew:g,bodyMessage:_}),t.documentElement.dataset.testsDone=`true`)},failUnexercisedAxes=async e=>{for(let t of e){let{matched:e}=await runtimeMatch([t]);if(!e)continue;let n=y.get(t);if(n&&n.tests>0)continue;++m;let r=`declared axis '${t}' ran on this host but exercised nothing — ${n?`${n.matched} gate(s) matched but executed no test, ${n.ignored} stood down`:`no on() gate named it`}`;k.push({suite:`<axis declaration>`,test:t,message:r}),B(`\n${F}❌ ${r}${z}`)}},failUnmetExpectedAxes=async()=>{let e=(envVar(`GJSIFY_TEST_EXPECT_AXES`)??``).split(`,`).map(e=>e.trim()).filter(Boolean);for(let t of e){if(!y.has(t))continue;let{matched:e}=await runtimeMatch([t]);if(e)continue;++m;let n=`axis '${t}' is expected on this host (GJSIFY_TEST_EXPECT_AXES) but stood down${t===`Gl`&&q?` — ${q}`:``}`;k.push({suite:`<axis expectation>`,test:t,message:n}),B(`\n${F}❌ ${n}${z}`)}},formatFailureVerdict=e=>{let t=[];if(e.failed&&t.push(`${e.failed} of ${e.tests} tests failed`),e.outside){let n=e.outside===1?``:`s`;t.push(e.failed?`${e.outside} failure${n} outside any test`:`${e.outside} failure${n} outside any test, ${e.tests} tests passed`)}return t.join(`, and `)},exitCodeFor=(e,t)=>e>0||t?1:0,flushed=e=>Promise.all(e.map(e=>new Promise(t=>e.write(``,()=>t())))).then(()=>void 0),printResult=()=>{let e=E>0?now()-E:0,t=e>0?` ${R}(${formatDuration(e)})`:``,n=T?`[${T}] `:``;if(h&&B(`\n${L}✔ ${h} ignored test${h>1?`s`:``}${z}`),y.size){B(`\n${L}⊞ axes exercised${z}`);for(let[e,t]of y)B(` ${L}↳ ${e}: ${t.tests} test${t.tests===1?``:`s`} from ${t.matched} gate${t.matched===1?``:`s`}${t.ignored?`, ${t.ignored} stood down`:``}${z}`)}if(v&&B(`\n${L}✗ ${v} expected failure${v>1?`s`:``} (it.failing — upstream defects)${z}`),S.length){B(`\n${L}⚠ ${S.length} warning${S.length>1?`s`:``} (not counted — nothing is claimed about these)${z}`);for(let e of S)B(` ${L}↳ ${e.message.trim().split(`
|
|
11
|
+
`)[0]}${z}`)}if(x.length){B(`\n${F}⚠ ${x.length} assertion${x.length>1?`s`:``} fired outside any it() (leaked from a settled test)${z}`);for(let e of x)B(` ${F}↳ ${e.message.trim().split(`
|
|
12
|
+
`)[0]}${z}`)}if(p||m){printFailureRecap(n);let e=formatFailureVerdict({failed:p,outside:m,tests:d});B(`\n${F}❌ ${n}${e}${countsSuffix()}${t}${z}`)}else B(g?`\n${F}❌ ${n}${d} test${d===1?``:`s`} passed, then a suite body threw — the run is INCOMPLETE${countsSuffix()}${t}${z}`:`\n${I}✔ ${n}${d} test${d===1?``:`s`} passed${countsSuffix()}${t}${z}`)},countsSuffix=()=>{let e=[`${u} assertion${u===1?``:`s`}`];return h&&e.push(`${h} ignored`),` ${R}· ${e.join(` · `)}${z}`},printFailureRecap=e=>{for(let t of formatFailureRecap(k,p+m,e))B(t);if(envVar(`GITHUB_ACTIONS`))for(let t of formatFailureAnnotations(k,e))B(t)},formatFailureAnnotations=(e,t=``,n=10)=>{let escape=e=>e.replace(/%/g,`%25`).replace(/\r/g,`%0D`).replace(/\n/g,`%0A`),r=e.slice(0,n).map(e=>`::error title=${escape(`${t}${e.suite} › ${e.test}`)}::${escape(e.message.trim().split(`
|
|
13
|
+
`)[0])}`);return e.length>n&&r.push(`::error title=${escape(`${t}more failures`)}::${e.length-n} further failure(s) — see the ✖ recap in the log`),r},formatFailureRecap=(e,t,n=``)=>{let r=[`\n${F}✖ ${n}failed test${e.length===1?``:`s`}${z}`];for(let t of e){let e=t.message.trim().split(`
|
|
14
|
+
`)[0];r.push(` ${F}✖ ${t.suite} › ${t.test}${z}${R} — ${e}${z}`)}return e.length!==t&&r.push(` ${F}✖ ${t} failure${t===1?``:`s`} counted but ${e.length} named — a failure path is raising the tally without recording itself, so this list is INCOMPLETE${z}`),r},Y={GJS:`Gjs`,"Node.js":`Node.js`,Bun:`Bun`,Deno:`Deno`},getRuntime=async()=>{if(T&&T!==`Unknown`)return T;let e=Y[a];return e?(T=o?`${e} ${o}`:e,T):runtimeGlobals().document===void 0?T||`Unknown`:(T=`Browser`,T)},printRuntime=async()=>{let e=await getRuntime();B(`\nRunning on ${e}`)},run=async(e,t)=>{applyEnvOverrides(),installUncaughtHooks(),E=now(),M=new Map,v=0,S.length=0,y.clear(),C=probeCwd(),g=!1,_=``;let n=[];if(t&&(typeof t==`number`?A.runTimeout=t:(t.timeout!==void 0&&(A.runTimeout=t.timeout),t.testTimeout!==void 0&&(A.testTimeout=t.testTimeout),t.suiteTimeout!==void 0&&(A.suiteTimeout=t.suiteTimeout),t.skip&&(M=new Map(Object.entries(t.skip))),t.requireAxes&&(n=t.requireAxes))),j=r(envBag(),A.runTimeout),printRuntime().then(async()=>{try{await withTimeout(()=>runTests(e),A.runTimeout,`entire test run`)}catch(e){if(e instanceof TimeoutError)B(`\n${F}⏱ ${e.message}${z}`),++m,k.push({suite:`<test run>`,test:`<run timed out>`,message:e.message});else throw e}}).then(()=>failUnexercisedAxes(n)).then(()=>failUnmetExpectedAxes()).catch(e=>{g=!0;let t=e instanceof Error?e.stack??e.message:String(e);_=`a suite body threw${D?` (in "${D}")`:``}: ${t}`,B(`\n${F}❌ a suite body threw, so the run is INCOMPLETE and every later suite was skipped${D?` (in "${D}")`:``} — ${t}${z}`)}).then(async()=>{if(printResult(),browserSignalDone(),B(),j.stop(),c(),l?.quit(),!l){let e=exitCodeFor(p+m,g);try{let t=globalThis.process||await import(`node:process`);await flushed([t.stdout,t.stderr]),t.exit(e)}catch{}}}),l?.run(),l){let e=exitCodeFor(p+m,g);runtimeGlobals().imports?.system?.exit(e)}};var X={run,assert,expect,it,afterEach,beforeEach,on,describe,configure,print:B,vi:U};export{afterEach,assert,beforeEach,browserResultsFor,configure,X as default,describe,exitCodeFor,expect,flushed,formatFailureAnnotations,formatFailureRecap,formatFailureVerdict,formatValue,getAxisLedger,getTestCounters,it,on,B as print,registerGlProbe,run,n as spy,U as vi};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
import '@girs/gjs';
|
|
2
|
+
import type GLib from '@girs/glib-2.0';
|
|
2
3
|
export * from './spy.js';
|
|
3
4
|
import nodeAssert from 'node:assert';
|
|
5
|
+
/**
|
|
6
|
+
* Typed view of the cross-runtime globals this runner reads. `@gjsify/unit` runs on plain GJS (no
|
|
7
|
+
* Node polyfills loaded), Node.js and browsers, so every `globalThis` access is potentially
|
|
8
|
+
* undefined; centralising the shapes keeps call sites on `runtimeGlobals().<field>?.…` instead of
|
|
9
|
+
* scattered `as any`.
|
|
10
|
+
*/
|
|
11
|
+
interface _RuntimeGlobals {
|
|
12
|
+
imports?: {
|
|
13
|
+
mainloop?: GLib.MainLoop;
|
|
14
|
+
gi?: {
|
|
15
|
+
GLib?: typeof GLib;
|
|
16
|
+
};
|
|
17
|
+
system?: {
|
|
18
|
+
exit: (code: number) => never;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
process?: {
|
|
22
|
+
env?: Partial<Record<string, string>>;
|
|
23
|
+
versions?: {
|
|
24
|
+
gjs?: string;
|
|
25
|
+
node?: string;
|
|
26
|
+
};
|
|
27
|
+
exit?: (code: number) => never;
|
|
28
|
+
cwd?: () => string;
|
|
29
|
+
on?: (event: string, listener: (error: unknown) => void) => unknown;
|
|
30
|
+
listenerCount?: (event: string) => number;
|
|
31
|
+
};
|
|
32
|
+
performance?: {
|
|
33
|
+
now?: () => number;
|
|
34
|
+
};
|
|
35
|
+
document?: {
|
|
36
|
+
documentElement: {
|
|
37
|
+
dataset: Record<string, string>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
__gjsify_test_results?: {
|
|
41
|
+
/** Tests that ran and did not fail. */
|
|
42
|
+
passed: number;
|
|
43
|
+
/** Failed tests, failures outside tests, and one more when the run is {@link incomplete}. */
|
|
44
|
+
failed: number;
|
|
45
|
+
/** A suite body threw, so later suites never started: `passed`/`total` describe a partial run. */
|
|
46
|
+
incomplete: boolean;
|
|
47
|
+
/** Tests that ran — NOT assertions, which is what this field used to carry (#1557). */
|
|
48
|
+
total: number;
|
|
49
|
+
/** Assertions executed, kept beside the total rather than instead of it. */
|
|
50
|
+
assertions: number;
|
|
51
|
+
errors: Array<{
|
|
52
|
+
suite: string;
|
|
53
|
+
test: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
4
58
|
/**
|
|
5
59
|
* What each `on()` gate actually DID, per axis it named.
|
|
6
60
|
*
|
|
@@ -188,6 +242,25 @@ export declare const assert: {
|
|
|
188
242
|
throws(promiseFn: () => unknown, args_0?: nodeAssert.AssertPredicate, args_1?: string): void;
|
|
189
243
|
deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
|
190
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* The object a browser harness reads from `window.__gjsify_test_results`, as a pure function of the
|
|
247
|
+
* tally. A browser has no exit code, so an INCOMPLETE run (a suite body threw) must be visible in
|
|
248
|
+
* the data itself: it counts as one failure and carries the throw, otherwise a harness asserting
|
|
249
|
+
* `failed === 0` passes a run that skipped most of its suites.
|
|
250
|
+
*/
|
|
251
|
+
export declare const browserResultsFor: (tally: {
|
|
252
|
+
run: number;
|
|
253
|
+
failed: number;
|
|
254
|
+
outside: number;
|
|
255
|
+
assertions: number;
|
|
256
|
+
errors: Array<{
|
|
257
|
+
suite: string;
|
|
258
|
+
test: string;
|
|
259
|
+
message: string;
|
|
260
|
+
}>;
|
|
261
|
+
bodyThrew: boolean;
|
|
262
|
+
bodyMessage: string;
|
|
263
|
+
}) => NonNullable<_RuntimeGlobals["__gjsify_test_results"]>;
|
|
191
264
|
/**
|
|
192
265
|
* The red summary's sentence: what failed, in terms that can be true together.
|
|
193
266
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/unit",
|
|
3
|
-
"version": "0.64.1-next.
|
|
3
|
+
"version": "0.64.1-next.244",
|
|
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",
|
|
@@ -57,22 +57,22 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@girs/gjs": "5.4.0",
|
|
59
59
|
"@girs/glib-2.0": "5.4.0",
|
|
60
|
-
"@gjsify/cli": "0.64.1-next.
|
|
60
|
+
"@gjsify/cli": "0.64.1-next.244",
|
|
61
61
|
"@types/node": "^25.9.2",
|
|
62
62
|
"typescript": "^6.0.3"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@gjsify/abort-controller": "0.64.1-next.
|
|
66
|
-
"@gjsify/assert": "0.64.1-next.
|
|
67
|
-
"@gjsify/buffer": "0.64.1-next.
|
|
68
|
-
"@gjsify/dom-elements": "0.64.1-next.
|
|
69
|
-
"@gjsify/dom-exception": "0.64.1-next.
|
|
70
|
-
"@gjsify/node-globals": "0.64.1-next.
|
|
71
|
-
"@gjsify/process": "0.64.1-next.
|
|
72
|
-
"@gjsify/runtime": "0.64.1-next.
|
|
73
|
-
"@gjsify/utils": "0.64.1-next.
|
|
74
|
-
"@gjsify/web-globals": "0.64.1-next.
|
|
75
|
-
"@gjsify/web-streams": "0.64.1-next.
|
|
65
|
+
"@gjsify/abort-controller": "0.64.1-next.244",
|
|
66
|
+
"@gjsify/assert": "0.64.1-next.244",
|
|
67
|
+
"@gjsify/buffer": "0.64.1-next.244",
|
|
68
|
+
"@gjsify/dom-elements": "0.64.1-next.244",
|
|
69
|
+
"@gjsify/dom-exception": "0.64.1-next.244",
|
|
70
|
+
"@gjsify/node-globals": "0.64.1-next.244",
|
|
71
|
+
"@gjsify/process": "0.64.1-next.244",
|
|
72
|
+
"@gjsify/runtime": "0.64.1-next.244",
|
|
73
|
+
"@gjsify/utils": "0.64.1-next.244",
|
|
74
|
+
"@gjsify/web-globals": "0.64.1-next.244",
|
|
75
|
+
"@gjsify/web-streams": "0.64.1-next.244"
|
|
76
76
|
},
|
|
77
77
|
"gjsify": {
|
|
78
78
|
"tier": 1,
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"win32": "supported"
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "9a6ca179c1a74477f23791c5b8f6d5a7bffaee61"
|
|
86
86
|
}
|