@gjsify/unit 0.4.27 → 0.4.29
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 +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/spy.d.ts +2 -2
- package/package.json +12 -12
package/lib/esm/index.js
CHANGED
|
@@ -5,4 +5,4 @@ import"./_virtual/_rolldown/runtime.js";import{spy as e}from"./spy.js";import"@g
|
|
|
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=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};
|
|
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(`node: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(`node: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/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@girs/gjs';
|
|
2
2
|
export * from './spy.js';
|
|
3
3
|
export interface TimeoutConfig {
|
|
4
4
|
/** Per-it() timeout in ms. Default: 5000. 0 = disabled. */
|
|
@@ -10,7 +10,7 @@ export interface TimeoutConfig {
|
|
|
10
10
|
}
|
|
11
11
|
export declare const configure: (overrides: Partial<TimeoutConfig>) => void;
|
|
12
12
|
export interface Namespaces {
|
|
13
|
-
[key: string]: () =>
|
|
13
|
+
[key: string]: () => Promise<void> | Namespaces;
|
|
14
14
|
}
|
|
15
15
|
export type Callback = () => Promise<void>;
|
|
16
16
|
export type Runtime = 'Gjs' | 'Deno' | 'Node.js' | 'Unknown' | 'Browser' | 'Display';
|
package/lib/types/spy.d.ts
CHANGED
|
@@ -28,14 +28,14 @@ export declare namespace Spy {
|
|
|
28
28
|
type Call<T extends (...args: any[]) => any> = ReturnedCall<T> | ThrownCall<T>;
|
|
29
29
|
/** Information for each returned call. */
|
|
30
30
|
interface ReturnedCall<T extends (...args: any[]) => any> {
|
|
31
|
-
type:
|
|
31
|
+
type: 'return';
|
|
32
32
|
this: This<T>;
|
|
33
33
|
arguments: Parameters<T>;
|
|
34
34
|
return: ReturnType<T>;
|
|
35
35
|
}
|
|
36
36
|
/** Information for each thrown call. */
|
|
37
37
|
interface ThrownCall<T extends (...args: any[]) => any> {
|
|
38
|
-
type:
|
|
38
|
+
type: 'throw';
|
|
39
39
|
this: This<T>;
|
|
40
40
|
arguments: Parameters<T>;
|
|
41
41
|
throw: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/unit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.29",
|
|
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,20 +46,20 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@girs/gjs": "4.0.1",
|
|
48
48
|
"@girs/glib-2.0": "2.88.0-4.0.1",
|
|
49
|
-
"@gjsify/cli": "^0.4.
|
|
49
|
+
"@gjsify/cli": "^0.4.29",
|
|
50
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.29",
|
|
55
|
+
"@gjsify/assert": "^0.4.29",
|
|
56
|
+
"@gjsify/buffer": "^0.4.29",
|
|
57
|
+
"@gjsify/dom-elements": "^0.4.29",
|
|
58
|
+
"@gjsify/dom-exception": "^0.4.29",
|
|
59
|
+
"@gjsify/node-globals": "^0.4.29",
|
|
60
|
+
"@gjsify/process": "^0.4.29",
|
|
61
|
+
"@gjsify/utils": "^0.4.29",
|
|
62
|
+
"@gjsify/web-globals": "^0.4.29",
|
|
63
|
+
"@gjsify/web-streams": "^0.4.29"
|
|
64
64
|
}
|
|
65
65
|
}
|