@gjsify/unit 0.4.20 → 0.4.22
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 +2 -2
- package/package.json +15 -15
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 r=
|
|
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=``,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=runtimeGlobals().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=()=>runtimeGlobals().performance?.now?.()??Date.now(),formatDuration=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,_=typeof runtimeGlobals().process?.versions?.gjs!=`string`&&runtimeGlobals().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
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=
|
|
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=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}_(`\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=runtimeGlobals(),t=e.document;t&&(e.__gjsify_test_results={passed:i-a,failed:a,total:i,errors:u},t.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 runtimeGlobals().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{runtimeGlobals().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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/unit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.22",
|
|
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",
|
|
@@ -44,22 +44,22 @@
|
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://github.com/gjsify/unit#readme",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@girs/gjs": "4.0.
|
|
48
|
-
"@girs/glib-2.0": "2.88.0-4.0.
|
|
49
|
-
"@gjsify/cli": "^0.4.
|
|
50
|
-
"@types/node": "^25.
|
|
47
|
+
"@girs/gjs": "4.0.1",
|
|
48
|
+
"@girs/glib-2.0": "2.88.0-4.0.1",
|
|
49
|
+
"@gjsify/cli": "^0.4.22",
|
|
50
|
+
"@types/node": "^25.9.1",
|
|
51
51
|
"typescript": "^6.0.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@gjsify/abort-controller": "^0.4.
|
|
55
|
-
"@gjsify/assert": "^0.4.
|
|
56
|
-
"@gjsify/buffer": "^0.4.
|
|
57
|
-
"@gjsify/dom-elements": "^0.4.
|
|
58
|
-
"@gjsify/dom-exception": "^0.4.
|
|
59
|
-
"@gjsify/node-globals": "^0.4.
|
|
60
|
-
"@gjsify/process": "^0.4.
|
|
61
|
-
"@gjsify/utils": "^0.4.
|
|
62
|
-
"@gjsify/web-globals": "^0.4.
|
|
63
|
-
"@gjsify/web-streams": "^0.4.
|
|
54
|
+
"@gjsify/abort-controller": "^0.4.22",
|
|
55
|
+
"@gjsify/assert": "^0.4.22",
|
|
56
|
+
"@gjsify/buffer": "^0.4.22",
|
|
57
|
+
"@gjsify/dom-elements": "^0.4.22",
|
|
58
|
+
"@gjsify/dom-exception": "^0.4.22",
|
|
59
|
+
"@gjsify/node-globals": "^0.4.22",
|
|
60
|
+
"@gjsify/process": "^0.4.22",
|
|
61
|
+
"@gjsify/utils": "^0.4.22",
|
|
62
|
+
"@gjsify/web-globals": "^0.4.22",
|
|
63
|
+
"@gjsify/web-streams": "^0.4.22"
|
|
64
64
|
}
|
|
65
65
|
}
|