@dereekb/util 12.6.21 → 13.0.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.
Files changed (67) hide show
  1. package/LICENSE +1 -1
  2. package/fetch/LICENSE +1 -1
  3. package/fetch/index.cjs.js +42 -2529
  4. package/fetch/index.esm.js +44 -2530
  5. package/fetch/package.json +21 -16
  6. package/fetch/src/lib/fetch.page.d.ts +0 -4
  7. package/fetch/src/lib/fetch.url.d.ts +0 -8
  8. package/fetch/src/lib/provider.d.ts +0 -4
  9. package/index.cjs.js +36 -2354
  10. package/index.esm.js +39 -2344
  11. package/package.json +18 -7
  12. package/src/lib/array/array.boolean.d.ts +0 -11
  13. package/src/lib/array/array.value.d.ts +0 -18
  14. package/src/lib/boolean.d.ts +1 -1
  15. package/src/lib/date/date.d.ts +0 -8
  16. package/src/lib/date/date.unix.d.ts +6 -30
  17. package/src/lib/date/expires.d.ts +4 -4
  18. package/src/lib/date/hour.d.ts +1 -1
  19. package/src/lib/date/time.d.ts +0 -4
  20. package/src/lib/key.d.ts +4 -0
  21. package/src/lib/object/object.map.d.ts +0 -9
  22. package/src/lib/page/index.d.ts +0 -1
  23. package/src/lib/promise/promise.d.ts +2 -3
  24. package/src/lib/set/set.hashset.d.ts +4 -4
  25. package/src/lib/storage/storage.d.ts +2 -2
  26. package/src/lib/string/mimetype.d.ts +0 -8
  27. package/src/lib/string/replace.d.ts +11 -1
  28. package/src/lib/tree/tree.flatten.d.ts +0 -10
  29. package/src/lib/value/indexed.d.ts +1 -1
  30. package/src/lib/value/maybe.type.d.ts +3 -3
  31. package/src/lib/value/point.d.ts +2 -2
  32. package/test/LICENSE +21 -0
  33. package/test/index.cjs.js +707 -0
  34. package/test/index.esm.js +664 -0
  35. package/test/package.json +20 -6
  36. package/test/src/lib/index.d.ts +1 -3
  37. package/test/src/lib/jest/index.d.ts +4 -0
  38. package/test/src/lib/jest/jest.d.ts +55 -0
  39. package/test/src/lib/jest/jest.fail.d.ts +72 -0
  40. package/test/src/lib/jest/jest.function.d.ts +41 -0
  41. package/test/src/lib/jest/jest.wrap.d.ts +24 -0
  42. package/test/src/lib/shared/index.d.ts +4 -0
  43. package/test/src/lib/shared/shared.d.ts +154 -0
  44. package/test/src/lib/shared/shared.fail.d.ts +83 -0
  45. package/test/src/lib/shared/shared.function.d.ts +25 -0
  46. package/test/src/lib/{jest.wrap.d.ts → shared/shared.wrap.d.ts} +9 -9
  47. package/index.esm.d.ts +0 -1
  48. package/src/lib/page/page.calculator.d.ts +0 -29
  49. package/test/CHANGELOG.md +0 -1956
  50. package/test/src/index.js +0 -5
  51. package/test/src/index.js.map +0 -1
  52. package/test/src/lib/index.js +0 -8
  53. package/test/src/lib/index.js.map +0 -1
  54. package/test/src/lib/jest.d.ts +0 -100
  55. package/test/src/lib/jest.fail.d.ts +0 -104
  56. package/test/src/lib/jest.fail.js +0 -224
  57. package/test/src/lib/jest.fail.js.map +0 -1
  58. package/test/src/lib/jest.function.d.ts +0 -25
  59. package/test/src/lib/jest.function.js +0 -21
  60. package/test/src/lib/jest.function.js.map +0 -1
  61. package/test/src/lib/jest.js +0 -113
  62. package/test/src/lib/jest.js.map +0 -1
  63. package/test/src/lib/jest.wrap.js +0 -70
  64. package/test/src/lib/jest.wrap.js.map +0 -1
  65. /package/fetch/{index.cjs.d.ts → index.d.ts} +0 -0
  66. /package/{fetch/index.esm.d.ts → index.d.ts} +0 -0
  67. /package/{index.cjs.d.ts → test/index.d.ts} +0 -0
