@gjsify/unit 0.3.21 → 0.4.3

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.
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
package/lib/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 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=globalThis?.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=globalThis.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=()=>globalThis.performance?.now?.()??Date.now(),formatDuration=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,_=typeof globalThis.process?.versions?.gjs!=`string`&&globalThis.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 ===
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=globalThis?.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=globalThis.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=()=>globalThis.performance?.now?.()??Date.now(),formatDuration=e=>e>=1e3?`${(e/1e3).toFixed(2)}s`:e>=100?`${Math.round(e)}ms`:`${e.toFixed(1)}ms`,_=typeof globalThis.process?.versions?.gjs!=`string`&&globalThis.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 ==
package/lib/esm/spy.js CHANGED
@@ -1 +1 @@
1
- function spy(t){let n=[];function spy(...e){let r;try{r=t?t.apply(this,e):void 0}catch(t){throw n.push({type:`throw`,this:this,arguments:e,throw:t}),t}return n.push({type:`return`,this:this,arguments:e,return:r}),r}return Object.defineProperties(spy,{calls:e.calls(n),returnedCalls:e.returnedCalls,thrownCalls:e.thrownCalls,firstCall:e.firstCall,lastCall:e.lastCall,firstReturnedCall:e.firstReturnedCall,lastReturnedCall:e.lastReturnedCall,firstThrownCall:e.firstThrownCall,lastThrownCall:e.lastThrownCall,reset:e.reset,toString:e.toString(t)}),spy}const e={calls(e){return{value:e,configurable:!0}},returnedCalls:{get:function(){return this.calls.filter(isReturned)},configurable:!0},thrownCalls:{get:function(){return this.calls.filter(isThrown)},configurable:!0},firstCall:{get:function(){return this.calls[0]||null},configurable:!0},lastCall:{get:function(){return this.calls[this.calls.length-1]||null},configurable:!0},firstReturnedCall:{get:function(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(isReturned(t))return t}return null},configurable:!0},lastReturnedCall:{get:function(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(isReturned(t))return t}return null},configurable:!0},firstThrownCall:{get:function(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(isThrown(t))return t}return null},configurable:!0},lastThrownCall:{get:function(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(isThrown(t))return t}return null},configurable:!0},reset:{value:function(){this.calls.length=0},configurable:!0},toString(e){return{value:function(){return`/* The spy of */ ${e?e.toString():`function(){}`}`},configurable:!0}}};function isReturned(e){return e.type===`return`}function isThrown(e){return e.type===`throw`}export{spy};
1
+ import"./_virtual/_rolldown/runtime.js";function spy(t){let n=[];function spy(...e){let r;try{r=t?t.apply(this,e):void 0}catch(t){throw n.push({type:`throw`,this:this,arguments:e,throw:t}),t}return n.push({type:`return`,this:this,arguments:e,return:r}),r}return Object.defineProperties(spy,{calls:e.calls(n),returnedCalls:e.returnedCalls,thrownCalls:e.thrownCalls,firstCall:e.firstCall,lastCall:e.lastCall,firstReturnedCall:e.firstReturnedCall,lastReturnedCall:e.lastReturnedCall,firstThrownCall:e.firstThrownCall,lastThrownCall:e.lastThrownCall,reset:e.reset,toString:e.toString(t)}),spy}const e={calls(e){return{value:e,configurable:!0}},returnedCalls:{get:function returnedCalls(){return this.calls.filter(isReturned)},configurable:!0},thrownCalls:{get:function thrownCalls(){return this.calls.filter(isThrown)},configurable:!0},firstCall:{get:function firstCall(){return this.calls[0]||null},configurable:!0},lastCall:{get:function lastCall(){return this.calls[this.calls.length-1]||null},configurable:!0},firstReturnedCall:{get:function firstReturnedCall(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(isReturned(t))return t}return null},configurable:!0},lastReturnedCall:{get:function lastReturnedCall(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(isReturned(t))return t}return null},configurable:!0},firstThrownCall:{get:function firstThrownCall(){for(let e=0;e<this.calls.length;++e){let t=this.calls[e];if(isThrown(t))return t}return null},configurable:!0},lastThrownCall:{get:function lastThrownCall(){for(let e=this.calls.length-1;e>=0;--e){let t=this.calls[e];if(isThrown(t))return t}return null},configurable:!0},reset:{value:function reset(){this.calls.length=0},configurable:!0},toString(e){return{value:function toString(){return`/* The spy of */ ${e?e.toString():`function(){}`}`},configurable:!0}}};function isReturned(e){return e.type===`return`}function isThrown(e){return e.type===`throw`}export{spy};
package/package.json CHANGED
@@ -1,55 +1,65 @@
1
1
  {
2
- "name": "@gjsify/unit",
3
- "version": "0.3.21",
4
- "description": "A BDD-style testing framework for Gjs",
5
- "module": "lib/esm/index.js",
6
- "types": "lib/types/index.d.ts",
7
- "type": "module",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "default": "./lib/esm/index.js"
2
+ "name": "@gjsify/unit",
3
+ "version": "0.4.3",
4
+ "description": "A BDD-style testing framework for Gjs",
5
+ "module": "lib/esm/index.js",
6
+ "types": "lib/types/index.d.ts",
7
+ "files": [
8
+ "lib"
9
+ ],
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/esm/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
19
+ "check": "tsc --noEmit",
20
+ "build": "gjsify run build:gjsify && gjsify run build:types",
21
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
22
+ "build:types": "tsc",
23
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
24
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
25
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
26
+ "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
27
+ "test:gjs": "gjsify run test.gjs.mjs",
28
+ "test:node": "node test.node.mjs"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/gjsify/unit.git"
33
+ },
34
+ "keywords": [
35
+ "gjs",
36
+ "test",
37
+ "tdd",
38
+ "bdd"
39
+ ],
40
+ "author": "Philipp Hoffmann <mail@philipphoffmann.de>",
41
+ "license": "MIT",
42
+ "bugs": {
43
+ "url": "https://github.com/gjsify/unit/issues"
44
+ },
45
+ "homepage": "https://github.com/gjsify/unit#readme",
46
+ "devDependencies": {
47
+ "@girs/gjs": "4.0.0-rc.15",
48
+ "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
49
+ "@gjsify/cli": "workspace:^",
50
+ "@types/node": "^25.6.2",
51
+ "typescript": "^6.0.3"
52
+ },
53
+ "dependencies": {
54
+ "@gjsify/abort-controller": "workspace:^",
55
+ "@gjsify/assert": "workspace:^",
56
+ "@gjsify/buffer": "workspace:^",
57
+ "@gjsify/dom-elements": "workspace:^",
58
+ "@gjsify/dom-exception": "workspace:^",
59
+ "@gjsify/node-globals": "workspace:^",
60
+ "@gjsify/process": "workspace:^",
61
+ "@gjsify/utils": "workspace:^",
62
+ "@gjsify/web-globals": "workspace:^",
63
+ "@gjsify/web-streams": "workspace:^"
12
64
  }
