@pezkuwi/dev-test 0.85.3 → 0.85.7
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 +201 -0
- package/browser.d.ts +1 -0
- package/browser.js +2 -0
- package/cjs/browser.d.ts +1 -0
- package/cjs/browser.js +4 -0
- package/cjs/env/browser.d.ts +313 -0
- package/cjs/env/browser.js +98 -0
- package/cjs/env/expect.d.ts +297 -0
- package/cjs/env/expect.js +213 -0
- package/cjs/env/index.d.ts +4 -0
- package/cjs/env/index.js +20 -0
- package/cjs/env/jest.d.ts +127 -0
- package/cjs/env/jest.js +56 -0
- package/cjs/env/lifecycle.d.ts +12 -0
- package/cjs/env/lifecycle.js +17 -0
- package/cjs/env/suite.d.ts +20 -0
- package/cjs/env/suite.js +35 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/cjs/node.d.ts +1 -0
- package/cjs/node.js +4 -0
- package/cjs/package.json +3 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/types.d.ts +15 -0
- package/cjs/types.js +2 -0
- package/cjs/util.d.ts +20 -0
- package/cjs/util.js +51 -0
- package/env/browser.d.ts +313 -0
- package/env/browser.js +95 -0
- package/env/expect.d.ts +297 -0
- package/env/expect.js +210 -0
- package/env/index.d.ts +4 -0
- package/env/index.js +17 -0
- package/env/jest.d.ts +127 -0
- package/env/jest.js +53 -0
- package/env/lifecycle.d.ts +12 -0
- package/env/lifecycle.js +14 -0
- package/env/suite.d.ts +20 -0
- package/env/suite.js +32 -0
- package/globals.cjs +4 -0
- package/globals.d.ts +30 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/node.d.ts +1 -0
- package/node.js +2 -0
- package/package.json +196 -7
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/types.d.ts +15 -0
- package/types.js +1 -0
- package/util.d.ts +20 -0
- package/util.js +46 -0
- package/.skip-deno +0 -0
- package/tsconfig.build.json +0 -16
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -16
- package/tsconfig.spec.tsbuildinfo +0 -1
package/env/jest.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { mock } from 'node:test';
|
|
2
|
+
import { enhanceObj, stubObj, warnObj } from '../util.js';
|
|
3
|
+
const JEST_KEYS_STUB = ['advanceTimersByTime', 'advanceTimersToNextTimer', 'autoMockOff', 'autoMockOn', 'clearAllMocks', 'clearAllTimers', 'createMockFromModule', 'deepUnmock', 'disableAutomock', 'doMock', 'dontMock', 'enableAutomock', 'fn', 'genMockFromModule', 'getRealSystemTime', 'getSeed', 'getTimerCount', 'isEnvironmentTornDown', 'isMockFunction', 'isolateModules', 'isolateModulesAsync', 'mock', 'mocked', 'now', 'replaceProperty', 'requireActual', 'requireMock', 'resetAllMocks', 'resetModules', 'restoreAllMocks', 'retryTimes', 'runAllImmediates', 'runAllTicks', 'runAllTimers', 'runOnlyPendingTimers', 'setMock', 'setSystemTime', 'setTimeout', 'spyOn', 'unmock', 'unstable_mockModule', 'useFakeTimers', 'useRealTimers'];
|
|
4
|
+
const JEST_KEYS_WARN = ['setTimeout'];
|
|
5
|
+
const MOCK_KEYS_STUB = ['_isMockFunction', 'getMockImplementation', 'getMockName', 'mock', 'mockClear', 'mockImplementation', 'mockImplementationOnce', 'mockName', 'mockRejectedValue', 'mockRejectedValueOnce', 'mockReset', 'mockResolvedValue', 'mockResolvedValueOnce', 'mockRestore', 'mockReturnThis', 'mockReturnValue', 'mockReturnValueOnce', 'withImplementation'];
|
|
6
|
+
const jestStub = stubObj('jest', JEST_KEYS_STUB);
|
|
7
|
+
const jestWarn = warnObj('jest', JEST_KEYS_WARN);
|
|
8
|
+
const mockStub = stubObj('jest.fn()', MOCK_KEYS_STUB);
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*
|
|
12
|
+
* This adds the mockReset and mockRestore functionality to any
|
|
13
|
+
* spy or mock function
|
|
14
|
+
**/
|
|
15
|
+
function extendMock(mocked) {
|
|
16
|
+
// We use the node:test mock here for casting below - however we
|
|
17
|
+
// don't want this in any method signature since this is a private
|
|
18
|
+
// types export, which could get us in "some" trouble
|
|
19
|
+
//
|
|
20
|
+
// Effectively the casts below ensure that our WithMock<*> aligns
|
|
21
|
+
// on a high-level to what we use via private type...
|
|
22
|
+
const spy = mocked;
|
|
23
|
+
return enhanceObj(enhanceObj(mocked, {
|
|
24
|
+
mockImplementation: (fn) => {
|
|
25
|
+
spy.mock.mockImplementation(fn);
|
|
26
|
+
},
|
|
27
|
+
mockImplementationOnce: (fn) => {
|
|
28
|
+
spy.mock.mockImplementationOnce(fn);
|
|
29
|
+
},
|
|
30
|
+
mockReset: () => {
|
|
31
|
+
spy.mock.resetCalls();
|
|
32
|
+
},
|
|
33
|
+
mockRestore: () => {
|
|
34
|
+
spy.mock.restore();
|
|
35
|
+
}
|
|
36
|
+
}), mockStub);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Sets up the jest object. This is certainly not extensive, and probably
|
|
40
|
+
* not quite meant to be (never say never). Rather this adds the functionality
|
|
41
|
+
* that we use in the pezkuwi-js projects.
|
|
42
|
+
**/
|
|
43
|
+
export function jest() {
|
|
44
|
+
return {
|
|
45
|
+
jest: enhanceObj(enhanceObj({
|
|
46
|
+
fn: (fn) => extendMock(mock.fn(fn)),
|
|
47
|
+
restoreAllMocks: () => {
|
|
48
|
+
mock.reset();
|
|
49
|
+
},
|
|
50
|
+
spyOn: (obj, key) => extendMock(mock.method(obj, key))
|
|
51
|
+
}, jestWarn), jestStub)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { after, afterEach, before, beforeEach } from 'node:test';
|
|
2
|
+
/**
|
|
3
|
+
* This ensures that the before/after functions are exposed
|
|
4
|
+
**/
|
|
5
|
+
export declare function lifecycle(): {
|
|
6
|
+
after: typeof after;
|
|
7
|
+
afterAll: typeof after;
|
|
8
|
+
afterEach: typeof afterEach;
|
|
9
|
+
before: typeof before;
|
|
10
|
+
beforeAll: typeof before;
|
|
11
|
+
beforeEach: typeof beforeEach;
|
|
12
|
+
};
|
package/env/lifecycle.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { after, afterEach, before, beforeEach } from 'node:test';
|
|
2
|
+
/**
|
|
3
|
+
* This ensures that the before/after functions are exposed
|
|
4
|
+
**/
|
|
5
|
+
export function lifecycle() {
|
|
6
|
+
return {
|
|
7
|
+
after,
|
|
8
|
+
afterAll: after,
|
|
9
|
+
afterEach,
|
|
10
|
+
before,
|
|
11
|
+
beforeAll: before,
|
|
12
|
+
beforeEach
|
|
13
|
+
};
|
|
14
|
+
}
|
package/env/suite.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type TestFn = (name: string, exec: () => void | Promise<void>, timeout?: number) => void;
|
|
2
|
+
export interface Describe extends TestFn {
|
|
3
|
+
only: TestFn;
|
|
4
|
+
skip: TestFn;
|
|
5
|
+
todo: TestFn;
|
|
6
|
+
}
|
|
7
|
+
export interface It extends TestFn {
|
|
8
|
+
only: TestFn;
|
|
9
|
+
skip: TestFn;
|
|
10
|
+
todo: TestFn;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This ensures that the describe and it functions match our actual usages.
|
|
14
|
+
* This includes .only, .skip and .todo helpers (.each is not applied)
|
|
15
|
+
**/
|
|
16
|
+
export declare function suite(): {
|
|
17
|
+
describe: Describe;
|
|
18
|
+
it: It;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
package/env/suite.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import { enhanceObj } from '../util.js';
|
|
3
|
+
const MINUTE = 60 * 1000;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* Wraps either describe or it with relevant .only, .skip, .todo & .each helpers,
|
|
8
|
+
* shimming it into a Jest-compatible environment.
|
|
9
|
+
*
|
|
10
|
+
* @param {} fn
|
|
11
|
+
*/
|
|
12
|
+
function createWrapper(fn, defaultTimeout) {
|
|
13
|
+
const wrap = (opts) => (name, exec, timeout) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec);
|
|
14
|
+
// Ensure that we have consistent helpers on the function. These are not consistently
|
|
15
|
+
// applied accross all node:test versions, latest has all, so always apply ours.
|
|
16
|
+
// Instead of node:test options for e.g. timeout, we provide a Jest-compatible signature
|
|
17
|
+
return enhanceObj(wrap({}), {
|
|
18
|
+
only: wrap({ only: true }),
|
|
19
|
+
skip: wrap({ skip: true }),
|
|
20
|
+
todo: wrap({ todo: true })
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This ensures that the describe and it functions match our actual usages.
|
|
25
|
+
* This includes .only, .skip and .todo helpers (.each is not applied)
|
|
26
|
+
**/
|
|
27
|
+
export function suite() {
|
|
28
|
+
return {
|
|
29
|
+
describe: createWrapper(describe, 60 * MINUTE),
|
|
30
|
+
it: createWrapper(it, 2 * MINUTE)
|
|
31
|
+
};
|
|
32
|
+
}
|
package/globals.cjs
ADDED
package/globals.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* eslint-disable no-var */
|
|
5
|
+
|
|
6
|
+
import type { expect } from './env/expect.js';
|
|
7
|
+
import type { jest } from './env/jest.js';
|
|
8
|
+
import type { lifecycle } from './env/lifecycle.js';
|
|
9
|
+
import type { Describe, It } from './env/suite.js';
|
|
10
|
+
|
|
11
|
+
type Expect = ReturnType<typeof expect>;
|
|
12
|
+
|
|
13
|
+
type Jest = ReturnType<typeof jest>;
|
|
14
|
+
|
|
15
|
+
type Lifecycle = ReturnType<typeof lifecycle>;
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
var after: Lifecycle['after'];
|
|
19
|
+
var afterAll: Lifecycle['afterAll'];
|
|
20
|
+
var afterEach: Lifecycle['afterEach'];
|
|
21
|
+
var before: Lifecycle['before'];
|
|
22
|
+
var beforeAll: Lifecycle['beforeAll'];
|
|
23
|
+
var beforeEach: Lifecycle['beforeEach'];
|
|
24
|
+
var describe: Describe;
|
|
25
|
+
var expect: Expect['expect'];
|
|
26
|
+
var it: It;
|
|
27
|
+
var jest: Jest['jest'];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error('Use node --require @pezkuwi/dev-test/{node, browser} depending on the required environment');
|
package/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/node.js
ADDED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "
|
|
2
|
+
"author": "Pezkuwi Team <team@pezkuwichain.app>",
|
|
3
3
|
"bugs": "https://github.com/pezkuwichain/pezkuwi-dev/issues",
|
|
4
4
|
"description": "A basic test-functions-as-global library on top of node:test",
|
|
5
5
|
"engines": {
|
|
@@ -15,16 +15,205 @@
|
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"type": "module",
|
|
18
|
-
"version": "0.85.
|
|
19
|
-
"main": "./index.js",
|
|
18
|
+
"version": "0.85.7",
|
|
19
|
+
"main": "./cjs/index.js",
|
|
20
|
+
"module": "./cjs/index.js",
|
|
21
|
+
"types": "./cjs/index.d.ts",
|
|
20
22
|
"exports": {
|
|
21
|
-
"./
|
|
23
|
+
"./cjs/package.json": "./cjs/package.json",
|
|
24
|
+
"./cjs/*": "./cjs/*.js",
|
|
25
|
+
".": {
|
|
26
|
+
"module": {
|
|
27
|
+
"types": "./index.d.ts",
|
|
28
|
+
"default": "./index.js"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./cjs/index.d.ts",
|
|
32
|
+
"default": "./cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"default": {
|
|
35
|
+
"types": "./index.d.ts",
|
|
36
|
+
"default": "./index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./browser": {
|
|
40
|
+
"module": {
|
|
41
|
+
"types": "./browser.d.ts",
|
|
42
|
+
"default": "./browser.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./cjs/browser.d.ts",
|
|
46
|
+
"default": "./cjs/browser.js"
|
|
47
|
+
},
|
|
48
|
+
"default": {
|
|
49
|
+
"types": "./browser.d.ts",
|
|
50
|
+
"default": "./browser.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"./env": {
|
|
54
|
+
"module": {
|
|
55
|
+
"types": "./env/index.d.ts",
|
|
56
|
+
"default": "./env/index.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./cjs/env/index.d.ts",
|
|
60
|
+
"default": "./cjs/env/index.js"
|
|
61
|
+
},
|
|
62
|
+
"default": {
|
|
63
|
+
"types": "./env/index.d.ts",
|
|
64
|
+
"default": "./env/index.js"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"./env/browser": {
|
|
68
|
+
"module": {
|
|
69
|
+
"types": "./env/browser.d.ts",
|
|
70
|
+
"default": "./env/browser.js"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"types": "./cjs/env/browser.d.ts",
|
|
74
|
+
"default": "./cjs/env/browser.js"
|
|
75
|
+
},
|
|
76
|
+
"default": {
|
|
77
|
+
"types": "./env/browser.d.ts",
|
|
78
|
+
"default": "./env/browser.js"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"./env/expect": {
|
|
82
|
+
"module": {
|
|
83
|
+
"types": "./env/expect.d.ts",
|
|
84
|
+
"default": "./env/expect.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./cjs/env/expect.d.ts",
|
|
88
|
+
"default": "./cjs/env/expect.js"
|
|
89
|
+
},
|
|
90
|
+
"default": {
|
|
91
|
+
"types": "./env/expect.d.ts",
|
|
92
|
+
"default": "./env/expect.js"
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"./env/jest": {
|
|
96
|
+
"module": {
|
|
97
|
+
"types": "./env/jest.d.ts",
|
|
98
|
+
"default": "./env/jest.js"
|
|
99
|
+
},
|
|
100
|
+
"require": {
|
|
101
|
+
"types": "./cjs/env/jest.d.ts",
|
|
102
|
+
"default": "./cjs/env/jest.js"
|
|
103
|
+
},
|
|
104
|
+
"default": {
|
|
105
|
+
"types": "./env/jest.d.ts",
|
|
106
|
+
"default": "./env/jest.js"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"./env/lifecycle": {
|
|
110
|
+
"module": {
|
|
111
|
+
"types": "./env/lifecycle.d.ts",
|
|
112
|
+
"default": "./env/lifecycle.js"
|
|
113
|
+
},
|
|
114
|
+
"require": {
|
|
115
|
+
"types": "./cjs/env/lifecycle.d.ts",
|
|
116
|
+
"default": "./cjs/env/lifecycle.js"
|
|
117
|
+
},
|
|
118
|
+
"default": {
|
|
119
|
+
"types": "./env/lifecycle.d.ts",
|
|
120
|
+
"default": "./env/lifecycle.js"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"./env/suite": {
|
|
124
|
+
"module": {
|
|
125
|
+
"types": "./env/suite.d.ts",
|
|
126
|
+
"default": "./env/suite.js"
|
|
127
|
+
},
|
|
128
|
+
"require": {
|
|
129
|
+
"types": "./cjs/env/suite.d.ts",
|
|
130
|
+
"default": "./cjs/env/suite.js"
|
|
131
|
+
},
|
|
132
|
+
"default": {
|
|
133
|
+
"types": "./env/suite.d.ts",
|
|
134
|
+
"default": "./env/suite.js"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"./globals.cjs": "./globals.cjs",
|
|
138
|
+
"./globals": "./globals.cjs",
|
|
139
|
+
"./globals.d.ts": "./globals.d.ts",
|
|
140
|
+
"./node": {
|
|
141
|
+
"module": {
|
|
142
|
+
"types": "./node.d.ts",
|
|
143
|
+
"default": "./node.js"
|
|
144
|
+
},
|
|
145
|
+
"require": {
|
|
146
|
+
"types": "./cjs/node.d.ts",
|
|
147
|
+
"default": "./cjs/node.js"
|
|
148
|
+
},
|
|
149
|
+
"default": {
|
|
150
|
+
"types": "./node.d.ts",
|
|
151
|
+
"default": "./node.js"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"./package.json": {
|
|
155
|
+
"require": "./cjs/package.json",
|
|
156
|
+
"default": "./package.json"
|
|
157
|
+
},
|
|
158
|
+
"./packageInfo.js": {
|
|
159
|
+
"module": {
|
|
160
|
+
"types": "./packageInfo.d.ts",
|
|
161
|
+
"default": "./packageInfo.js"
|
|
162
|
+
},
|
|
163
|
+
"require": {
|
|
164
|
+
"types": "./cjs/packageInfo.d.ts",
|
|
165
|
+
"default": "./cjs/packageInfo.js"
|
|
166
|
+
},
|
|
167
|
+
"default": {
|
|
168
|
+
"types": "./packageInfo.d.ts",
|
|
169
|
+
"default": "./packageInfo.js"
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
"./packageInfo": {
|
|
173
|
+
"module": {
|
|
174
|
+
"types": "./packageInfo.d.ts",
|
|
175
|
+
"default": "./packageInfo.js"
|
|
176
|
+
},
|
|
177
|
+
"require": {
|
|
178
|
+
"types": "./cjs/packageInfo.d.ts",
|
|
179
|
+
"default": "./cjs/packageInfo.js"
|
|
180
|
+
},
|
|
181
|
+
"default": {
|
|
182
|
+
"types": "./packageInfo.d.ts",
|
|
183
|
+
"default": "./packageInfo.js"
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"./types": {
|
|
187
|
+
"module": {
|
|
188
|
+
"types": "./types.d.ts",
|
|
189
|
+
"default": "./types.js"
|
|
190
|
+
},
|
|
191
|
+
"require": {
|
|
192
|
+
"types": "./cjs/types.d.ts",
|
|
193
|
+
"default": "./cjs/types.js"
|
|
194
|
+
},
|
|
195
|
+
"default": {
|
|
196
|
+
"types": "./types.d.ts",
|
|
197
|
+
"default": "./types.js"
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"./util": {
|
|
201
|
+
"module": {
|
|
202
|
+
"types": "./util.d.ts",
|
|
203
|
+
"default": "./util.js"
|
|
204
|
+
},
|
|
205
|
+
"require": {
|
|
206
|
+
"types": "./cjs/util.d.ts",
|
|
207
|
+
"default": "./cjs/util.js"
|
|
208
|
+
},
|
|
209
|
+
"default": {
|
|
210
|
+
"types": "./util.d.ts",
|
|
211
|
+
"default": "./util.js"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
22
214
|
},
|
|
23
215
|
"dependencies": {
|
|
24
216
|
"jsdom": "^24.0.0",
|
|
25
217
|
"tslib": "^2.7.0"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@types/jsdom": "^21.1.6"
|
|
29
218
|
}
|
|
30
219
|
}
|
package/packageInfo.d.ts
ADDED
package/packageInfo.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const packageInfo = { name: '@pezkuwi/dev-test', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.85.4' };
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type AnyFn = (...args: any[]) => any;
|
|
2
|
+
export type BaseObj = Record<string, unknown>;
|
|
3
|
+
export type BaseFn = Function;
|
|
4
|
+
export type StubFn = (...args: unknown[]) => unknown;
|
|
5
|
+
export type WithMock<F extends AnyFn> = F & {
|
|
6
|
+
mock: {
|
|
7
|
+
calls: {
|
|
8
|
+
arguments: unknown[];
|
|
9
|
+
}[];
|
|
10
|
+
mockImplementation: (fn: AnyFn) => void;
|
|
11
|
+
mockImplementationOnce: (fn: AnyFn) => void;
|
|
12
|
+
resetCalls: () => void;
|
|
13
|
+
restore: () => void;
|
|
14
|
+
};
|
|
15
|
+
};
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/util.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BaseFn, BaseObj, StubFn } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extends an existing object with the additional function if they
|
|
4
|
+
* are not already existing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function enhanceObj<T extends BaseObj | BaseFn, X>(obj: T, extra: X): T & Omit<X, keyof T>;
|
|
7
|
+
/**
|
|
8
|
+
* Extends a given object with the named functions if they do not
|
|
9
|
+
* already exist on the object.
|
|
10
|
+
*
|
|
11
|
+
* @type {StubObjFn}
|
|
12
|
+
*/
|
|
13
|
+
export declare function stubObj<N extends readonly string[]>(objName: string, keys: N, alts?: Record<string, string>): { [K in N[number]]: StubFn; };
|
|
14
|
+
/**
|
|
15
|
+
* Extends a given object with the named functions if they do not
|
|
16
|
+
* already exist on the object.
|
|
17
|
+
*
|
|
18
|
+
* @type {StubObjFn}
|
|
19
|
+
*/
|
|
20
|
+
export declare function warnObj<N extends readonly string[]>(objName: string, keys: N): { [K in N[number]]: StubFn; };
|
package/util.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extends an existing object with the additional function if they
|
|
3
|
+
* are not already existing.
|
|
4
|
+
*/
|
|
5
|
+
export function enhanceObj(obj, extra) {
|
|
6
|
+
Object
|
|
7
|
+
.entries(extra)
|
|
8
|
+
.forEach(([key, value]) => {
|
|
9
|
+
obj[key] ??= value;
|
|
10
|
+
});
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*
|
|
16
|
+
* A helper to create a stub object based wite the stub creator supplied
|
|
17
|
+
*/
|
|
18
|
+
function createStub(keys, creator) {
|
|
19
|
+
return keys.reduce((obj, key) => {
|
|
20
|
+
obj[key] ??= creator(key);
|
|
21
|
+
return obj;
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extends a given object with the named functions if they do not
|
|
26
|
+
* already exist on the object.
|
|
27
|
+
*
|
|
28
|
+
* @type {StubObjFn}
|
|
29
|
+
*/
|
|
30
|
+
export function stubObj(objName, keys, alts) {
|
|
31
|
+
return createStub(keys, (key) => () => {
|
|
32
|
+
const alt = alts?.[key];
|
|
33
|
+
throw new Error(`${objName}.${key} has not been implemented${alt ? ` (Use ${alt} instead)` : ''}`);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extends a given object with the named functions if they do not
|
|
38
|
+
* already exist on the object.
|
|
39
|
+
*
|
|
40
|
+
* @type {StubObjFn}
|
|
41
|
+
*/
|
|
42
|
+
export function warnObj(objName, keys) {
|
|
43
|
+
return createStub(keys, (key) => () => {
|
|
44
|
+
console.warn(`${objName}.${key} has been implemented as a noop`);
|
|
45
|
+
});
|
|
46
|
+
}
|
package/.skip-deno
DELETED
|
File without changes
|
package/tsconfig.build.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": "..",
|
|
5
|
-
"outDir": "./build",
|
|
6
|
-
"rootDir": "./src"
|
|
7
|
-
},
|
|
8
|
-
"exclude": [
|
|
9
|
-
"**/mod.ts",
|
|
10
|
-
"src/**/*.spec.ts"
|
|
11
|
-
],
|
|
12
|
-
"include": [
|
|
13
|
-
"src/**/*"
|
|
14
|
-
],
|
|
15
|
-
"references": []
|
|
16
|
-
}
|