package/test/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/util/test/src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./jest"), exports);
5
- tslib_1.__exportStar(require("./jest.fail"), exports);
6
- tslib_1.__exportStar(require("./jest.wrap"), exports);
7
- tslib_1.__exportStar(require("./jest.function"), exports);
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/test/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,sDAA4B;AAC5B,sDAA4B;AAC5B,0DAAgC"}
@@ -1,100 +0,0 @@
1
- import { type PromiseOrValue } from '@dereekb/util';
2
- /**
3
- * A fixture instance that is generated new for each test run.
4
- */
5
- export type JestTestFixtureInstance<I> = I;
6
- /**
7
- * The test fixture is used as a singleton across tests used in a single context.
8
- *
9
- * This allows us to define tests while referencing the instance.
10
- */
11
- export interface JestTestFixture<I> {
12
- readonly instance: JestTestFixtureInstance<I>;
13
- }
14
- export type JestTestContextFixtureClearInstanceFunction = () => void;
15
- /**
16
- * JestTestFixture with additional functions that the JestTestContextFactory sees for managing the instance.
17
- *
18
- * The fixture is used as a refernce point for the Instance that is changed between each test.
19
- */
20
- export interface JestTestContextFixture<I> extends JestTestFixture<I> {
21
- /**
22
- * Sets the instance before the tests run, and returns a function to clean the instance later.
23
- *
24
- * If called again before the instance is finished being used, this should thrown an exception.
25
- *
26
- * @param instance
27
- */
28
- setInstance(instance: I): JestTestContextFixtureClearInstanceFunction;
29
- }
30
- /**
31
- * Abstract JestTestContextFixture instance.
32
- */
33
- export declare abstract class AbstractJestTestContextFixture<I> implements JestTestContextFixture<I> {
34
- private _instance?;
35
- get instance(): I;
36
- setInstance(instance: I): JestTestContextFixtureClearInstanceFunction;
37
- }
38
- /**
39
- * Abstract JestTestContextFixture instance with a parent.
40
- */
41
- export declare abstract class AbstractChildJestTestContextFixture<I, P extends JestTestContextFixture<any>> extends AbstractJestTestContextFixture<I> {
42
- readonly parent: P;
43
- constructor(parent: P);
44
- }
45
- export type JestBuildTestsWithContextFunction<F> = (fixture: F) => void;
46
- /**
47
- * Used for Jest tests to execute a number of tests using the fixture.
48
- *
49
- * The fixture is automatically setup and torn down each test per the configuration with a clean fixture instance.
50
- */
51
- export type JestTestContextFactory<F> = (buildTests: JestBuildTestsWithContextFunction<F>) => void;
52
- /**
53
- * Used to configure a JestTestContextFactory for building tests.
54
- */
55
- export type JestTestContextBuilderFunction<I, F extends JestTestContextFixture<I>, C> = (config?: Partial<C>) => JestTestContextFactory<F>;
56
- export interface JestTestContextBuilderConfig<I, F extends JestTestContextFixture<I>, C> {
57
- /**
58
- * Builds a config given the optional, partial input config. This is used across all tests.
59
- */
60
- buildConfig: (config?: Partial<C>) => C;
61
- /**
62
- * Builds a new fixture to use across all encapsulated tests.
63
- */
64
- buildFixture: (config: C) => F;
65
- /**
66
- * Arbitrary before each function, called before the instance is setup.
67
- */
68
- beforeEach?: () => Promise<void>;
69
- /**
70
- * Use for building an instance.
71
- *
72
- * When the promise resolves it should be ready to be used by the test being executed.
73
- */
74
- setupInstance: (config: C) => Promise<I>;
75
- /**
76
- * Use for cleaning up the instance before the next test.
77
- */
78
- teardownInstance: (instance: I, config: C) => Promise<void>;
79
- /**
80
- * Arbitrary after each function.
81
- */
82
- afterEach?: () => Promise<void>;
83
- }
84
- /**
85
- * Creates a JestTestContextBuilderFunction given the input builder.
86
- *
87
- * @param builder
88
- * @returns
89
- */
90
- export declare function jestTestContextBuilder<I, F extends JestTestContextFixture<I>, C>(builder: JestTestContextBuilderConfig<I, F, C>): JestTestContextBuilderFunction<I, F, C>;
91
- export interface UseJestContextFixture<C extends JestTestContextFixture<I>, I> {
92
- readonly fixture: C;
93
- readonly buildTests: JestBuildTestsWithContextFunction<C>;
94
- initInstance(): PromiseOrValue<I>;
95
- destroyInstance?(instance: I): PromiseOrValue<void>;
96
- }
97
- /**
98
- * Creates a test context and jest configurations that will initialize an instance
99
- */
100
- export declare function useJestContextFixture<C extends JestTestContextFixture<I>, I>(config: UseJestContextFixture<C, I>): void;
@@ -1,104 +0,0 @@
1
- /**
2
- * https://github.com/facebook/jest/issues/11698
3
- *
4
- * Since fail() was silently removed, we redefine it.
5
- */
6
- import { type PromiseReference, type PromiseOrValue, type ClassType, type Maybe, type ClassLikeType } from '@dereekb/util';
7
- import { BaseError } from 'make-error';
8
- export interface JestDoneCallback {
9
- (...args: any[]): any;
10
- /**
11
- * NOTE: Not typically available in Jest, but here for legacy purposes.
12
- *
13
- * @param error
14
- */
15
- fail(error?: string | {
16
- message: string;
17
- }): any;
18
- }
19
- /**
20
- * Passes the error to the JestDoneCallback.
21
- * @param done
22
- * @param e
23
- */
24
- export declare function failWithJestDoneCallback(done: JestDoneCallback, e?: unknown): void;
25
- export type JestProvidesCallbackWithDone = (cb: JestDoneCallback) => void | undefined;
26
- export type JestProvidesCallback = JestProvidesCallbackWithDone | (() => Promise<unknown>);
27
- /**
28
- * Error thrown by fail() and used by expectError()
29
- */
30
- export declare class JestExpectedFailError extends BaseError {
31
- }
32
- export declare function failSuccessfullyError(message?: string): JestExpectedFailError;
33
- export declare function failSuccessfully(message?: string): never;
34
- /**
35
- * Error thrown when success occurs when it should not have.
36
- */
37
- export declare class JestUnexpectedSuccessFailureError extends BaseError {
38
- }
39
- export declare function failDueToSuccessError(message?: string): JestUnexpectedSuccessFailureError;
40
- /**
41
- * Error thrown when the error type was different than the expected type.
42
- */
43
- export declare class JestExpectedErrorOfSpecificTypeError extends BaseError {
44
- readonly encounteredType: unknown;
45
- readonly expectedType?: Maybe<ClassLikeType | string>;
46
- constructor(encounteredType: unknown, expectedType?: Maybe<ClassLikeType | string>);
47
- }
48
- export declare function failTest(message?: string): never;
49
- export declare function failDueToSuccess(): never;
50
- export declare function failWithDoneDueToSuccess(done: JestDoneCallback): void;
51
- export declare function EXPECT_ERROR_DEFAULT_HANDLER(e: unknown): void;
52
- /**
53
- * Used to assert additional information about the expected error.
54
- *
55
- * Can assert within this function, or return a boolean. A boolean returning false means the test should throw a JestExpectedErrorOfSpecificTypeError.
56
- */
57
- export type JestExpectFailAssertionFunction = (error: unknown) => PromiseOrValue<Maybe<boolean> | void>;
58
- /**
59
- * Creates a JestExpectFailAssertionFunction that asserts the encountered error is of the expected type using the instanceof keyword.
60
- *
61
- * Throws a JestExpectedErrorOfSpecificTypeError on failures.
62
- *
63
- * @param expectedType
64
- * @returns
65
- */
66
- export declare function jestExpectFailAssertErrorType(expectedType: ClassType | ClassLikeType | typeof Error | any): JestExpectFailAssertionFunction;
67
- /**
68
- * Function that expects any failure to be thrown, then throws a JestExpectedFailError.
69
- *
70
- * @param errorFn
71
- * @param handleError
72
- */
73
- export declare function expectFail(errorFn: () => void, assertFailType?: JestExpectFailAssertionFunction): void;
74
- export declare function expectFail(errorFn: () => Promise<void>, assertFailType?: JestExpectFailAssertionFunction): Promise<void>;
75
- /**
76
- * Function that expects a JestExpectedFailError to be thrown.
77
- *
78
- * @param errorFn
79
- * @param handleError
80
- */
81
- export declare function expectSuccessfulFail(errorFn: () => void, handleError?: (e: unknown) => void): void;
82
- export declare function expectSuccessfulFail(errorFn: () => Promise<void>, handleError?: (e: unknown) => void): Promise<void>;
83
- export interface JestShouldFailDoneCallback extends JestDoneCallback {
84
- failSuccessfully(): void;
85
- }
86
- export type JestShouldFailProvidesCallbackWithDone = (cb: JestShouldFailDoneCallback) => void | undefined;
87
- export type JestShouldFailProvidesCallbackWithResult = () => PromiseOrValue<unknown>;
88
- export type JestShouldFailProvidesCallback = JestShouldFailProvidesCallbackWithDone | JestShouldFailProvidesCallbackWithResult;
89
- /**
90
- * Used to wrap a Jest testing function and watch for JestExpectedFailError errors in order to pass the test. Other exceptions are treated normally as failures.
91
- *
92
- * This is typically used in conjunction with failSuccessfully(), expectSuccessfulFail(), or expectFail().
93
- *
94
- * @param fn
95
- * @param strict
96
- * @returns
97
- */
98
- export declare function shouldFail(fn: JestShouldFailProvidesCallback): JestProvidesCallback;
99
- export declare function itShouldFail(fn: JestShouldFailProvidesCallback): void;
100
- export declare function itShouldFail(describe: string, fn: JestShouldFailProvidesCallback): void;
101
- export interface JestFakeDoneHandler extends JestDoneCallback, PromiseReference {
102
- _ref: PromiseReference;
103
- }
104
- export declare function fakeDoneHandler(): JestFakeDoneHandler;
@@ -1,224 +0,0 @@
1
- "use strict";
2
- /**
3
- * https://github.com/facebook/jest/issues/11698
4
- *
5
- * Since fail() was silently removed, we redefine it.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.JestExpectedErrorOfSpecificTypeError = exports.JestUnexpectedSuccessFailureError = exports.JestExpectedFailError = void 0;
9
- exports.failWithJestDoneCallback = failWithJestDoneCallback;
10
- exports.failSuccessfullyError = failSuccessfullyError;
11
- exports.failSuccessfully = failSuccessfully;
12
- exports.failDueToSuccessError = failDueToSuccessError;
13
- exports.failTest = failTest;
14
- exports.failDueToSuccess = failDueToSuccess;
15
- exports.failWithDoneDueToSuccess = failWithDoneDueToSuccess;
16
- exports.EXPECT_ERROR_DEFAULT_HANDLER = EXPECT_ERROR_DEFAULT_HANDLER;
17
- exports.jestExpectFailAssertErrorType = jestExpectFailAssertErrorType;
18
- exports.expectFail = expectFail;
19
- exports.expectSuccessfulFail = expectSuccessfulFail;
20
- exports.shouldFail = shouldFail;
21
- exports.itShouldFail = itShouldFail;
22
- exports.fakeDoneHandler = fakeDoneHandler;
23
- const util_1 = require("@dereekb/util");
24
- const make_error_1 = require("make-error");
25
- /**
26
- * Passes the error to the JestDoneCallback.
27
- * @param done
28
- * @param e
29
- */
30
- function failWithJestDoneCallback(done, e = new Error('failed test')) {
31
- if (done.fail != null) {
32
- done.fail(e);
33
- }
34
- else {
35
- done(e);
36
- }
37
- }
38
- // MARK: Errors
39
- /**
40
- * Error thrown by fail() and used by expectError()
41
- */
42
- class JestExpectedFailError extends make_error_1.BaseError {
43
- }
44
- exports.JestExpectedFailError = JestExpectedFailError;
45
- function failSuccessfullyError(message) {
46
- return new JestExpectedFailError(message);
47
- }
48
- function failSuccessfully(message) {
49
- throw failSuccessfullyError(message);
50
- }
51
- /**
52
- * Error thrown when success occurs when it should not have.
53
- */
54
- class JestUnexpectedSuccessFailureError extends make_error_1.BaseError {
55
- }
56
- exports.JestUnexpectedSuccessFailureError = JestUnexpectedSuccessFailureError;
57
- function failDueToSuccessError(message) {
58
- return new JestUnexpectedSuccessFailureError(message ?? 'expected an error to occur but was successful instead');
59
- }
60
- /**
61
- * Error thrown when the error type was different than the expected type.
62
- */
63
- class JestExpectedErrorOfSpecificTypeError extends make_error_1.BaseError {
64
- encounteredType;
65
- expectedType;
66
- constructor(encounteredType, expectedType) {
67
- super(`The error encountered was not of the expected type. Expected: ${expectedType ?? 'n/a'}, but encountered: ${encounteredType} `);
68
- this.encounteredType = encounteredType;
69
- this.expectedType = expectedType;
70
- }
71
- }
72
- exports.JestExpectedErrorOfSpecificTypeError = JestExpectedErrorOfSpecificTypeError;
73
- function failTest(message) {
74
- throw failDueToSuccessError(message);
75
- }
76
- function failDueToSuccess() {
77
- throw failDueToSuccessError();
78
- }
79
- function failWithDoneDueToSuccess(done) {
80
- failWithJestDoneCallback(done, failDueToSuccessError());
81
- }
82
- function EXPECT_ERROR_DEFAULT_HANDLER(e) {
83
- if (e instanceof JestExpectedFailError) {
84
- // success
85
- }
86
- else {
87
- throw e;
88
- }
89
- }
90
- /**
91
- * Creates a JestExpectFailAssertionFunction that asserts the encountered error is of the expected type using the instanceof keyword.
92
- *
93
- * Throws a JestExpectedErrorOfSpecificTypeError on failures.
94
- *
95
- * @param expectedType
96
- * @returns
97
- */
98
- function jestExpectFailAssertErrorType(expectedType) {
99
- return (error) => {
100
- if (!(error instanceof expectedType)) {
101
- throw new JestExpectedErrorOfSpecificTypeError(error, expectedType);
102
- }
103
- };
104
- }
105
- function expectFail(errorFn, assertFailType) {
106
- function handleError(e) {
107
- if (e instanceof JestUnexpectedSuccessFailureError) {
108
- throw e;
109
- }
110
- else {
111
- const assertionResult = assertFailType?.(e);
112
- if (assertionResult === false) {
113
- throw new JestExpectedErrorOfSpecificTypeError(e);
114
- }
115
- failSuccessfully();
116
- }
117
- }
118
- try {
119
- const result = errorFn();
120
- if ((0, util_1.isPromise)(result)) {
121
- return result.then(failDueToSuccess).catch(handleError);
122
- }
123
- else {
124
- failDueToSuccess();
125
- }
126
- }
127
- catch (e) {
128
- handleError(e);
129
- }
130
- }
131
- function expectSuccessfulFail(errorFn, handleError = EXPECT_ERROR_DEFAULT_HANDLER) {
132
- try {
133
- const result = errorFn();
134
- if ((0, util_1.isPromise)(result)) {
135
- return result.then(failDueToSuccess).catch(handleError);
136
- }
137
- else {
138
- failDueToSuccess();
139
- }
140
- }
141
- catch (e) {
142
- handleError(e);
143
- }
144
- }
145
- /**
146
- * Used to wrap a Jest testing function and watch for JestExpectedFailError errors in order to pass the test. Other exceptions are treated normally as failures.
147
- *
148
- * This is typically used in conjunction with failSuccessfully(), expectSuccessfulFail(), or expectFail().
149
- *
150
- * @param fn
151
- * @param strict
152
- * @returns
153
- */
154
- function shouldFail(fn) {
155
- const usesDoneCallback = fn.length > 0;
156
- return (done) => {
157
- function handleError(e) {
158
- if (!(e instanceof JestExpectedFailError)) {
159
- failWithJestDoneCallback(done, e);
160
- }
161
- else {
162
- done();
163
- }
164
- }
165
- expectSuccessfulFail(() => {
166
- let result;
167
- if (usesDoneCallback) {
168
- const fakeDone = (0, util_1.build)({
169
- base: fakeDoneHandler(),
170
- build: (x) => {
171
- x.failSuccessfully = () => {
172
- fakeDone(failSuccessfullyError());
173
- };
174
- }
175
- });
176
- const callbackWithDoneResult = fn(fakeDone);
177
- if ((0, util_1.isPromise)(callbackWithDoneResult)) {
178
- fakeDone.reject(new Error('Configured to use "done" value while returning a promise. Configure your test to use one or the other.'));
179
- }
180
- // return the fake done promise. Done/fail will resolve as a promise.
181
- result = fakeDone._ref.promise;
182
- }
183
- else {
184
- result = fn();
185
- }
186
- return result;
187
- }, handleError);
188
- };
189
- }
190
- function itShouldFail(describeOrFn, fn) {
191
- let description;
192
- if (typeof describeOrFn === 'string') {
193
- description = `should fail ${describeOrFn}`;
194
- }
195
- else {
196
- fn = describeOrFn;
197
- description = 'should fail';
198
- }
199
- it(description, shouldFail(fn));
200
- }
201
- function fakeDoneHandler() {
202
- const promiseRef = (0, util_1.promiseReference)();
203
- const doneHandler = promiseRef.resolve;
204
- const failHandler = (e) => {
205
- promiseRef.reject(e);
206
- };
207
- const fakeDone = (error) => {
208
- if (error) {
209
- failHandler(error);
210
- }
211
- else {
212
- doneHandler(0);
213
- }
214
- };
215
- fakeDone.fail = (error) => {
216
- failHandler(error);
217
- };
218
- fakeDone._ref = promiseRef;
219
- fakeDone.promise = promiseRef.promise;
220
- fakeDone.resolve = promiseRef.resolve;
221
- fakeDone.reject = promiseRef.reject;
222
- return fakeDone;
223
- }
224
- //# sourceMappingURL=jest.fail.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.fail.js","sourceRoot":"","sources":["../../../../../../packages/util/test/src/lib/jest.fail.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAqBH,4DAMC;AAWD,sDAEC;AAED,4CAEC;AAOD,sDAEC;AAcD,4BAEC;AAED,4CAEC;AAED,4DAEC;AAED,oEAMC;AAkBD,sEAMC;AAUD,gCA0BC;AAUD,oDAYC;AAoBD,gCAwCC;AAKD,oCAWC;AAOD,0CA0BC;AAlRD,wCAA8K;AAC9K,2CAAuC;AAavC;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,IAAsB,EAAE,IAAa,IAAI,KAAK,CAAC,aAAa,CAAC;IACpG,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,CAAU,CAAC,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AAKD,eAAe;AACf;;GAEG;AACH,MAAa,qBAAsB,SAAQ,sBAAS;CAAG;AAAvD,sDAAuD;AAEvD,SA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WAAW,CAAC;IAEhB,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,WAAW,GAAG,eAAe,YAAY,EAAE,CAAC;IAC9C,CAAC;SAAM,CAAC;QACN,EAAE,GAAG,YAAY,CAAC;QAClB,WAAW,GAAG,aAAa,CAAC;IAC9B,CAAC;IAED,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,EAAoC,CAAC,CAAC,CAAC;AACpE,CAAC;AAOD,SAAgB,eAAe;IAC7B,MAAM,UAAU,GAAG,IAAA,uBAAgB,GAAE,CAAC;IAEtC,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IACvC,MAAM,WAAW,GAAG,CAAC,CAAU,EAAE,EAAE;QACjC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAkC,CAAC,KAAoC,EAAE,EAAE;QACvF,IAAI,KAAK,EAAE,CAAC;YACV,WAAW,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;IACH,CAAC,CAAC;IAEF,QAAQ,CAAC,IAAI,GAAG,CAAC,KAAoC,EAAE,EAAE;QACvD,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC;IAEF,QAAQ,CAAC,IAAI,GAAG,UAAU,CAAC;IAC3B,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACtC,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACtC,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAEpC,OAAO,QAA+B,CAAC;AACzC,CAAC"}
@@ -1,25 +0,0 @@
1
- import { type Getter } from '@dereekb/util';
2
- export type UseJestFunctionFixtureFunctionGetter<I extends (...args: any[]) => O, O = any> = Getter<I>;
3
- export interface UseJestFunctionFixture<I extends (...args: any[]) => O, O = any> {
4
- fn: Getter<I>;
5
- }
6
- export type JestFunctionFixtureBuildTests<I> = (fn: I) => void;
7
- /**
8
- * Creates a test context and jest configurations that provides a function to build tests based on the configuration.
9
- */
10
- export declare function useJestFunctionFixture<I extends (...args: any[]) => O, O = any>(config: UseJestFunctionFixture<I, O>, buildTests: JestFunctionFixtureBuildTests<I>): void;
11
- export type UseJestFunctionMapObject = Record<string, (...args: any[]) => any>;
12
- export type UseJestFunctionMapFixture<T extends UseJestFunctionMapObject> = {
13
- fns: UseJestFunctionMapFixtureGetterFunctions<T>;
14
- };
15
- export type UseJestFunctionMapFixtureGetterFunctions<T extends UseJestFunctionMapObject> = {
16
- [K in keyof T]: T[K] extends UseJestFunctionFixtureFunctionGetter<infer I, infer O> ? T[K] : never;
17
- };
18
- export type UseJestFunctionMapFixtureFunctions<T extends UseJestFunctionMapObject> = {
19
- [K in keyof T]: T[K] extends UseJestFunctionFixtureFunctionGetter<infer I, infer O> ? I : never;
20
- };
21
- export type JestFunctionFixtureMapBuildTests<T extends UseJestFunctionMapObject> = (fixture: UseJestFunctionMapFixtureFunctions<T>) => void;
22
- /**
23
- * Creates a test context and jest configurations that provides a function to build tests based on the configuration.
24
- */
25
- export declare function useJestFunctionMapFixture<T extends UseJestFunctionMapObject>(config: UseJestFunctionMapFixture<T>, buildTests: JestFunctionFixtureMapBuildTests<T>): void;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useJestFunctionFixture = useJestFunctionFixture;
4
- exports.useJestFunctionMapFixture = useJestFunctionMapFixture;
5
- const util_1 = require("@dereekb/util");
6
- /**
7
- * Creates a test context and jest configurations that provides a function to build tests based on the configuration.
8
- */
9
- function useJestFunctionFixture(config, buildTests) {
10
- const { fn } = config;
11
- const forward = (0, util_1.forwardFunction)(fn);
12
- buildTests(forward);
13
- }
14
- /**
15
- * Creates a test context and jest configurations that provides a function to build tests based on the configuration.
16
- */
17
- function useJestFunctionMapFixture(config, buildTests) {
18
- const forwardedFunctions = (0, util_1.mapObjectMap)(config.fns, (fn) => (0, util_1.forwardFunction)(fn));
19
- buildTests(forwardedFunctions);
20
- }
21
- //# sourceMappingURL=jest.function.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.function.js","sourceRoot":"","sources":["../../../../../../packages/util/test/src/lib/jest.function.ts"],"names":[],"mappings":";;AAaA,wDAKC;AAsBD,8DAGC;AA3CD,wCAA2E;AAU3E;;GAEG;AACH,SAAgB,sBAAsB,CAA2C,MAAoC,EAAE,UAA4C;IACjK,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;IAEtB,MAAM,OAAO,GAAG,IAAA,sBAAe,EAAC,EAAE,CAAC,CAAC;IACpC,UAAU,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC;AAmBD;;GAEG;AACH,SAAgB,yBAAyB,CAAqC,MAAoC,EAAE,UAA+C;IACjK,MAAM,kBAAkB,GAAG,IAAA,mBAAY,EAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAA,sBAAe,EAAC,EAAE,CAAC,CAAC,CAAC;IACjF,UAAU,CAAC,kBAAkB,CAAC,CAAC;AACjC,CAAC"}
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractChildJestTestContextFixture = exports.AbstractJestTestContextFixture = void 0;
4
- exports.jestTestContextBuilder = jestTestContextBuilder;
5
- exports.useJestContextFixture = useJestContextFixture;
6
- /**
7
- * Abstract JestTestContextFixture instance.
8
- */
9
- class AbstractJestTestContextFixture {
10
- _instance;
11
- get instance() {
12
- return this._instance;
13
- }
14
- setInstance(instance) {
15
- if (this._instance != null) {
16
- throw new Error(`The testing fixture is locked. Don't call setInstance() directly.`);
17
- }
18
- this._instance = instance;
19
- return () => {
20
- delete this._instance;
21
- };
22
- }
23
- }
24
- exports.AbstractJestTestContextFixture = AbstractJestTestContextFixture;
25
- /**
26
- * Abstract JestTestContextFixture instance with a parent.
27
- */
28
- class AbstractChildJestTestContextFixture extends AbstractJestTestContextFixture {
29
- parent;
30
- constructor(parent) {
31
- super();
32
- this.parent = parent;
33
- }
34
- }
35
- exports.AbstractChildJestTestContextFixture = AbstractChildJestTestContextFixture;
36
- /**
37
- * Creates a JestTestContextBuilderFunction given the input builder.
38
- *
39
- * @param builder
40
- * @returns
41
- */
42
- function jestTestContextBuilder(builder) {
43
- return (inputConfig) => {
44
- const config = builder.buildConfig(inputConfig);
45
- return (buildTests) => {
46
- const fixture = builder.buildFixture(config);
47
- // add before each
48
- if (builder.beforeEach != null) {
49
- beforeEach(builder.beforeEach);
50
- }
51
- // add tests
52
- useJestContextFixture({
53
- fixture,
54
- /**
55
- * Build tests by passing the fixture to the testing functions.
56
- *
57
- * This will inject all tests and sub Jest lifecycle items.
58
- */
59
- buildTests,
60
- initInstance: () => builder.setupInstance(config),
61
- destroyInstance: (instance) => builder.teardownInstance(instance, config)
62
- });
63
- // add after each
64
- if (builder.afterEach != null) {
65
- afterEach(builder.afterEach);
66
- }
67
- };
68
- };
69
- }
70
- /**
71
- * Creates a test context and jest configurations that will initialize an instance
72
- */
73
- function useJestContextFixture(config) {
74
- const { buildTests, fixture, initInstance, destroyInstance } = config;
75
- let clearInstance;
76
- let instance;
77
- // Create an instance
78
- beforeEach(async () => {
79
- try {
80
- instance = await initInstance();
81
- clearInstance = fixture.setInstance(instance);
82
- }
83
- catch (e) {
84
- console.error('Failed building a test instance due to an error in buildInstance(). Error: ', e);
85
- if (clearInstance) {
86
- clearInstance();
87
- }
88
- throw e;
89
- }
90
- });
91
- // Declare tests
92
- buildTests(fixture);
93
- // Cleanup
94
- afterEach(async () => {
95
- if (clearInstance) {
96
- clearInstance();
97
- }
98
- if (fixture.instance != null) {
99
- console.warn('Expected instance to be set on fixture for cleanup but was set to something else.');
100
- }
101
- if (destroyInstance) {
102
- try {
103
- await destroyInstance(instance);
104
- instance = undefined;
105
- }
106
- catch (e) {
107
- console.error('Failed due to error in destroyInstance()');
108
- throw e;
109
- }
110
- }
111
- });
112
- }
113
- //# sourceMappingURL=jest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.js","sourceRoot":"","sources":["../../../../../../packages/util/test/src/lib/jest.ts"],"names":[],"mappings":";;;AAwHA,wDA+BC;AAYD,sDA6CC;AA9KD;;GAEG;AACH,MAAsB,8BAA8B;IAC1C,SAAS,CAAK;IAEtB,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAU,CAAC;IACzB,CAAC;IAED,WAAW,CAAC,QAAW;QACrB,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACvF,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAE1B,OAAO,GAAG,EAAE;YACV,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC;CACF;AAlBD,wEAkBC;AAED;;GAEG;AACH,MAAsB,mCAA8E,SAAQ,8BAAiC;IACtH;IAArB,YAAqB,MAAS;QAC5B,KAAK,EAAE,CAAC;QADW,WAAM,GAAN,MAAM,CAAG;IAE9B,CAAC;CACF;AAJD,kFAIC;AAkDD;;;;;GAKG;AACH,SAAgB,sBAAsB,CAA4C,OAA8C;IAC9H,OAAO,CAAC,WAAwB,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAEhD,OAAO,CAAC,UAAgD,EAAE,EAAE;YAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAE7C,kBAAkB;YAClB,IAAI,OAAO,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;gBAC/B,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACjC,CAAC;YAED,YAAY;YACZ,qBAAqB,CAAC;gBACpB,OAAO;gBACP;;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