@gjsify/unit 0.28.0 → 0.29.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 +3 -3
- package/lib/types/index.d.ts +0 -7
- package/package.json +12 -12
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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,c=0;const l=[],u=[],noteWarning=e=>{u.push({suite:h,message:e})},noteStrayFailure=e=>{++a,l.push({suite:h,message:e}),_.push({suite:h,test:`<stray assertion outside any it()>`,message:e})},d=[],noteThrownAssertion=e=>{let t=d[d.length-1];t&&e instanceof Error&&t.add(e)},forgetThrownAssertion=e=>{if(e instanceof Error)for(let t of d)t.delete(e)};let p=``,m=0,h=``,g=``,_=[],v={testTimeout:5e3,suiteTimeout:3e4,runTimeout:12e4},y=new Map;var TimeoutError=class extends Error{constructor(e,t){super(`Timeout: "${e}" exceeded ${t}ms`),this.name=`TimeoutError`}};const b=[];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(()=>{}),b.push(a);try{let t=Promise.resolve(e());return t.catch(()=>{}),await Promise.race([t,i,o])}finally{clearTimeout(r);let e=b.lastIndexOf(a);e!==-1&&b.splice(e,1)}}let x=!1;const installUncaughtHooks=()=>{if(x)return;let e=runtimeGlobals().process;if(typeof e?.on!=`function`||typeof e.versions?.gjs==`string`)return;x=!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=c>0?` during "${g}"`:``;noteWarning(`${t}: ${e}${r} — absorbed by a listener the spec installed itself`);return}let a=b[b.length-1];a?a(n):noteStrayFailure(n?.message??String(n))};e.on(`uncaughtException`,handle(`uncaughtException`)),e.on(`unhandledRejection`,handle(`unhandledRejection`))},configure=e=>{v={...v,...e}};function applyEnvOverrides(){try{let e=runtimeGlobals().process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(v.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(v.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(v.runTimeout=r)}catch{}}const S=`\x1B[31m`,C=`\x1B[32m`,w=`\x1B[34m`,T=`\x1B[90m`,E=`\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`,D=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 O=[],k=[];function envBag(){return globalThis.process?.env}const A={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;O.push({key:e,had:e in n,prev:n[e]}),n[e]=t},unstubAllGlobals(){let e=globalThis;for(let t=O.length-1;t>=0;t--){let n=O[t];n.had?e[n.key]=n.prev:delete e[n.key]}O.length=0},stubEnv(e,t){let n=envBag();n&&(k.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=k.length-1;t>=0;t--){let n=k[t];n.had?e[n.key]=n.prev:delete e[n.key]}k.length=0}}};var j=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,c===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
|
-
Expected: ${formatValue(e)} (${typeof e})\n Actual: ${formatValue(this.actualValue)} (${typeof this.actualValue})`)}toEqual(e){this.
|
|
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
|
|
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,c=0;const l=[],u=[],noteWarning=e=>{u.push({suite:h,message:e})},noteStrayFailure=e=>{++a,l.push({suite:h,message:e}),_.push({suite:h,test:`<stray assertion outside any it()>`,message:e})},d=[],noteThrownAssertion=e=>{let t=d[d.length-1];t&&e instanceof Error&&t.add(e)},forgetThrownAssertion=e=>{if(e instanceof Error)for(let t of d)t.delete(e)};let p=``,m=0,h=``,g=``,_=[],v={testTimeout:5e3,suiteTimeout:3e4,runTimeout:12e4},y=new Map;var TimeoutError=class extends Error{constructor(e,t){super(`Timeout: "${e}" exceeded ${t}ms`),this.name=`TimeoutError`}};const b=[];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(()=>{}),b.push(a);try{let t=Promise.resolve(e());return t.catch(()=>{}),await Promise.race([t,i,o])}finally{clearTimeout(r);let e=b.lastIndexOf(a);e!==-1&&b.splice(e,1)}}let x=!1;const installUncaughtHooks=()=>{if(x)return;let e=runtimeGlobals().process;if(typeof e?.on!=`function`||typeof e.versions?.gjs==`string`)return;x=!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=c>0?` during "${g}"`:``;noteWarning(`${t}: ${e}${r} — absorbed by a listener the spec installed itself`);return}let a=b[b.length-1];a?a(n):noteStrayFailure(n?.message??String(n))};e.on(`uncaughtException`,handle(`uncaughtException`)),e.on(`unhandledRejection`,handle(`unhandledRejection`))},configure=e=>{v={...v,...e}};function applyEnvOverrides(){try{let e=runtimeGlobals().process?.env;if(!e)return;let t=parseInt(e.GJSIFY_TEST_TIMEOUT,10);!isNaN(t)&&t>=0&&(v.testTimeout=t);let n=parseInt(e.GJSIFY_SUITE_TIMEOUT,10);!isNaN(n)&&n>=0&&(v.suiteTimeout=n);let r=parseInt(e.GJSIFY_RUN_TIMEOUT,10);!isNaN(r)&&r>=0&&(v.runTimeout=r)}catch{}}const S=`\x1B[31m`,C=`\x1B[32m`,w=`\x1B[34m`,T=`\x1B[90m`,E=`\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`,D=typeof runtimeGlobals().process?.versions?.gjs!=`string`&&runtimeGlobals().document!==void 0?console.log:globalThis.print||console.log;function isStructurallyEqual(e,n){try{return t.deepStrictEqual(e,n),!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 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 O=[],k=[];function envBag(){return globalThis.process?.env}const A={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;O.push({key:e,had:e in n,prev:n[e]}),n[e]=t},unstubAllGlobals(){let e=globalThis;for(let t=O.length-1;t>=0;t--){let n=O[t];n.had?e[n.key]=n.prev:delete e[n.key]}O.length=0},stubEnv(e,t){let n=envBag();n&&(k.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=k.length-1;t>=0;t--){let n=k[t];n.had?e[n.key]=n.prev:delete e[n.key]}k.length=0}}};var j=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,c===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
|
+
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
|
+
Expected: ${formatValue(e)} (${typeof e})\n Actual: ${formatValue(this.actualValue)} (${typeof this.actualValue})${n}`)}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
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,13 +16,6 @@ export interface Namespaces {
|
|
|
16
16
|
export type Callback = () => void | Promise<void>;
|
|
17
17
|
export type Runtime = 'Gjs' | 'Deno' | 'Node.js' | 'Unknown' | 'Browser' | 'Display';
|
|
18
18
|
export declare const print: (...data: any[]) => void;
|
|
19
|
-
/**
|
|
20
|
-
* Render any value as a human-readable string for assertion failure messages
|
|
21
|
-
* WITHOUT throwing. Template-literal / `+` interpolation throws a TypeError on
|
|
22
|
-
* `symbol` and `bigint` operands (`Cannot convert a Symbol value to a string`),
|
|
23
|
-
* which would mask the real assertion result, so matchers route operands
|
|
24
|
-
* through this instead of interpolating them directly.
|
|
25
|
-
*/
|
|
26
19
|
export declare function formatValue(value: unknown): string;
|
|
27
20
|
type AnyFn = (...args: any[]) => any;
|
|
28
21
|
/** A vitest-style mock function: callable with any args + records `.mock.calls`. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/unit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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",
|
|
@@ -49,21 +49,21 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@girs/gjs": "^4.1.0",
|
|
51
51
|
"@girs/glib-2.0": "^4.1.0",
|
|
52
|
-
"@gjsify/cli": "^0.
|
|
52
|
+
"@gjsify/cli": "^0.29.0",
|
|
53
53
|
"@types/node": "^25.9.2",
|
|
54
54
|
"typescript": "^6.0.3"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@gjsify/abort-controller": "^0.
|
|
58
|
-
"@gjsify/assert": "^0.
|
|
59
|
-
"@gjsify/buffer": "^0.
|
|
60
|
-
"@gjsify/dom-elements": "^0.
|
|
61
|
-
"@gjsify/dom-exception": "^0.
|
|
62
|
-
"@gjsify/node-globals": "^0.
|
|
63
|
-
"@gjsify/process": "^0.
|
|
64
|
-
"@gjsify/utils": "^0.
|
|
65
|
-
"@gjsify/web-globals": "^0.
|
|
66
|
-
"@gjsify/web-streams": "^0.
|
|
57
|
+
"@gjsify/abort-controller": "^0.29.0",
|
|
58
|
+
"@gjsify/assert": "^0.29.0",
|
|
59
|
+
"@gjsify/buffer": "^0.29.0",
|
|
60
|
+
"@gjsify/dom-elements": "^0.29.0",
|
|
61
|
+
"@gjsify/dom-exception": "^0.29.0",
|
|
62
|
+
"@gjsify/node-globals": "^0.29.0",
|
|
63
|
+
"@gjsify/process": "^0.29.0",
|
|
64
|
+
"@gjsify/utils": "^0.29.0",
|
|
65
|
+
"@gjsify/web-globals": "^0.29.0",
|
|
66
|
+
"@gjsify/web-streams": "^0.29.0"
|
|
67
67
|
},
|
|
68
68
|
"gjsify": {
|
|
69
69
|
"tier": 1
|