@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.
- package/LICENSE +1 -1
- package/fetch/LICENSE +1 -1
- package/fetch/index.cjs.js +42 -2529
- package/fetch/index.esm.js +44 -2530
- package/fetch/package.json +21 -16
- package/fetch/src/lib/fetch.page.d.ts +0 -4
- package/fetch/src/lib/fetch.url.d.ts +0 -8
- package/fetch/src/lib/provider.d.ts +0 -4
- package/index.cjs.js +36 -2354
- package/index.esm.js +39 -2344
- package/package.json +18 -7
- package/src/lib/array/array.boolean.d.ts +0 -11
- package/src/lib/array/array.value.d.ts +0 -18
- package/src/lib/boolean.d.ts +1 -1
- package/src/lib/date/date.d.ts +0 -8
- package/src/lib/date/date.unix.d.ts +6 -30
- package/src/lib/date/expires.d.ts +4 -4
- package/src/lib/date/hour.d.ts +1 -1
- package/src/lib/date/time.d.ts +0 -4
- package/src/lib/key.d.ts +4 -0
- package/src/lib/object/object.map.d.ts +0 -9
- package/src/lib/page/index.d.ts +0 -1
- package/src/lib/promise/promise.d.ts +2 -3
- package/src/lib/set/set.hashset.d.ts +4 -4
- package/src/lib/storage/storage.d.ts +2 -2
- package/src/lib/string/mimetype.d.ts +0 -8
- package/src/lib/string/replace.d.ts +11 -1
- package/src/lib/tree/tree.flatten.d.ts +0 -10
- package/src/lib/value/indexed.d.ts +1 -1
- package/src/lib/value/maybe.type.d.ts +3 -3
- package/src/lib/value/point.d.ts +2 -2
- package/test/LICENSE +21 -0
- package/test/index.cjs.js +707 -0
- package/test/index.esm.js +664 -0
- package/test/package.json +20 -6
- package/test/src/lib/index.d.ts +1 -3
- package/test/src/lib/jest/index.d.ts +4 -0
- package/test/src/lib/jest/jest.d.ts +55 -0
- package/test/src/lib/jest/jest.fail.d.ts +72 -0
- package/test/src/lib/jest/jest.function.d.ts +41 -0
- package/test/src/lib/jest/jest.wrap.d.ts +24 -0
- package/test/src/lib/shared/index.d.ts +4 -0
- package/test/src/lib/shared/shared.d.ts +154 -0
- package/test/src/lib/shared/shared.fail.d.ts +83 -0
- package/test/src/lib/shared/shared.function.d.ts +25 -0
- package/test/src/lib/{jest.wrap.d.ts → shared/shared.wrap.d.ts} +9 -9
- package/index.esm.d.ts +0 -1
- package/src/lib/page/page.calculator.d.ts +0 -29
- package/test/CHANGELOG.md +0 -1956
- package/test/src/index.js +0 -5
- package/test/src/index.js.map +0 -1
- package/test/src/lib/index.js +0 -8
- package/test/src/lib/index.js.map +0 -1
- package/test/src/lib/jest.d.ts +0 -100
- package/test/src/lib/jest.fail.d.ts +0 -104
- package/test/src/lib/jest.fail.js +0 -224
- package/test/src/lib/jest.fail.js.map +0 -1
- package/test/src/lib/jest.function.d.ts +0 -25
- package/test/src/lib/jest.function.js +0 -21
- package/test/src/lib/jest.function.js.map +0 -1
- package/test/src/lib/jest.js +0 -113
- package/test/src/lib/jest.js.map +0 -1
- package/test/src/lib/jest.wrap.js +0 -70
- package/test/src/lib/jest.wrap.js.map +0 -1
- /package/fetch/{index.cjs.d.ts → index.d.ts} +0 -0
- /package/{fetch/index.esm.d.ts → index.d.ts} +0 -0
- /package/{index.cjs.d.ts → test/index.d.ts} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type TestFixtureInstance, type TestFixture, type TestContextFixtureClearInstanceFunction, type TestContextFixture, AbstractTestContextFixture, AbstractChildTestContextFixture, type BuildTestsWithContextFunction, type TestContextFactory, type TestContextBuilderFunction, type TestContextBuilderConfig, testContextBuilder, type UseContextFixture, useTestContextFixture } from '../shared/shared';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use TestFixtureInstance from shared instead. This is kept for backwards compatibility.
|
|
4
|
+
*/
|
|
5
|
+
export type JestTestFixtureInstance<I> = TestFixtureInstance<I>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use TestFixture from shared instead. This is kept for backwards compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export type JestTestFixture<I> = TestFixture<I>;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use TestContextFixtureClearInstanceFunction from shared instead. This is kept for backwards compatibility.
|
|
12
|
+
*/
|
|
13
|
+
export type JestTestContextFixtureClearInstanceFunction = TestContextFixtureClearInstanceFunction;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use TestContextFixture from shared instead. This is kept for backwards compatibility.
|
|
16
|
+
*/
|
|
17
|
+
export type JestTestContextFixture<I> = TestContextFixture<I>;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use AbstractTestContextFixture from shared instead. This is kept for backwards compatibility.
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class AbstractJestTestContextFixture<I> extends AbstractTestContextFixture<I> {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use AbstractChildTestContextFixture from shared instead. This is kept for backwards compatibility.
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class AbstractChildJestTestContextFixture<I, P extends TestContextFixture<any>> extends AbstractChildTestContextFixture<I, P> {
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use BuildTestsWithContextFunction from shared instead. This is kept for backwards compatibility.
|
|
30
|
+
*/
|
|
31
|
+
export type JestBuildTestsWithContextFunction<F> = BuildTestsWithContextFunction<F>;
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use TestContextFactory from shared instead. This is kept for backwards compatibility.
|
|
34
|
+
*/
|
|
35
|
+
export type JestTestContextFactory<F> = TestContextFactory<F>;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use TestContextBuilderFunction from shared instead. This is kept for backwards compatibility.
|
|
38
|
+
*/
|
|
39
|
+
export type JestTestContextBuilderFunction<I, F extends TestContextFixture<I>, C> = TestContextBuilderFunction<I, F, C>;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use TestContextBuilderConfig from shared instead. This is kept for backwards compatibility.
|
|
42
|
+
*/
|
|
43
|
+
export type JestTestContextBuilderConfig<I, F extends TestContextFixture<I>, C> = TestContextBuilderConfig<I, F, C>;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use testContextBuilder from shared instead. This is kept for backwards compatibility.
|
|
46
|
+
*/
|
|
47
|
+
export declare const jestTestContextBuilder: typeof testContextBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use UseContextFixture from shared instead. This is kept for backwards compatibility.
|
|
50
|
+
*/
|
|
51
|
+
export type UseJestContextFixture<C extends TestContextFixture<I>, I> = UseContextFixture<C, I>;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use useContextFixture from shared instead. This is kept for backwards compatibility.
|
|
54
|
+
*/
|
|
55
|
+
export declare const useJestContextFixture: typeof useTestContextFixture;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://github.com/facebook/jest/issues/11698
|
|
3
|
+
*
|
|
4
|
+
* Since fail() was silently removed, we redefine it.
|
|
5
|
+
*/
|
|
6
|
+
import { type TestDoneCallback, failWithTestDoneCallback, type TestProvidesCallbackWithDone, type TestProvidesCallback } from '../shared';
|
|
7
|
+
import { ExpectedFailError, failSuccessfullyError, failSuccessfully, UnexpectedSuccessFailureError, failDueToSuccessError, ExpectedErrorOfSpecificTypeError, failTest, failDueToSuccess, EXPECT_ERROR_DEFAULT_HANDLER, type ExpectFailAssertionFunction, expectFailAssertErrorType, expectFail, expectSuccessfulFail, type ShouldFailDoneCallback, type ShouldFailProvidesCallbackWithDone, type ShouldFailProvidesCallbackWithResult, type ShouldFailProvidesCallback, type FakeDoneHandler } from '../shared/shared.fail';
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use TestDoneCallback from shared instead. This is kept for backwards compatibility.
|
|
10
|
+
*/
|
|
11
|
+
export type JestDoneCallback = TestDoneCallback;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use failWithTestDoneCallback from shared instead. This is kept for backwards compatibility.
|
|
14
|
+
*/
|
|
15
|
+
export declare const failWithJestDoneCallback: typeof failWithTestDoneCallback;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use TestProvidesCallbackWithDone from shared instead. This is kept for backwards compatibility.
|
|
18
|
+
*/
|
|
19
|
+
export type JestProvidesCallbackWithDone = TestProvidesCallbackWithDone;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use TestProvidesCallback from shared instead. This is kept for backwards compatibility.
|
|
22
|
+
*/
|
|
23
|
+
export type JestProvidesCallback = TestProvidesCallback;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use ExpectedFailError from shared instead. This is kept for backwards compatibility.
|
|
26
|
+
*/
|
|
27
|
+
export declare class JestExpectedFailError extends ExpectedFailError {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use UnexpectedSuccessFailureError from shared instead. This is kept for backwards compatibility.
|
|
31
|
+
*/
|
|
32
|
+
export declare class JestUnexpectedSuccessFailureError extends UnexpectedSuccessFailureError {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use ExpectedErrorOfSpecificTypeError from shared instead. This is kept for backwards compatibility.
|
|
36
|
+
*/
|
|
37
|
+
export declare class JestExpectedErrorOfSpecificTypeError extends ExpectedErrorOfSpecificTypeError {
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use failWithTestDoneCallback with failDueToSuccessError from shared instead. This is kept for backwards compatibility.
|
|
41
|
+
*/
|
|
42
|
+
export declare function failWithDoneDueToSuccess(done: TestDoneCallback): void;
|
|
43
|
+
export { failSuccessfullyError, failSuccessfully, failDueToSuccessError, failTest, failDueToSuccess, EXPECT_ERROR_DEFAULT_HANDLER };
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use ExpectFailAssertionFunction from shared instead. This is kept for backwards compatibility.
|
|
46
|
+
*/
|
|
47
|
+
export type JestExpectFailAssertionFunction = ExpectFailAssertionFunction;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use expectFailAssertErrorType from shared instead. This is kept for backwards compatibility.
|
|
50
|
+
*/
|
|
51
|
+
export declare const jestExpectFailAssertErrorType: typeof expectFailAssertErrorType;
|
|
52
|
+
export { expectFail, expectSuccessfulFail };
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use ShouldFailDoneCallback from shared instead. This is kept for backwards compatibility.
|
|
55
|
+
*/
|
|
56
|
+
export type JestShouldFailDoneCallback = ShouldFailDoneCallback;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use ShouldFailProvidesCallbackWithDone from shared instead. This is kept for backwards compatibility.
|
|
59
|
+
*/
|
|
60
|
+
export type JestShouldFailProvidesCallbackWithDone = ShouldFailProvidesCallbackWithDone;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use ShouldFailProvidesCallbackWithResult from shared instead. This is kept for backwards compatibility.
|
|
63
|
+
*/
|
|
64
|
+
export type JestShouldFailProvidesCallbackWithResult = ShouldFailProvidesCallbackWithResult;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use ShouldFailProvidesCallback from shared instead. This is kept for backwards compatibility.
|
|
67
|
+
*/
|
|
68
|
+
export type JestShouldFailProvidesCallback = ShouldFailProvidesCallback;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use FakeDoneHandler from shared instead. This is kept for backwards compatibility.
|
|
71
|
+
*/
|
|
72
|
+
export type JestFakeDoneHandler = FakeDoneHandler;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type UseTestFunctionFixtureFunctionGetter, type UseTestFunctionFixture, type TestFunctionFixtureBuildTests, useTestFunctionFixture, type UseTestFunctionMapObject, type UseTestFunctionMapFixture, type UseTestFunctionMapFixtureGetterFunctions, type UseTestFunctionMapFixtureFunctions, type TestFunctionFixtureMapBuildTests, useTestFunctionMapFixture } from '../shared/shared.function';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use UseTestFunctionFixtureFunctionGetter from shared instead. This is kept for backwards compatibility.
|
|
4
|
+
*/
|
|
5
|
+
export type UseJestFunctionFixtureFunctionGetter<I extends (...args: any[]) => O, O = any> = UseTestFunctionFixtureFunctionGetter<I, O>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use UseTestFunctionFixture from shared instead. This is kept for backwards compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export type UseJestFunctionFixture<I extends (...args: any[]) => O, O = any> = UseTestFunctionFixture<I, O>;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use TestFunctionFixtureBuildTests from shared instead. This is kept for backwards compatibility.
|
|
12
|
+
*/
|
|
13
|
+
export type JestFunctionFixtureBuildTests<I> = TestFunctionFixtureBuildTests<I>;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use useTestFunctionFixture from shared instead. This is kept for backwards compatibility.
|
|
16
|
+
*/
|
|
17
|
+
export declare const useJestFunctionFixture: typeof useTestFunctionFixture;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use UseTestFunctionMapObject from shared instead. This is kept for backwards compatibility.
|
|
20
|
+
*/
|
|
21
|
+
export type UseJestFunctionMapObject = UseTestFunctionMapObject;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Use UseTestFunctionMapFixture from shared instead. This is kept for backwards compatibility.
|
|
24
|
+
*/
|
|
25
|
+
export type UseJestFunctionMapFixture<T extends UseTestFunctionMapObject> = UseTestFunctionMapFixture<T>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use UseTestFunctionMapFixtureGetterFunctions from shared instead. This is kept for backwards compatibility.
|
|
28
|
+
*/
|
|
29
|
+
export type UseJestFunctionMapFixtureGetterFunctions<T extends UseTestFunctionMapObject> = UseTestFunctionMapFixtureGetterFunctions<T>;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use UseTestFunctionMapFixtureFunctions from shared instead. This is kept for backwards compatibility.
|
|
32
|
+
*/
|
|
33
|
+
export type UseJestFunctionMapFixtureFunctions<T extends UseTestFunctionMapObject> = UseTestFunctionMapFixtureFunctions<T>;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use TestFunctionFixtureMapBuildTests from shared instead. This is kept for backwards compatibility.
|
|
36
|
+
*/
|
|
37
|
+
export type JestFunctionFixtureMapBuildTests<T extends UseTestFunctionMapObject> = TestFunctionFixtureMapBuildTests<T>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use useTestFunctionMapFixture from shared instead. This is kept for backwards compatibility.
|
|
40
|
+
*/
|
|
41
|
+
export declare const useJestFunctionMapFixture: typeof useTestFunctionMapFixture;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type AbstractWrappedFixtureWithInstance, type WrapTestContextConfig, wrapTestContextFactory, type InstanceWrapTestContextConfig, instanceWrapTestContextFactory, type TestWrappedContextFactoryBuilder } from '../shared/shared.wrap';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use TestWrappedContextFactoryBuilder from shared instead. This is kept for backwards compatibility.
|
|
4
|
+
*/
|
|
5
|
+
export type JestTestWrappedContextFactoryBuilder<W, F> = TestWrappedContextFactoryBuilder<W, F>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use WrapTestContextConfig from shared instead. This is kept for backwards compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export type JestWrapTestContextConfig<W, F, E = any> = WrapTestContextConfig<W, F, E>;
|
|
10
|
+
/**
|
|
11
|
+
* Wraps the input JestTestContextFactory to emit another type of Fixture for tests.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Use wrapTestContextFactory from shared instead. This is kept for backwards compatibility.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const wrapJestTestContextFactory: typeof wrapTestContextFactory;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use InstanceWrapTestContextConfig from shared instead. This is kept for backwards compatibility.
|
|
19
|
+
*/
|
|
20
|
+
export type InstanceJestWrapTestContextConfig<I, W extends AbstractWrappedFixtureWithInstance<I, F>, F> = InstanceWrapTestContextConfig<I, W, F>;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use instanceWrapTestContextFactory from shared instead. This is kept for backwards compatibility.
|
|
23
|
+
*/
|
|
24
|
+
export declare const instanceWrapJestTestContextFactory: typeof instanceWrapTestContextFactory;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { type PromiseOrValue, type PromiseReference } from '@dereekb/util';
|
|
2
|
+
/**
|
|
3
|
+
* A done callback function used by test frameworks to signal that a test has completed.
|
|
4
|
+
*
|
|
5
|
+
* Most modern test frameworks have deprecated the "done" callback in favor of async/await.
|
|
6
|
+
*/
|
|
7
|
+
export type TestDoneCallback = ((...args: any[]) => any) & {
|
|
8
|
+
/**
|
|
9
|
+
* NOTE: Not available in all test frameworks, but here for legacy purposes.
|
|
10
|
+
*
|
|
11
|
+
* @param error
|
|
12
|
+
*/
|
|
13
|
+
fail(error?: string | {
|
|
14
|
+
message: string;
|
|
15
|
+
}): any;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Passes the error to the TestDoneCallback.
|
|
19
|
+
* @param done
|
|
20
|
+
* @param e
|
|
21
|
+
*/
|
|
22
|
+
export declare function failWithTestDoneCallback(done: TestDoneCallback, e?: unknown): void;
|
|
23
|
+
export type TestProvidesCallbackWithDone = (cb: TestDoneCallback) => void | undefined;
|
|
24
|
+
export type TestProvidesCallback = TestProvidesCallbackWithDone | (() => Promise<unknown>);
|
|
25
|
+
export type TestDoneCallbackRef = Omit<TestDoneCallback, 'fail'> & {
|
|
26
|
+
readonly _promise: PromiseReference<void>;
|
|
27
|
+
readonly done: TestDoneCallback;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new TestDoneCallbackRef.
|
|
31
|
+
*
|
|
32
|
+
* Used to create a promise reference that can be used to assert that a test function was called.
|
|
33
|
+
*/
|
|
34
|
+
export declare function testDoneCallbackRef(): TestDoneCallbackRef;
|
|
35
|
+
/**
|
|
36
|
+
* Wraps a callback-based test (using done) for Vitest compatibility.
|
|
37
|
+
* Converts the callback pattern to a Promise-based pattern.
|
|
38
|
+
*
|
|
39
|
+
* This also supports calling the input test with async, but still only returns when done is called.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* // Before (Jasmine/Jest style):
|
|
44
|
+
* it('test name', (done) => {
|
|
45
|
+
* // async test code
|
|
46
|
+
* done();
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // After (Vitest compatible):
|
|
50
|
+
* it('test name', callbackTest((done) => {
|
|
51
|
+
* // async test code
|
|
52
|
+
* done();
|
|
53
|
+
* }));
|
|
54
|
+
*/
|
|
55
|
+
export declare function callbackTest(testFn: TestProvidesCallbackWithDone | ((cb: TestDoneCallback) => PromiseOrValue<void | undefined>)): () => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* A fixture instance that is generated new for each test run.
|
|
58
|
+
*/
|
|
59
|
+
export type TestFixtureInstance<I> = I;
|
|
60
|
+
/**
|
|
61
|
+
* The test fixture is used as a singleton across tests used in a single context.
|
|
62
|
+
*
|
|
63
|
+
* This allows us to define tests while referencing the instance.
|
|
64
|
+
*/
|
|
65
|
+
export interface TestFixture<I> {
|
|
66
|
+
readonly instance: TestFixtureInstance<I>;
|
|
67
|
+
}
|
|
68
|
+
export type TestContextFixtureClearInstanceFunction = () => void;
|
|
69
|
+
/**
|
|
70
|
+
* TestFixture with additional functions that the TestContextFactory sees for managing the instance.
|
|
71
|
+
*
|
|
72
|
+
* The fixture is used as a reference point for the Instance that is changed between each test.
|
|
73
|
+
*/
|
|
74
|
+
export interface TestContextFixture<I> extends TestFixture<I> {
|
|
75
|
+
/**
|
|
76
|
+
* Sets the instance before the tests run, and returns a function to clean the instance later.
|
|
77
|
+
*
|
|
78
|
+
* If called again before the instance is finished being used, this should throw an exception.
|
|
79
|
+
*
|
|
80
|
+
* @param instance
|
|
81
|
+
*/
|
|
82
|
+
setInstance(instance: I): TestContextFixtureClearInstanceFunction;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Abstract TestContextFixture instance.
|
|
86
|
+
*/
|
|
87
|
+
export declare abstract class AbstractTestContextFixture<I> implements TestContextFixture<I> {
|
|
88
|
+
private _instance?;
|
|
89
|
+
get instance(): I;
|
|
90
|
+
setInstance(instance: I): TestContextFixtureClearInstanceFunction;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Abstract TestContextFixture instance with a parent.
|
|
94
|
+
*/
|
|
95
|
+
export declare abstract class AbstractChildTestContextFixture<I, P extends TestContextFixture<any>> extends AbstractTestContextFixture<I> {
|
|
96
|
+
readonly parent: P;
|
|
97
|
+
constructor(parent: P);
|
|
98
|
+
}
|
|
99
|
+
export type BuildTestsWithContextFunction<F> = (fixture: F) => void;
|
|
100
|
+
/**
|
|
101
|
+
* Used for tests to execute a number of tests using the fixture.
|
|
102
|
+
*
|
|
103
|
+
* The fixture is automatically setup and torn down each test per the configuration with a clean fixture instance.
|
|
104
|
+
*/
|
|
105
|
+
export type TestContextFactory<F> = (buildTests: BuildTestsWithContextFunction<F>) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Used to configure a TestContextFactory for building tests.
|
|
108
|
+
*/
|
|
109
|
+
export type TestContextBuilderFunction<I, F extends TestContextFixture<I>, C> = (config?: Partial<C>) => TestContextFactory<F>;
|
|
110
|
+
export interface TestContextBuilderConfig<I, F extends TestContextFixture<I>, C> {
|
|
111
|
+
/**
|
|
112
|
+
* Builds a config given the optional, partial input config. This is used across all tests.
|
|
113
|
+
*/
|
|
114
|
+
buildConfig: (config?: Partial<C>) => C;
|
|
115
|
+
/**
|
|
116
|
+
* Builds a new fixture to use across all encapsulated tests.
|
|
117
|
+
*/
|
|
118
|
+
buildFixture: (config: C) => F;
|
|
119
|
+
/**
|
|
120
|
+
* Arbitrary before each function, called before the instance is setup.
|
|
121
|
+
*/
|
|
122
|
+
beforeEach?: () => Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Use for building an instance.
|
|
125
|
+
*
|
|
126
|
+
* When the promise resolves it should be ready to be used by the test being executed.
|
|
127
|
+
*/
|
|
128
|
+
setupInstance: (config: C) => Promise<I>;
|
|
129
|
+
/**
|
|
130
|
+
* Use for cleaning up the instance before the next test.
|
|
131
|
+
*/
|
|
132
|
+
teardownInstance: (instance: I, config: C) => Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Arbitrary after each function.
|
|
135
|
+
*/
|
|
136
|
+
afterEach?: () => Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates a TestContextBuilderFunction given the input builder.
|
|
140
|
+
*
|
|
141
|
+
* @param builder
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
export declare function testContextBuilder<I, F extends TestContextFixture<I>, C>(builder: TestContextBuilderConfig<I, F, C>): TestContextBuilderFunction<I, F, C>;
|
|
145
|
+
export interface UseContextFixture<C extends TestContextFixture<I>, I> {
|
|
146
|
+
readonly fixture: C;
|
|
147
|
+
readonly buildTests: BuildTestsWithContextFunction<C>;
|
|
148
|
+
initInstance(): PromiseOrValue<I>;
|
|
149
|
+
destroyInstance?(instance: I): PromiseOrValue<void>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a test context and configurations that will initialize an instance
|
|
153
|
+
*/
|
|
154
|
+
export declare function useTestContextFixture<C extends TestContextFixture<I>, I>(config: UseContextFixture<C, I>): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities for handling expected failures and errors.
|
|
3
|
+
*/
|
|
4
|
+
import { type PromiseReference, type PromiseOrValue, type ClassType, type Maybe, type ClassLikeType } from '@dereekb/util';
|
|
5
|
+
import { BaseError } from 'make-error';
|
|
6
|
+
import { type TestDoneCallback } from './shared';
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown by fail() and used by expectError()
|
|
9
|
+
*/
|
|
10
|
+
export declare class ExpectedFailError extends BaseError {
|
|
11
|
+
}
|
|
12
|
+
export declare function failSuccessfullyError(message?: string): ExpectedFailError;
|
|
13
|
+
export declare function failSuccessfully(message?: string): never;
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when success occurs when it should not have.
|
|
16
|
+
*/
|
|
17
|
+
export declare class UnexpectedSuccessFailureError extends BaseError {
|
|
18
|
+
}
|
|
19
|
+
export declare function failDueToSuccessError(message?: string): UnexpectedSuccessFailureError;
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when the error type was different than the expected type.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ExpectedErrorOfSpecificTypeError extends BaseError {
|
|
24
|
+
readonly encounteredType: unknown;
|
|
25
|
+
readonly expectedType?: Maybe<ClassLikeType | string>;
|
|
26
|
+
constructor(encounteredType: unknown, expectedType?: Maybe<ClassLikeType | string>);
|
|
27
|
+
}
|
|
28
|
+
export declare function failTest(message?: string): never;
|
|
29
|
+
export declare function failDueToSuccess(): never;
|
|
30
|
+
export declare function EXPECT_ERROR_DEFAULT_HANDLER(e: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Used to assert additional information about the expected error.
|
|
33
|
+
*
|
|
34
|
+
* Can assert within this function, or return a boolean. A boolean returning false means the test should throw an ExpectedErrorOfSpecificTypeError.
|
|
35
|
+
*/
|
|
36
|
+
export type ExpectFailAssertionFunction = (error: unknown) => PromiseOrValue<Maybe<boolean> | void>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates an ExpectFailAssertionFunction that asserts the encountered error is of the expected type using the instanceof keyword.
|
|
39
|
+
*
|
|
40
|
+
* Throws an ExpectedErrorOfSpecificTypeError on failures.
|
|
41
|
+
*
|
|
42
|
+
* @param expectedType
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare function expectFailAssertErrorType(expectedType: ClassType | ClassLikeType | typeof Error | any): ExpectFailAssertionFunction;
|
|
46
|
+
/**
|
|
47
|
+
* Function that expects any failure to be thrown, then throws an ExpectedFailError.
|
|
48
|
+
*
|
|
49
|
+
* @param errorFn
|
|
50
|
+
* @param handleError
|
|
51
|
+
*/
|
|
52
|
+
export declare function expectFail(errorFn: () => void, assertFailType?: ExpectFailAssertionFunction): void;
|
|
53
|
+
export declare function expectFail(errorFn: () => Promise<void>, assertFailType?: ExpectFailAssertionFunction): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Function that expects an ExpectedFailError to be thrown.
|
|
56
|
+
*
|
|
57
|
+
* @param errorFn
|
|
58
|
+
* @param handleError
|
|
59
|
+
*/
|
|
60
|
+
export declare function expectSuccessfulFail(errorFn: () => void, handleError?: (e: unknown) => void): void;
|
|
61
|
+
export declare function expectSuccessfulFail(errorFn: () => Promise<void>, handleError?: (e: unknown) => void): Promise<void>;
|
|
62
|
+
export interface ShouldFailDoneCallback extends TestDoneCallback {
|
|
63
|
+
failSuccessfully(): void;
|
|
64
|
+
}
|
|
65
|
+
export type ShouldFailProvidesCallbackWithDone = (cb: ShouldFailDoneCallback) => void | undefined;
|
|
66
|
+
export type ShouldFailProvidesCallbackWithResult = () => PromiseOrValue<unknown>;
|
|
67
|
+
export type ShouldFailProvidesCallback = ShouldFailProvidesCallbackWithDone | ShouldFailProvidesCallbackWithResult;
|
|
68
|
+
/**
|
|
69
|
+
* Used to wrap a testing function and watch for ExpectedFailError errors in order to pass the test. Other exceptions are treated normally as failures.
|
|
70
|
+
*
|
|
71
|
+
* This is typically used in conjunction with failSuccessfully(), expectSuccessfulFail(), or expectFail().
|
|
72
|
+
*
|
|
73
|
+
* @param fn
|
|
74
|
+
* @param strict
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
export declare function shouldFail(fn: ShouldFailProvidesCallback): () => Promise<unknown>;
|
|
78
|
+
export declare function itShouldFail(fn: ShouldFailProvidesCallback): void;
|
|
79
|
+
export declare function itShouldFail(describe: string, fn: ShouldFailProvidesCallback): void;
|
|
80
|
+
export interface FakeDoneHandler extends TestDoneCallback, PromiseReference {
|
|
81
|
+
_ref: PromiseReference;
|
|
82
|
+
}
|
|
83
|
+
export declare function fakeDoneHandler(): FakeDoneHandler;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Getter } from '@dereekb/util';
|
|
2
|
+
export type UseTestFunctionFixtureFunctionGetter<I extends (...args: any[]) => O, O = any> = Getter<I>;
|
|
3
|
+
export interface UseTestFunctionFixture<I extends (...args: any[]) => O, O = any> {
|
|
4
|
+
fn: Getter<I>;
|
|
5
|
+
}
|
|
6
|
+
export type TestFunctionFixtureBuildTests<I> = (fn: I) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a test context and configurations that provides a function to build tests based on the configuration.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useTestFunctionFixture<I extends (...args: any[]) => O, O = any>(config: UseTestFunctionFixture<I, O>, buildTests: TestFunctionFixtureBuildTests<I>): void;
|
|
11
|
+
export type UseTestFunctionMapObject = Record<string, (...args: any[]) => any>;
|
|
12
|
+
export type UseTestFunctionMapFixture<T extends UseTestFunctionMapObject> = {
|
|
13
|
+
fns: UseTestFunctionMapFixtureGetterFunctions<T>;
|
|
14
|
+
};
|
|
15
|
+
export type UseTestFunctionMapFixtureGetterFunctions<T extends UseTestFunctionMapObject> = {
|
|
16
|
+
[K in keyof T]: T[K] extends UseTestFunctionFixtureFunctionGetter<infer I, infer O> ? T[K] : never;
|
|
17
|
+
};
|
|
18
|
+
export type UseTestFunctionMapFixtureFunctions<T extends UseTestFunctionMapObject> = {
|
|
19
|
+
[K in keyof T]: T[K] extends UseTestFunctionFixtureFunctionGetter<infer I, infer O> ? I : never;
|
|
20
|
+
};
|
|
21
|
+
export type TestFunctionFixtureMapBuildTests<T extends UseTestFunctionMapObject> = (fixture: UseTestFunctionMapFixtureFunctions<T>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a test context and configurations that provides a function to build tests based on the configuration.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useTestFunctionMapFixture<T extends UseTestFunctionMapObject>(config: UseTestFunctionMapFixture<T>, buildTests: TestFunctionFixtureMapBuildTests<T>): void;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractTestContextFixture, type TestContextFactory } from './shared';
|
|
2
2
|
export declare abstract class AbstractWrappedFixture<F> {
|
|
3
3
|
readonly fixture: F;
|
|
4
4
|
constructor(fixture: F);
|
|
5
5
|
}
|
|
6
|
-
export declare abstract class AbstractWrappedFixtureWithInstance<I, F> extends
|
|
6
|
+
export declare abstract class AbstractWrappedFixtureWithInstance<I, F> extends AbstractTestContextFixture<I> {
|
|
7
7
|
readonly parent: F;
|
|
8
8
|
constructor(parent: F);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Used to wrap a
|
|
11
|
+
* Used to wrap a TestContextFactory of one fixture type to another.
|
|
12
12
|
*
|
|
13
13
|
* This is useful for cases where the base fixture may be used in a lot of places and contexts, but the wrapped version can configure
|
|
14
14
|
* tests more specifically.
|
|
15
15
|
*/
|
|
16
|
-
export type
|
|
17
|
-
export interface
|
|
16
|
+
export type TestWrappedContextFactoryBuilder<W, F> = (factory: TestContextFactory<F>) => TestContextFactory<W>;
|
|
17
|
+
export interface WrapTestContextConfig<W, F, E = any> {
|
|
18
18
|
/**
|
|
19
19
|
* Wraps the fixture. This occurs once before any tests execute.
|
|
20
20
|
*/
|
|
@@ -35,12 +35,12 @@ export interface JestWrapTestContextConfig<W, F, E = any> {
|
|
|
35
35
|
teardownWrap?: (wrap: W, effect: E) => Promise<void>;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Wraps the input
|
|
38
|
+
* Wraps the input TestContextFactory to emit another type of Fixture for tests.
|
|
39
39
|
*
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
|
-
export declare function
|
|
43
|
-
export interface
|
|
42
|
+
export declare function wrapTestContextFactory<W, F, E = any>(config: WrapTestContextConfig<W, F, E>): (factory: TestContextFactory<F>) => TestContextFactory<W>;
|
|
43
|
+
export interface InstanceWrapTestContextConfig<I, W extends AbstractWrappedFixtureWithInstance<I, F>, F> extends Pick<WrapTestContextConfig<W, F>, 'wrapFixture'> {
|
|
44
44
|
/**
|
|
45
45
|
* Creates a new instance for the tests.
|
|
46
46
|
*/
|
|
@@ -58,4 +58,4 @@ export interface InstanceJestWrapTestContextConfig<I, W extends AbstractWrappedF
|
|
|
58
58
|
*/
|
|
59
59
|
teardownInstance?: (instance: I) => void | Promise<void>;
|
|
60
60
|
}
|
|
61
|
-
export declare function
|
|
61
|
+
export declare function instanceWrapTestContextFactory<I, W extends AbstractWrappedFixtureWithInstance<I, F>, F>(config: InstanceWrapTestContextConfig<I, W, F>): (factory: TestContextFactory<F>) => TestContextFactory<W>;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type PageNumber, type Page } from './page';
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated
|
|
4
|
-
*/
|
|
5
|
-
export interface PageCalculatorConfig {
|
|
6
|
-
pageSize: number;
|
|
7
|
-
limitKey?: string;
|
|
8
|
-
skipKey?: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Page calculation context for calculating the amount to skip/etc.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated
|
|
14
|
-
*/
|
|
15
|
-
export declare class PageCalculator {
|
|
16
|
-
readonly pageSize: number;
|
|
17
|
-
readonly limitKey: string;
|
|
18
|
-
readonly skipKey: string;
|
|
19
|
-
constructor(config: PageCalculatorConfig);
|
|
20
|
-
get limit(): number;
|
|
21
|
-
calcWithPage(page?: Page): {
|
|
22
|
-
[x: string]: number;
|
|
23
|
-
};
|
|
24
|
-
calc(page?: PageNumber): {
|
|
25
|
-
[x: string]: number;
|
|
26
|
-
};
|
|
27
|
-
calcSkipWithPage(page?: Page): number;
|
|
28
|
-
calcSkip(page?: PageNumber): number;
|
|
29
|
-
}
|