@omnitron-dev/testing 0.4.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/LICENSE +21 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/bun-adapter.d.ts +1 -0
- package/dist/runtime/bun-adapter.js +90 -0
- package/dist/runtime/bun-adapter.js.map +1 -0
- package/dist/runtime/deno-adapter.d.ts +26 -0
- package/dist/runtime/deno-adapter.js +208 -0
- package/dist/runtime/deno-adapter.js.map +1 -0
- package/dist/runtime/node-adapter.d.ts +16 -0
- package/dist/runtime/node-adapter.js +30 -0
- package/dist/runtime/node-adapter.js.map +1 -0
- package/dist/runtime/test-adapter.d.ts +22 -0
- package/dist/runtime/test-adapter.js +95 -0
- package/dist/runtime/test-adapter.js.map +1 -0
- package/package.json +97 -0
- package/runtime/bun.d.ts +2 -0
- package/runtime/bun.js +5 -0
- package/runtime/bun.ts +7 -0
- package/runtime/deno.d.ts +2 -0
- package/runtime/deno.js +4 -0
- package/runtime/jest.d.ts +2 -0
- package/runtime/jest.js +16 -0
- package/runtime/jest.ts +7 -0
- package/src/globals.d.ts +24 -0
- package/src/index.ts +41 -0
- package/src/runtime/bun-adapter.ts +117 -0
- package/src/runtime/deno-adapter.ts +272 -0
- package/src/runtime/node-adapter.ts +40 -0
- package/src/runtime/test-adapter.test.ts +98 -0
- package/src/runtime/test-adapter.ts +124 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LuxQuant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './runtime/test-adapter.js';
|
|
2
|
+
export { RUNTIME } from './runtime/test-adapter.js';
|
|
3
|
+
export type MockFunction<T extends (...args: any[]) => any> = T & {
|
|
4
|
+
mock: {
|
|
5
|
+
calls: Parameters<T>[];
|
|
6
|
+
results: ReturnType<T>[];
|
|
7
|
+
lastCall: () => Parameters<T> | undefined;
|
|
8
|
+
};
|
|
9
|
+
mockImplementation: (impl: T) => MockFunction<T>;
|
|
10
|
+
mockReturnValue: (value: ReturnType<T>) => MockFunction<T>;
|
|
11
|
+
mockResolvedValue: (value: Awaited<ReturnType<T>>) => MockFunction<T>;
|
|
12
|
+
mockRejectedValue: (value: any) => MockFunction<T>;
|
|
13
|
+
mockClear: () => void;
|
|
14
|
+
mockReset: () => void;
|
|
15
|
+
};
|
|
16
|
+
export declare function loadRuntimeAdapter(): Promise<typeof import("./runtime/bun-adapter.js")>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './runtime/test-adapter.js';
|
|
2
|
+
export { RUNTIME } from './runtime/test-adapter.js';
|
|
3
|
+
export function loadRuntimeAdapter() {
|
|
4
|
+
const runtime = (() => {
|
|
5
|
+
if (typeof globalThis.Bun !== 'undefined')
|
|
6
|
+
return 'bun';
|
|
7
|
+
if (typeof globalThis.Deno !== 'undefined')
|
|
8
|
+
return 'deno';
|
|
9
|
+
return 'node';
|
|
10
|
+
})();
|
|
11
|
+
switch (runtime) {
|
|
12
|
+
case 'bun':
|
|
13
|
+
return import('./runtime/bun-adapter.js');
|
|
14
|
+
case 'deno':
|
|
15
|
+
return import('./runtime/deno-adapter.js');
|
|
16
|
+
default:
|
|
17
|
+
return import('./runtime/node-adapter.js');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAkBpD,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE;QACpB,IAAI,OAAQ,UAAkB,CAAC,GAAG,KAAK,WAAW;YAAE,OAAO,KAAK,CAAC;QACjE,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO,MAAM,CAAC;QACnE,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,CAAC;IAEL,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,KAAK;YACR,OAAO,MAAM,CAAC,0BAA0B,CAAC,CAAC;QAC5C,KAAK,MAAM;YACT,OAAO,MAAM,CAAC,2BAA2B,CAAC,CAAC;QAC7C;YACE,OAAO,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { mock, test as bunTest, expect as bunExpect, describe as bunDescribe, afterAll as bunAfterAll, afterEach as bunAfterEach, beforeAll as bunBeforeAll, beforeEach as bunBeforeEach, } from 'bun:test';
|
|
2
|
+
import { timerUtils } from './test-adapter.js';
|
|
3
|
+
global.describe = bunDescribe;
|
|
4
|
+
global.test = bunTest;
|
|
5
|
+
global.it = bunTest;
|
|
6
|
+
global.expect = bunExpect;
|
|
7
|
+
global.beforeEach = bunBeforeEach;
|
|
8
|
+
global.afterEach = bunAfterEach;
|
|
9
|
+
global.beforeAll = bunBeforeAll;
|
|
10
|
+
global.afterAll = bunAfterAll;
|
|
11
|
+
const fakeTimers = {
|
|
12
|
+
useFakeTimers: () => {
|
|
13
|
+
timerUtils.useFakeTimers();
|
|
14
|
+
return fakeTimers;
|
|
15
|
+
},
|
|
16
|
+
useRealTimers: () => {
|
|
17
|
+
timerUtils.useRealTimers();
|
|
18
|
+
return fakeTimers;
|
|
19
|
+
},
|
|
20
|
+
advanceTimersByTime: (ms) => {
|
|
21
|
+
timerUtils.advanceTimersByTime(ms);
|
|
22
|
+
},
|
|
23
|
+
runAllTimers: () => {
|
|
24
|
+
timerUtils.runAllTimers();
|
|
25
|
+
},
|
|
26
|
+
clearAllTimers: () => {
|
|
27
|
+
timerUtils.clearAllTimers();
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
global.jest = {
|
|
31
|
+
fn: mock,
|
|
32
|
+
mock,
|
|
33
|
+
useFakeTimers: fakeTimers.useFakeTimers,
|
|
34
|
+
useRealTimers: fakeTimers.useRealTimers,
|
|
35
|
+
advanceTimersByTime: fakeTimers.advanceTimersByTime,
|
|
36
|
+
runAllTimers: fakeTimers.runAllTimers,
|
|
37
|
+
clearAllTimers: fakeTimers.clearAllTimers,
|
|
38
|
+
};
|
|
39
|
+
const originalExpect = bunExpect;
|
|
40
|
+
if (!originalExpect.toBeInstanceOf) {
|
|
41
|
+
originalExpect.extend({
|
|
42
|
+
toBeInstanceOf(received, constructor) {
|
|
43
|
+
const pass = received instanceof constructor;
|
|
44
|
+
return {
|
|
45
|
+
pass,
|
|
46
|
+
message: () => pass
|
|
47
|
+
? `expected ${received} not to be instance of ${constructor.name}`
|
|
48
|
+
: `expected ${received} to be instance of ${constructor.name}`,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (!originalExpect.toStrictEqual) {
|
|
54
|
+
originalExpect.toStrictEqual = originalExpect.toEqual;
|
|
55
|
+
}
|
|
56
|
+
if (!originalExpect.toThrowError) {
|
|
57
|
+
originalExpect.extend({
|
|
58
|
+
toThrowError(received, expected) {
|
|
59
|
+
let error;
|
|
60
|
+
let pass = false;
|
|
61
|
+
try {
|
|
62
|
+
if (typeof received === 'function') {
|
|
63
|
+
received();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
error = e;
|
|
68
|
+
pass = true;
|
|
69
|
+
if (expected !== undefined) {
|
|
70
|
+
if (typeof expected === 'string') {
|
|
71
|
+
pass = error.message.includes(expected);
|
|
72
|
+
}
|
|
73
|
+
else if (expected instanceof RegExp) {
|
|
74
|
+
pass = expected.test(error.message);
|
|
75
|
+
}
|
|
76
|
+
else if (typeof expected === 'function') {
|
|
77
|
+
pass = error instanceof expected;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
pass,
|
|
83
|
+
message: () => pass
|
|
84
|
+
? `expected function not to throw${expected ? ` ${expected}` : ''}`
|
|
85
|
+
: `expected function to throw${expected ? ` ${expected}` : ''}`,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=bun-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun-adapter.js","sourceRoot":"","sources":["../../src/runtime/bun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AG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBAC1C,CAAC;yBAAM,IAAI,QAAQ,YAAY,MAAM,EAAE,CAAC;wBACtC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;oBACtC,CAAC;yBAAM,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;wBAC1C,IAAI,GAAG,KAAK,YAAY,QAAQ,CAAC;oBACnC,CAAC;gBACH,CAAC;YACH,CAAC;YAED,OAAO;gBACL,IAAI;gBACJ,OAAO,EAAE,GAAG,EAAE,CACZ,IAAI;oBACF,CAAC,CAAC,iCAAiC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;oBACnE,CAAC,CAAC,6BAA6B,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;aACpE,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare function inherits(ctor: any, superCtor: any): void;
|
|
2
|
+
declare function describe(name: string, fn: () => void): void;
|
|
3
|
+
declare function it(name: string, fn: () => void | Promise<void>): void;
|
|
4
|
+
declare function beforeEach(fn: () => void | Promise<void>): void;
|
|
5
|
+
declare function afterEach(fn: () => void | Promise<void>): void;
|
|
6
|
+
declare function beforeAll(fn: () => void | Promise<void>): void;
|
|
7
|
+
declare function afterAll(fn: () => void | Promise<void>): void;
|
|
8
|
+
declare function mockFn(implementation?: (...args: any[]) => any): {
|
|
9
|
+
(...args: any[]): any;
|
|
10
|
+
mock: {
|
|
11
|
+
calls: any[][];
|
|
12
|
+
results: any[];
|
|
13
|
+
lastCall: () => any[] | undefined;
|
|
14
|
+
};
|
|
15
|
+
mockImplementation(impl: (...args: any[]) => any): any;
|
|
16
|
+
mockReturnValue(value: any): any;
|
|
17
|
+
mockResolvedValue(value: any): any;
|
|
18
|
+
mockRejectedValue(value: any): any;
|
|
19
|
+
mockClear(): void;
|
|
20
|
+
mockReset(): void;
|
|
21
|
+
};
|
|
22
|
+
declare const expect: {
|
|
23
|
+
(value: any): any;
|
|
24
|
+
extend(matchers: Record<string, any>): void;
|
|
25
|
+
};
|
|
26
|
+
export { it, expect, mockFn, describe, afterAll, inherits, afterEach, beforeAll, beforeEach };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { FakeTime } from 'https://deno.land/std@0.208.0/testing/time.ts';
|
|
2
|
+
import { expect as denoExpect } from 'https://deno.land/x/expect@v0.3.0/mod.ts';
|
|
3
|
+
import { it as denoIt, describe as denoDescribe } from 'https://deno.land/std@0.208.0/testing/bdd.ts';
|
|
4
|
+
function inherits(ctor, superCtor) {
|
|
5
|
+
if (ctor === undefined || ctor === null) {
|
|
6
|
+
throw new TypeError('The constructor to "inherits" must not be null or undefined');
|
|
7
|
+
}
|
|
8
|
+
if (superCtor === undefined || superCtor === null) {
|
|
9
|
+
throw new TypeError('The super constructor to "inherits" must not be null or undefined');
|
|
10
|
+
}
|
|
11
|
+
if (superCtor.prototype === undefined) {
|
|
12
|
+
throw new TypeError('The super constructor to "inherits" must have a prototype property');
|
|
13
|
+
}
|
|
14
|
+
ctor.super_ = superCtor;
|
|
15
|
+
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
|
|
16
|
+
}
|
|
17
|
+
let fakeTime = null;
|
|
18
|
+
const beforeEachCallbacks = [];
|
|
19
|
+
const afterEachCallbacks = [];
|
|
20
|
+
const beforeAllCallbacks = [];
|
|
21
|
+
const afterAllCallbacks = [];
|
|
22
|
+
function describe(name, fn) {
|
|
23
|
+
denoDescribe(name, () => {
|
|
24
|
+
const localBeforeAll = [...beforeAllCallbacks];
|
|
25
|
+
const localAfterAll = [...afterAllCallbacks];
|
|
26
|
+
if (localBeforeAll.length > 0) {
|
|
27
|
+
denoIt('beforeAll', async () => {
|
|
28
|
+
for (const cb of localBeforeAll) {
|
|
29
|
+
await cb();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
fn();
|
|
34
|
+
if (localAfterAll.length > 0) {
|
|
35
|
+
denoIt('afterAll', async () => {
|
|
36
|
+
for (const cb of localAfterAll) {
|
|
37
|
+
await cb();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function it(name, fn) {
|
|
44
|
+
denoIt(name, async () => {
|
|
45
|
+
for (const cb of beforeEachCallbacks) {
|
|
46
|
+
await cb();
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
await fn();
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
for (const cb of afterEachCallbacks) {
|
|
53
|
+
await cb();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function beforeEach(fn) {
|
|
59
|
+
beforeEachCallbacks.push(fn);
|
|
60
|
+
}
|
|
61
|
+
function afterEach(fn) {
|
|
62
|
+
afterEachCallbacks.push(fn);
|
|
63
|
+
}
|
|
64
|
+
function beforeAll(fn) {
|
|
65
|
+
beforeAllCallbacks.push(fn);
|
|
66
|
+
}
|
|
67
|
+
function afterAll(fn) {
|
|
68
|
+
afterAllCallbacks.push(fn);
|
|
69
|
+
}
|
|
70
|
+
function mockFn(implementation) {
|
|
71
|
+
const calls = [];
|
|
72
|
+
const results = [];
|
|
73
|
+
const fn = (...args) => {
|
|
74
|
+
calls.push(args);
|
|
75
|
+
const result = implementation ? implementation(...args) : undefined;
|
|
76
|
+
results.push(result);
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
fn.mock = {
|
|
80
|
+
calls,
|
|
81
|
+
results,
|
|
82
|
+
lastCall: () => calls[calls.length - 1],
|
|
83
|
+
};
|
|
84
|
+
fn.mockImplementation = (impl) => {
|
|
85
|
+
implementation = impl;
|
|
86
|
+
return fn;
|
|
87
|
+
};
|
|
88
|
+
fn.mockReturnValue = (value) => {
|
|
89
|
+
implementation = () => value;
|
|
90
|
+
return fn;
|
|
91
|
+
};
|
|
92
|
+
fn.mockResolvedValue = (value) => {
|
|
93
|
+
implementation = () => Promise.resolve(value);
|
|
94
|
+
return fn;
|
|
95
|
+
};
|
|
96
|
+
fn.mockRejectedValue = (value) => {
|
|
97
|
+
implementation = () => Promise.reject(value);
|
|
98
|
+
return fn;
|
|
99
|
+
};
|
|
100
|
+
fn.mockClear = () => {
|
|
101
|
+
calls.length = 0;
|
|
102
|
+
results.length = 0;
|
|
103
|
+
};
|
|
104
|
+
fn.mockReset = () => {
|
|
105
|
+
calls.length = 0;
|
|
106
|
+
results.length = 0;
|
|
107
|
+
implementation = undefined;
|
|
108
|
+
};
|
|
109
|
+
return fn;
|
|
110
|
+
}
|
|
111
|
+
const fakeTimers = {
|
|
112
|
+
useFakeTimers: () => {
|
|
113
|
+
fakeTime = new FakeTime();
|
|
114
|
+
return fakeTimers;
|
|
115
|
+
},
|
|
116
|
+
useRealTimers: () => {
|
|
117
|
+
if (fakeTime) {
|
|
118
|
+
fakeTime.restore();
|
|
119
|
+
fakeTime = null;
|
|
120
|
+
}
|
|
121
|
+
return fakeTimers;
|
|
122
|
+
},
|
|
123
|
+
advanceTimersByTime: (ms) => {
|
|
124
|
+
if (fakeTime) {
|
|
125
|
+
fakeTime.tick(ms);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
runAllTimers: () => {
|
|
129
|
+
if (fakeTime) {
|
|
130
|
+
fakeTime.runAll();
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
clearAllTimers: () => {
|
|
134
|
+
if (fakeTime) {
|
|
135
|
+
fakeTime.restore();
|
|
136
|
+
fakeTime = new FakeTime();
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const expect = (value) => {
|
|
141
|
+
const matcher = denoExpect(value);
|
|
142
|
+
matcher.toBeInstanceOf = function toBeInstanceOf(constructor) {
|
|
143
|
+
const pass = value instanceof constructor;
|
|
144
|
+
if (!pass) {
|
|
145
|
+
throw new Error(`expected ${value} to be instance of ${constructor.name}`);
|
|
146
|
+
}
|
|
147
|
+
return { pass };
|
|
148
|
+
};
|
|
149
|
+
matcher.toStrictEqual = function toStrictEqual(expected) {
|
|
150
|
+
return matcher.toEqual(expected);
|
|
151
|
+
};
|
|
152
|
+
matcher.toThrowError = function toThrowError(expected) {
|
|
153
|
+
let error;
|
|
154
|
+
let thrown = false;
|
|
155
|
+
try {
|
|
156
|
+
if (typeof value === 'function') {
|
|
157
|
+
value();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
error = e;
|
|
162
|
+
thrown = true;
|
|
163
|
+
}
|
|
164
|
+
if (!thrown) {
|
|
165
|
+
throw new Error('expected function to throw');
|
|
166
|
+
}
|
|
167
|
+
if (expected !== undefined) {
|
|
168
|
+
if (typeof expected === 'string' && !error.message.includes(expected)) {
|
|
169
|
+
throw new Error(`expected error message to include "${expected}"`);
|
|
170
|
+
}
|
|
171
|
+
if (expected instanceof RegExp && !expected.test(error.message)) {
|
|
172
|
+
throw new Error(`expected error message to match ${expected}`);
|
|
173
|
+
}
|
|
174
|
+
if (typeof expected === 'function' && !(error instanceof expected)) {
|
|
175
|
+
throw new Error(`expected error to be instance of ${expected.name}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { pass: true };
|
|
179
|
+
};
|
|
180
|
+
return matcher;
|
|
181
|
+
};
|
|
182
|
+
expect.extend = (matchers) => {
|
|
183
|
+
Object.assign(expect, matchers);
|
|
184
|
+
};
|
|
185
|
+
globalThis.describe = describe;
|
|
186
|
+
globalThis.test = it;
|
|
187
|
+
globalThis.it = it;
|
|
188
|
+
globalThis.expect = expect;
|
|
189
|
+
globalThis.beforeEach = beforeEach;
|
|
190
|
+
globalThis.afterEach = afterEach;
|
|
191
|
+
globalThis.beforeAll = beforeAll;
|
|
192
|
+
globalThis.afterAll = afterAll;
|
|
193
|
+
globalThis.jest = {
|
|
194
|
+
fn: mockFn,
|
|
195
|
+
mock: mockFn,
|
|
196
|
+
useFakeTimers: fakeTimers.useFakeTimers,
|
|
197
|
+
useRealTimers: fakeTimers.useRealTimers,
|
|
198
|
+
advanceTimersByTime: fakeTimers.advanceTimersByTime,
|
|
199
|
+
runAllTimers: fakeTimers.runAllTimers,
|
|
200
|
+
clearAllTimers: fakeTimers.clearAllTimers,
|
|
201
|
+
};
|
|
202
|
+
globalThis.node = {
|
|
203
|
+
util: {
|
|
204
|
+
inherits,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
export { it, expect, mockFn, describe, afterAll, inherits, afterEach, beforeAll, beforeEach };
|
|
208
|
+
//# sourceMappingURL=deno-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deno-adapter.js","sourceRoot":"","sources":["../../src/runtime/deno-adapter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEhF,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,8CAA8C,CAAC;AAGtG,SAAS,QAAQ,CAAC,IAAS,EAAE,SAAc;IACzC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,MAAM,IAAI,SAAS,CAAC,6DAA6D,CAAC,CAAC;IACrF,CAAC;IACD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC;IAC3F,CAAC;IACD,IAAI,SAAS,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,IAAI,SAAS,CAAC,oEAAoE,CAAC,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AC;AAC3C,UAAkB,CAAC,SAAS,GAAG,SAAS,CAAC;AACzC,UAAkB,CAAC,SAAS,GAAG,SAAS,CAAC;AACzC,UAAkB,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAGvC,UAAkB,CAAC,IAAI,GAAG;IACzB,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,MAAM;IACZ,aAAa,EAAE,UAAU,CAAC,aAAa;IACvC,aAAa,EAAE,UAAU,CAAC,aAAa;IACvC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;IACnD,YAAY,EAAE,UAAU,CAAC,YAAY;IACrC,cAAc,EAAE,UAAU,CAAC,cAAc;CAC1C,CAAC;AAGD,UAAkB,CAAC,IAAI,GAAG;IACzB,IAAI,EAAE;QACJ,QAAQ;KACT;CACF,CAAC;AAGF,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const fakeTimers: {
|
|
2
|
+
useFakeTimers: () => any;
|
|
3
|
+
useRealTimers: () => any;
|
|
4
|
+
advanceTimersByTime: (ms: number) => void;
|
|
5
|
+
runAllTimers: () => void;
|
|
6
|
+
clearAllTimers: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const describe: any;
|
|
9
|
+
export declare const it: any;
|
|
10
|
+
export declare const test: any;
|
|
11
|
+
export declare const expect: any;
|
|
12
|
+
export declare const beforeEach: any;
|
|
13
|
+
export declare const afterEach: any;
|
|
14
|
+
export declare const beforeAll: any;
|
|
15
|
+
export declare const afterAll: any;
|
|
16
|
+
export declare const jest: any;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { timerUtils } from './test-adapter.js';
|
|
2
|
+
export const fakeTimers = {
|
|
3
|
+
useFakeTimers: () => {
|
|
4
|
+
timerUtils.useFakeTimers();
|
|
5
|
+
return fakeTimers;
|
|
6
|
+
},
|
|
7
|
+
useRealTimers: () => {
|
|
8
|
+
timerUtils.useRealTimers();
|
|
9
|
+
return fakeTimers;
|
|
10
|
+
},
|
|
11
|
+
advanceTimersByTime: (ms) => {
|
|
12
|
+
timerUtils.advanceTimersByTime(ms);
|
|
13
|
+
},
|
|
14
|
+
runAllTimers: () => {
|
|
15
|
+
timerUtils.runAllTimers();
|
|
16
|
+
},
|
|
17
|
+
clearAllTimers: () => {
|
|
18
|
+
timerUtils.clearAllTimers();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const describe = global.describe;
|
|
22
|
+
export const it = global.it;
|
|
23
|
+
export const test = global.test;
|
|
24
|
+
export const expect = global.expect;
|
|
25
|
+
export const beforeEach = global.beforeEach;
|
|
26
|
+
export const afterEach = global.afterEach;
|
|
27
|
+
export const beforeAll = global.beforeAll;
|
|
28
|
+
export const afterAll = global.afterAll;
|
|
29
|
+
export const jest = global.jest;
|
|
30
|
+
//# sourceMappingURL=node-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-adapter.js","sourceRoot":"","sources":["../../src/runtime/node-adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa,EAAE,GAAG,EAAE;QAClB,UAAU,CAAC,aAAa,EAAE,CAAC;QAC3B,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,aAAa,EAAE,GAAG,EAAE;QAClB,UAAU,CAAC,aAAa,EAAE,CAAC;QAC3B,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,mBAAmB,EAAE,CAAC,EAAU,EAAE,EAAE;QAClC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,YAAY,EAAE,GAAG,EAAE;QACjB,UAAU,CAAC,YAAY,EAAE,CAAC;IAC5B,CAAC;IACD,cAAc,EAAE,GAAG,EAAE;QACnB,UAAU,CAAC,cAAc,EAAE,CAAC;IAC9B,CAAC;CACF,CAAC;AAGF,MAAM,CAAC,MAAM,QAAQ,GAAI,MAAc,CAAC,QAAQ,CAAC;AACjD,MAAM,CAAC,MAAM,EAAE,GAAI,MAAc,CAAC,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,IAAI,GAAI,MAAc,CAAC,IAAI,CAAC;AACzC,MAAM,CAAC,MAAM,MAAM,GAAI,MAAc,CAAC,MAAM,CAAC;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAI,MAAc,CAAC,UAAU,CAAC;AACrD,MAAM,CAAC,MAAM,SAAS,GAAI,MAAc,CAAC,SAAS,CAAC;AACnD,MAAM,CAAC,MAAM,SAAS,GAAI,MAAc,CAAC,SAAS,CAAC;AACnD,MAAM,CAAC,MAAM,QAAQ,GAAI,MAAc,CAAC,QAAQ,CAAC;AAGjD,MAAM,CAAC,MAAM,IAAI,GAAI,MAAc,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const RUNTIME: string;
|
|
2
|
+
export declare const timerUtils: {
|
|
3
|
+
useFakeTimers(): void;
|
|
4
|
+
useRealTimers(): void;
|
|
5
|
+
advanceTimersByTime(ms: number): void;
|
|
6
|
+
runAllTimers(): void;
|
|
7
|
+
clearAllTimers(): void;
|
|
8
|
+
canUseFakeTimers(): boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function skipIfNoFakeTimers(): boolean;
|
|
11
|
+
export declare function normalizeGlobalChecks(value: any): boolean;
|
|
12
|
+
export declare const isBun: boolean;
|
|
13
|
+
export declare const isDeno: boolean;
|
|
14
|
+
export declare const isNode: boolean;
|
|
15
|
+
export declare const isJest: boolean;
|
|
16
|
+
export declare const supportsFakeTimers: () => boolean;
|
|
17
|
+
export declare const setupFakeTimers: () => void;
|
|
18
|
+
export declare const teardownFakeTimers: () => void;
|
|
19
|
+
export declare const advanceTimersByTime: (ms: number) => void;
|
|
20
|
+
export declare const clearAllTimers: () => void;
|
|
21
|
+
export declare const expectAsync: (fn: () => Promise<any>) => Promise<any>;
|
|
22
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const RUNTIME = (() => {
|
|
2
|
+
if (typeof globalThis.Bun !== 'undefined')
|
|
3
|
+
return 'bun';
|
|
4
|
+
if (typeof globalThis.Deno !== 'undefined')
|
|
5
|
+
return 'deno';
|
|
6
|
+
return 'node';
|
|
7
|
+
})();
|
|
8
|
+
export const timerUtils = {
|
|
9
|
+
useFakeTimers() {
|
|
10
|
+
if (RUNTIME === 'node' && typeof global.jest !== 'undefined') {
|
|
11
|
+
global.jest.useFakeTimers();
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
useRealTimers() {
|
|
15
|
+
if (RUNTIME === 'node' && typeof global.jest !== 'undefined') {
|
|
16
|
+
global.jest.useRealTimers();
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
advanceTimersByTime(ms) {
|
|
20
|
+
if (RUNTIME === 'node' && typeof global.jest !== 'undefined') {
|
|
21
|
+
global.jest.advanceTimersByTime(ms);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
runAllTimers() {
|
|
27
|
+
if (RUNTIME === 'node' && typeof global.jest !== 'undefined') {
|
|
28
|
+
global.jest.runAllTimers();
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
clearAllTimers() {
|
|
32
|
+
if (RUNTIME === 'node' && typeof global.jest !== 'undefined') {
|
|
33
|
+
global.jest.clearAllTimers();
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
canUseFakeTimers() {
|
|
37
|
+
return RUNTIME === 'node';
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export function skipIfNoFakeTimers() {
|
|
41
|
+
if (!timerUtils.canUseFakeTimers()) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
export function normalizeGlobalChecks(value) {
|
|
47
|
+
if (RUNTIME === 'bun' && value === globalThis) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
export const isBun = RUNTIME === 'bun';
|
|
53
|
+
export const isDeno = RUNTIME === 'deno';
|
|
54
|
+
export const isNode = RUNTIME === 'node';
|
|
55
|
+
export const isJest = isNode &&
|
|
56
|
+
typeof globalThis.jest !== 'undefined' &&
|
|
57
|
+
typeof globalThis.jest.useFakeTimers === 'function';
|
|
58
|
+
export const supportsFakeTimers = () => isJest;
|
|
59
|
+
export const setupFakeTimers = () => {
|
|
60
|
+
timerUtils.useFakeTimers();
|
|
61
|
+
};
|
|
62
|
+
export const teardownFakeTimers = () => {
|
|
63
|
+
timerUtils.useRealTimers();
|
|
64
|
+
};
|
|
65
|
+
export const advanceTimersByTime = (ms) => {
|
|
66
|
+
timerUtils.advanceTimersByTime(ms);
|
|
67
|
+
};
|
|
68
|
+
export const clearAllTimers = () => {
|
|
69
|
+
timerUtils.clearAllTimers();
|
|
70
|
+
};
|
|
71
|
+
export const expectAsync = async (fn) => {
|
|
72
|
+
if (isBun) {
|
|
73
|
+
try {
|
|
74
|
+
await fn();
|
|
75
|
+
throw new Error('Expected promise to reject but it resolved');
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return {
|
|
79
|
+
toThrow: (expectedError) => {
|
|
80
|
+
if (expectedError) {
|
|
81
|
+
globalThis.expect(error).toEqual(expectedError);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
globalThis.expect(error).toBeDefined();
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return globalThis.expect(fn()).rejects;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
95
|
+
//# sourceMappingURL=test-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-adapter.js","sourceRoot":"","sources":["../../src/runtime/test-adapter.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE;IAC3B,IAAI,OAAQ,UAAkB,CAAC,GAAG,KAAK,WAAW;QAAE,OAAO,KAAK,CAAC;IACjE,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,MAAM,CAAC;IACnE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,EAAE,CAAC;AAGL,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa;QAEX,IAAI,OAAO,KAAK,MAAM,IAAI,OAAQ,MAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACrE,MAAc,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IAED,aAAa;QACX,IAAI,OAAO,KAAK,MAAM,IAAI,OAAQ,MAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACrE,MAAc,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,EAAU;QAC5B,IAAI,OAAO,KAAK,MAAM,IAAI,OAAQ,MAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACrE,MAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;QAGR,CAAC;IACH,CAAC;IAED,YAAY;QACV,IAAI,OAAO,KAAK,MAAM,IAAI,OAAQ,MAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACrE,MAAc,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;IAED,cAAc;QACZ,IAAI,OAAO,KAAK,MAAM,IAAI,O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