@gjsify/unit 0.0.4 → 0.1.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/README.md +45 -68
- package/lib/esm/index.js +293 -34
- package/lib/types/index.d.ts +55 -10
- package/package.json +16 -20
- package/src/index.spec.ts +47 -1
- package/src/index.ts +329 -33
- package/tsconfig.json +25 -7
- package/lib/cjs/index.js +0 -360
- package/lib/cjs/spy.js +0 -139
- package/test.gjs.mjs +0 -35597
- package/test.node.mjs +0 -1219
- package/tsconfig.types.json +0 -8
package/lib/types/index.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import "@girs/gjs";
|
|
2
2
|
export * from './spy.js';
|
|
3
|
+
export interface TimeoutConfig {
|
|
4
|
+
/** Per-it() timeout in ms. Default: 5000. 0 = disabled. */
|
|
5
|
+
testTimeout: number;
|
|
6
|
+
/** Per-describe() timeout in ms. Default: 30000. 0 = disabled. */
|
|
7
|
+
suiteTimeout: number;
|
|
8
|
+
/** Global run timeout in ms. Default: 120000. 0 = disabled. */
|
|
9
|
+
runTimeout: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const configure: (overrides: Partial<TimeoutConfig>) => void;
|
|
3
12
|
export interface Namespaces {
|
|
4
13
|
[key: string]: () => (Promise<void>) | Namespaces;
|
|
5
14
|
}
|
|
6
15
|
export type Callback = () => Promise<void>;
|
|
7
|
-
export type Runtime = 'Gjs' | 'Deno' | 'Node.js' | 'Unknown' | 'Browser';
|
|
16
|
+
export type Runtime = 'Gjs' | 'Deno' | 'Node.js' | 'Unknown' | 'Browser' | 'Display';
|
|
8
17
|
export declare const print: typeof globalThis.print;
|
|
9
18
|
declare class MatcherFactory {
|
|
10
19
|
protected readonly actualValue: any;
|
|
@@ -15,7 +24,10 @@ declare class MatcherFactory {
|
|
|
15
24
|
to(callback: (actualValue: any) => boolean): void;
|
|
16
25
|
toBe(expectedValue: any): void;
|
|
17
26
|
toEqual(expectedValue: any): void;
|
|
27
|
+
toStrictEqual(expectedValue: any): void;
|
|
18
28
|
toEqualArray(expectedValue: Array<any> | Uint8Array): void;
|
|
29
|
+
toBeInstanceOf(expectedType: Function): void;
|
|
30
|
+
toHaveLength(expectedLength: number): void;
|
|
19
31
|
toMatch(expectedValue: any): void;
|
|
20
32
|
toBeDefined(): void;
|
|
21
33
|
toBeUndefined(): void;
|
|
@@ -25,37 +37,70 @@ declare class MatcherFactory {
|
|
|
25
37
|
toContain(needle: any): void;
|
|
26
38
|
toBeLessThan(greaterValue: number): void;
|
|
27
39
|
toBeGreaterThan(smallerValue: number): void;
|
|
40
|
+
toBeGreaterThanOrEqual(value: number): void;
|
|
41
|
+
toBeLessThanOrEqual(value: number): void;
|
|
28
42
|
toBeCloseTo(expectedValue: number, precision: number): void;
|
|
29
|
-
toThrow(
|
|
43
|
+
toThrow(expected?: typeof Error | string | RegExp): void;
|
|
44
|
+
toReject(expected?: typeof Error | string | RegExp): Promise<void>;
|
|
45
|
+
toResolve(): Promise<void>;
|
|
30
46
|
}
|
|
31
|
-
export declare const describe:
|
|
47
|
+
export declare const describe: {
|
|
48
|
+
(moduleName: string, callback: Callback, options?: {
|
|
49
|
+
timeout?: number;
|
|
50
|
+
} | number): Promise<void>;
|
|
51
|
+
skip(moduleName: string, _callback?: Callback): Promise<void>;
|
|
52
|
+
};
|
|
32
53
|
/** E.g on('Deno', () { it(...) }) */
|
|
33
54
|
export declare const on: (onRuntime: Runtime | Runtime[], version: string | Callback, callback?: Callback) => Promise<void>;
|
|
34
55
|
export declare const beforeEach: (callback?: Callback) => void;
|
|
35
56
|
export declare const afterEach: (callback?: Callback) => void;
|
|
36
|
-
export declare const it:
|
|
57
|
+
export declare const it: {
|
|
58
|
+
(expectation: string, callback: () => void | Promise<void>, options?: {
|
|
59
|
+
timeout?: number;
|
|
60
|
+
} | number): Promise<void>;
|
|
61
|
+
skip(expectation: string, _callback?: () => void | Promise<void>): Promise<void>;
|
|
62
|
+
};
|
|
37
63
|
export declare const expect: (actualValue: any) => MatcherFactory;
|
|
38
64
|
export declare const assert: {
|
|
39
65
|
(success: any, message?: string | Error): void;
|
|
40
66
|
strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
|
41
67
|
throws(promiseFn: () => unknown, ...args: any[]): void;
|
|
42
|
-
deepStrictEqual<
|
|
68
|
+
deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
|
43
69
|
};
|
|
44
|
-
export declare const run: (namespaces: Namespaces
|
|
70
|
+
export declare const run: (namespaces: Namespaces, options?: {
|
|
71
|
+
timeout?: number;
|
|
72
|
+
testTimeout?: number;
|
|
73
|
+
suiteTimeout?: number;
|
|
74
|
+
} | number) => Promise<void>;
|
|
45
75
|
declare const _default: {
|
|
46
|
-
run: (namespaces: Namespaces
|
|
76
|
+
run: (namespaces: Namespaces, options?: {
|
|
77
|
+
timeout?: number;
|
|
78
|
+
testTimeout?: number;
|
|
79
|
+
suiteTimeout?: number;
|
|
80
|
+
} | number) => Promise<void>;
|
|
47
81
|
assert: {
|
|
48
82
|
(success: any, message?: string | Error): void;
|
|
49
83
|
strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
|
50
84
|
throws(promiseFn: () => unknown, ...args: any[]): void;
|
|
51
|
-
deepStrictEqual<
|
|
85
|
+
deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
|
52
86
|
};
|
|
53
87
|
expect: (actualValue: any) => MatcherFactory;
|
|
54
|
-
it:
|
|
88
|
+
it: {
|
|
89
|
+
(expectation: string, callback: () => void | Promise<void>, options?: {
|
|
90
|
+
timeout?: number;
|
|
91
|
+
} | number): Promise<void>;
|
|
92
|
+
skip(expectation: string, _callback?: () => void | Promise<void>): Promise<void>;
|
|
93
|
+
};
|
|
55
94
|
afterEach: (callback?: Callback) => void;
|
|
56
95
|
beforeEach: (callback?: Callback) => void;
|
|
57
96
|
on: (onRuntime: Runtime | Runtime[], version: string | Callback, callback?: Callback) => Promise<void>;
|
|
58
|
-
describe:
|
|
97
|
+
describe: {
|
|
98
|
+
(moduleName: string, callback: Callback, options?: {
|
|
99
|
+
timeout?: number;
|
|
100
|
+
} | number): Promise<void>;
|
|
101
|
+
skip(moduleName: string, _callback?: Callback): Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
configure: (overrides: Partial<TimeoutConfig>) => void;
|
|
59
104
|
print: typeof globalThis.print;
|
|
60
105
|
};
|
|
61
106
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/unit",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A BDD-style testing framework for Gjs",
|
|
5
|
-
"main": "lib/cjs/index.js",
|
|
6
5
|
"module": "lib/esm/index.js",
|
|
7
6
|
"types": "lib/types/index.d.ts",
|
|
8
7
|
"type": "module",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"default": "./lib/esm/index.js"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "./lib/types/index.d.ts",
|
|
17
|
-
"default": "./lib/cjs/index.js"
|
|
18
|
-
}
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/esm/index.js"
|
|
19
12
|
}
|
|
20
13
|
},
|
|
21
14
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"build": "yarn
|
|
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",
|
|
25
18
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
26
|
-
"build:types": "tsc
|
|
19
|
+
"build:types": "tsc",
|
|
27
20
|
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
28
21
|
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
29
22
|
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
30
|
-
"test": "yarn
|
|
23
|
+
"test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
31
24
|
"test:gjs": "gjs -m test.gjs.mjs",
|
|
32
25
|
"test:node": "node test.node.mjs"
|
|
33
26
|
},
|
|
@@ -48,12 +41,15 @@
|
|
|
48
41
|
},
|
|
49
42
|
"homepage": "https://github.com/gjsify/unit#readme",
|
|
50
43
|
"devDependencies": {
|
|
51
|
-
"@girs/gjs": "^
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
44
|
+
"@girs/gjs": "^4.0.0-beta.42",
|
|
45
|
+
"@girs/glib-2.0": "^2.88.0-4.0.0-beta.42",
|
|
46
|
+
"@gjsify/cli": "^0.1.0",
|
|
47
|
+
"@types/node": "^25.5.0",
|
|
48
|
+
"typescript": "^6.0.2"
|
|
54
49
|
},
|
|
55
50
|
"dependencies": {
|
|
56
|
-
"@gjsify/assert": "^0.0
|
|
57
|
-
"@gjsify/process": "^0.0
|
|
51
|
+
"@gjsify/assert": "^0.1.0",
|
|
52
|
+
"@gjsify/process": "^0.1.0",
|
|
53
|
+
"@gjsify/utils": "^0.1.0"
|
|
58
54
|
}
|
|
59
55
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, assert, beforeEach, afterEach } from '@gjsify/unit';
|
|
1
|
+
import { describe, it, expect, assert, beforeEach, afterEach, configure } from '@gjsify/unit';
|
|
2
2
|
|
|
3
3
|
export default async () => {
|
|
4
4
|
|
|
@@ -259,4 +259,50 @@ export default async () => {
|
|
|
259
259
|
expect(dontThrowException).not.toThrow();
|
|
260
260
|
});
|
|
261
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
|
+
});
|
|
262
308
|
}
|