13
- },
14
- "scripts": {
15
- "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
16
- "check": "tsc --noEmit",
17
- "build": "yarn build:gjsify && yarn build:types",
18
- "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
19
- "build:types": "tsc",
20
- "build:test": "yarn build:test:gjs && yarn build:test:node",
21
- "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
22
- "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
23
- "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
24
- "test:gjs": "gjsify run test.gjs.mjs",
25
- "test:node": "node test.node.mjs"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/gjsify/unit.git"
30
- },
31
- "keywords": [
32
- "gjs",
33
- "test",
34
- "tdd",
35
- "bdd"
36
- ],
37
- "author": "Philipp Hoffmann <mail@philipphoffmann.de>",
38
- "license": "MIT",
39
- "bugs": {
40
- "url": "https://github.com/gjsify/unit/issues"
41
- },
42
- "homepage": "https://github.com/gjsify/unit#readme",
43
- "devDependencies": {
44
- "@girs/gjs": "4.0.0-rc.14",
45
- "@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
46
- "@gjsify/cli": "^0.3.21",
47
- "@types/node": "^25.6.2",
48
- "typescript": "^6.0.3"
49
- },
50
- "dependencies": {
51
- "@gjsify/assert": "^0.3.21",
52
- "@gjsify/process": "^0.3.21",
53
- "@gjsify/utils": "^0.3.21"
54
- }
55
- }
65
+ }
package/src/index.spec.ts DELETED
@@ -1,308 +0,0 @@
1
- import { describe, it, expect, assert, beforeEach, afterEach, configure } from '@gjsify/unit';
2
-
3
- export default async () => {
4
-
5
- await describe('assert', async () => {
6
-
7
- await it('should consider truthy values as valid', async () => {
8
- assert(true);
9
- assert(1);
10
- assert({});
11
- assert([]);
12
- });
13
- })
14
-
15
- await describe('beforeEach', async () => {
16
-
17
- let foo = '';
18
- let count = 0;
19
- let countAfter = 0;
20
-
21
- beforeEach(async () => {
22
- console.log("beforeEach");
23
- foo = 'bar';
24
- ++count;
25
- });
26
-
27
- afterEach(async () => {
28
- console.log("afterEach");
29
- --countAfter;
30
- });
31
-
32
- await it('foo should be "bar"', async () => {
33
- expect(foo).toBe('bar');
34
- foo = 'override me again'
35
- });
36
-
37
- await it('foo should be "bar" again', async () => {
38
- expect(foo).toBe('bar');
39
- });
40
-
41
- await it('count should be 3 again', async () => {
42
- expect(count).toBe(3);
43
- });
44
-
45
- await it('countAfter should be -3', async () => {
46
- expect(countAfter).toBe(-3);
47
- });
48
- });
49
-
50
- await describe('expect::to', async () => {
51
- await it('should be possible to validate expectations by callback', async () => {
52
- expect(3).to(function(actualValue) {
53
- return actualValue === 3;
54
- });
55
- });
56
-
57
- await it('should be possible to invalidate expectations by callback', async () => {
58
- expect(3).not.to(function(actualValue) {
59
- return actualValue === 5;
60
- });
61
- });
62
- });
63
-
64
- await describe('expect::toBe', async () => {
65
- var obj = {};
66
- var obj2 = {};
67
-
68
- await it('should compare using ===', async () => {
69
- expect(true).toBe(true);
70
- expect(false).toBe(false);
71
- expect('test').toBe('test');
72
- expect(obj).toBe(obj);
73
- });
74
-
75
- await it('should compare using !==', async () => {
76
- expect(true).not.toBe(false);
77
- expect(true).not.toBe(1);
78
- expect(false).not.toBe(true);
79
- expect(false).not.toBe(0);
80
- expect('test').not.toBe('test2');
81
- expect(obj).not.toBe(obj2);
82
- });
83
- });
84
-
85
- await describe('expect::toEqual', async () => {
86
- var obj = {};
87
- var obj2 = {};
88
-
89
- await it('should compare using ==', async () => {
90
- expect(true).toEqual(true);
91
- expect(true).toEqual(1);
92
- expect(false).toEqual(false);
93
- expect(false).toEqual(0);
94
- expect('test').toEqual('test');
95
- expect(obj).toEqual(obj);
96
- });
97
-
98
- await it('should compare using !=', async () => {
99
- expect(true).not.toEqual(false);
100
- expect(false).not.toEqual(true);
101
- expect('test').not.toEqual('test2');
102
- expect(obj).not.toEqual(obj2);
103
- });
104
- });
105
-
106
- await describe('expect::toMatch', async () => {
107
- await it('should consider matching regular expressions as valid', async () => {
108
- expect('test').toMatch(/test/);
109
- expect('test').toMatch(/est/);
110
- expect('test').toMatch('test');
111
- });
112
-
113
- await it('should consider non matching regular expressions as invalid', async () => {
114
- expect('test').not.toMatch(/tester/);
115
- });
116
- });
117
-
118
- await describe('expect::toBeDefined', async () => {
119
- var obj = {key: 'value'};
120
-
121
- await it('should consider defined values as valid', async () => {
122
- expect(obj.key).toBeDefined();
123
- });
124
-
125
- await it('should consider undefined values as invalid', async () => {
126
- expect((obj as any).invalidKey).not.toBeDefined();
127
- });
128
- });
129
-
130
- await describe('expect::toBeUndefined', async () => {
131
- var obj = {key: 'value'};
132
-
133
- await it('should consider undefined values as valid', async () => {
134
- expect((obj as any).invalidKey).toBeUndefined();
135
- });
136
-
137
- await it('should consider defined values as invalid', async () => {
138
- expect(obj.key).not.toBeUndefined();
139
- });
140
- });
141
-
142
- await describe('expect::toBeNull', async () => {
143
- await it('should consider null values as valid', async () => {
144
- expect(null).toBeNull();
145
- });
146
-
147
- await it('should consider non null values as invalid', async () => {
148
- expect(0).not.toBeNull();
149
- expect(false).not.toBeNull();
150
- expect('').not.toBeNull();
151
- expect('null').not.toBeNull();
152
- expect(undefined).not.toBeNull();
153
- expect({}).not.toBeNull();
154
- });
155
- });
156
-
157
- await describe('expect::toBeTruthy', async () => {
158
- await it('should consider truthy values as valid', async () => {
159
- expect(true).toBeTruthy();
160
- expect(1).toBeTruthy();
161
- expect({}).toBeTruthy();
162
- expect([]).toBeTruthy();
163
- });
164
-
165
- await it('should consider non truthy values as invalid', async () => {
166
- expect(false).not.toBeTruthy();
167
- expect(0).not.toBeTruthy();
168
- expect('').not.toBeTruthy();
169
- expect(null).not.toBeTruthy();
170
- expect(undefined).not.toBeTruthy();
171
- });
172
- });
173
-
174
- await describe('expect::toBeFalsy', async () => {
175
- await it('should consider truthy values as valid', async () => {
176
- expect(false).toBeFalsy();
177
- expect(0).toBeFalsy();
178
- expect('').toBeFalsy();
179
- expect(null).toBeFalsy();
180
- expect(undefined).toBeFalsy();
181
- });
182
-
183
- await it('should consider non truthy values as invalid', async () => {
184
- expect(true).not.toBeFalsy();
185
- expect(1).not.toBeFalsy();
186
- expect({}).not.toBeFalsy();
187
- expect([]).not.toBeFalsy();
188
- });
189
- });
190
-
191
- await describe('expect::toContain', async () => {
192
- var testArray = [1, 'a'];
193
-
194
- await it('should consider array containing a value as valid', async () => {
195
- expect(testArray).toContain(1);
196
- expect(testArray).toContain('a');
197
- });
198
-
199
- await it('should consider arrays not containing a value as invalid', async () => {
200
- expect(testArray).not.toContain(0);
201
- expect(testArray).not.toContain('b');
202
- });
203
- });
204
-
205
- await describe('expect::toBeLessThan', async () => {
206
- await it('should consider greater values as valid', async () => {
207
- expect(1).toBeLessThan(2);
208
- expect(1).toBeLessThan(200);
209
- });
210
-
211
- await it('should consider equal values as invalid', async () => {
212
- expect(1).not.toBeLessThan(1);
213
- });
214
-
215
- await it('should consider smaller values as invalid', async () => {
216
- expect(1).not.toBeLessThan(0);
217
- expect(1).not.toBeLessThan(-5);
218
- });
219
- });
220
-
221
- await describe('expect::toBeGreaterThan', async () => {
222
- await it('should consider smaller values as valid', async () => {
223
- expect(2).toBeGreaterThan(1);
224
- expect(2).toBeGreaterThan(0);
225
- expect(2).toBeGreaterThan(-5);
226
- });
227
-
228
- await it('should consider equal values as invalid', async () => {
229
- expect(1).not.toBeGreaterThan(1);
230
- });
231
-
232
- await it('should consider greater values as invalid', async () => {
233
- expect(1).not.toBeGreaterThan(2);
234
- expect(1).not.toBeGreaterThan(200);
235
- });
236
- });
237
-
238
- await describe('expect::toBeCloseTo', async () => {
239
- var pi = 3.1415926, e = 2.78;
240
-
241
- await it('should consider close numbers as valid', async () => {
242
- expect(pi).toBeCloseTo(e, 0);
243
- });
244
-
245
- await it('should consider non close numbers as invalid', async () => {
246
- expect(pi).not.toBeCloseTo(e, 2);
247
- });
248
- });
249
-
250
- await describe('expect::toBeCloseTo', async () => {
251
- function throwException() { throw {}; }
252
- function dontThrowException() {}
253
-
254
- await it('should consider functions throwing an exception as valid', async () => {
255
- expect(throwException).toThrow();
256
- });
257
-
258
- await it('should consider functions not throwing an exception as invalid', async () => {
259
- expect(dontThrowException).not.toThrow();
260
- });
261
- });
262
-
263
- await describe('timeout::it', async () => {
264
-
265
- await it('should pass when test completes within timeout', async () => {
266
- await new Promise<void>(resolve => setTimeout(resolve, 10));
267
- expect(true).toBeTruthy();
268
- }, 1000);
269
-
270
- await it('should fail when test exceeds timeout', async () => {
271
- // This test verifies timeout detection by running a test that will timeout,
272
- // then checking that the failure was counted.
273
- const failedBefore = (globalThis as any).__testFailedCount;
274
-
275
- // We can't directly test that it() times out from within it() itself,
276
- // so we test that a fast test with a generous timeout succeeds.
277
- expect(true).toBeTruthy();
278
- }, 1000);
279
-
280
- await it('should accept timeout as options object', async () => {
281
- await new Promise<void>(resolve => setTimeout(resolve, 10));
282
- expect(true).toBeTruthy();
283
- }, { timeout: 1000 });
284
-
285
- await it('should accept timeout as number shorthand', async () => {
286
- await new Promise<void>(resolve => setTimeout(resolve, 10));
287
- expect(true).toBeTruthy();
288
- }, 1000);
289
- });
290
-
291
- await describe('timeout::configure', async () => {
292
-
293
- await it('should allow configuring default test timeout', async () => {
294
- // Save and restore config
295
- configure({ testTimeout: 2000 });
296
- // A fast test should still pass with 2s timeout
297
- expect(true).toBeTruthy();
298
- // Restore default
299
- configure({ testTimeout: 5000 });
300
- });
301
-
302
- await it('should allow disabling timeout with 0', async () => {
303
- // timeout: 0 means no timeout
304
- await new Promise<void>(resolve => setTimeout(resolve, 10));
305
- expect(true).toBeTruthy();
306
- }, 0);
307
- });
308
- }