@bemedev/dev-utils 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +577 -0
- package/lib/_virtual/_rolldown/runtime.cjs +33 -0
- package/lib/_virtual/_rolldown/runtime.js +13 -0
- package/lib/build-tests/addTarball.cjs +23 -0
- package/lib/build-tests/addTarball.cjs.map +1 -0
- package/lib/build-tests/addTarball.d.ts +1 -0
- package/lib/build-tests/addTarball.js +18 -0
- package/lib/build-tests/addTarball.js.map +1 -0
- package/lib/build-tests/buildPackageJson.cjs +53 -0
- package/lib/build-tests/buildPackageJson.cjs.map +1 -0
- package/lib/build-tests/buildPackageJson.d.ts +8 -0
- package/lib/build-tests/buildPackageJson.js +49 -0
- package/lib/build-tests/buildPackageJson.js.map +1 -0
- package/lib/build-tests/cleanup.cjs +15 -0
- package/lib/build-tests/cleanup.cjs.map +1 -0
- package/lib/build-tests/cleanup.d.ts +1 -0
- package/lib/build-tests/cleanup.js +12 -0
- package/lib/build-tests/cleanup.js.map +1 -0
- package/lib/build-tests/cli/cli.cjs +23 -0
- package/lib/build-tests/cli/cli.cjs.map +1 -0
- package/lib/build-tests/cli/cli.d.ts +52 -0
- package/lib/build-tests/cli/cli.js +20 -0
- package/lib/build-tests/cli/cli.js.map +1 -0
- package/lib/build-tests/cli/index.cjs +8 -0
- package/lib/build-tests/cli/index.cjs.map +1 -0
- package/lib/build-tests/cli/index.d.ts +2 -0
- package/lib/build-tests/cli/index.js +9 -0
- package/lib/build-tests/cli/index.js.map +1 -0
- package/lib/build-tests/cli/post.cjs +18 -0
- package/lib/build-tests/cli/post.cjs.map +1 -0
- package/lib/build-tests/cli/post.d.ts +5 -0
- package/lib/build-tests/cli/post.js +17 -0
- package/lib/build-tests/cli/post.js.map +1 -0
- package/lib/build-tests/cli/pre.cjs +18 -0
- package/lib/build-tests/cli/pre.cjs.map +1 -0
- package/lib/build-tests/cli/pre.d.ts +5 -0
- package/lib/build-tests/cli/pre.js +17 -0
- package/lib/build-tests/cli/pre.js.map +1 -0
- package/lib/build-tests/cli/test.cjs +41 -0
- package/lib/build-tests/cli/test.cjs.map +1 -0
- package/lib/build-tests/cli/test.d.ts +15 -0
- package/lib/build-tests/cli/test.js +38 -0
- package/lib/build-tests/cli/test.js.map +1 -0
- package/lib/build-tests/constants.cjs +42 -0
- package/lib/build-tests/constants.cjs.map +1 -0
- package/lib/build-tests/constants.d.ts +19 -0
- package/lib/build-tests/constants.js +28 -0
- package/lib/build-tests/constants.js.map +1 -0
- package/lib/build-tests/getRelativePath.cjs +13 -0
- package/lib/build-tests/getRelativePath.cjs.map +1 -0
- package/lib/build-tests/getRelativePath.d.ts +4 -0
- package/lib/build-tests/getRelativePath.js +11 -0
- package/lib/build-tests/getRelativePath.js.map +1 -0
- package/lib/build-tests/getTypescriptOutdir.cjs +14 -0
- package/lib/build-tests/getTypescriptOutdir.cjs.map +1 -0
- package/lib/build-tests/getTypescriptOutdir.d.ts +4 -0
- package/lib/build-tests/getTypescriptOutdir.js +11 -0
- package/lib/build-tests/getTypescriptOutdir.js.map +1 -0
- package/lib/build-tests/index.cjs +20 -0
- package/lib/build-tests/index.cjs.map +1 -0
- package/lib/build-tests/index.d.ts +2 -0
- package/lib/build-tests/index.js +12 -0
- package/lib/build-tests/index.js.map +1 -0
- package/lib/build-tests/pack.cjs +25 -0
- package/lib/build-tests/pack.cjs.map +1 -0
- package/lib/build-tests/pack.d.ts +4 -0
- package/lib/build-tests/pack.js +22 -0
- package/lib/build-tests/pack.js.map +1 -0
- package/lib/index.cjs +36 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +6 -0
- package/lib/rolldown-config/config.cjs +86 -0
- package/lib/rolldown-config/config.cjs.map +1 -0
- package/lib/rolldown-config/config.d.ts +2 -0
- package/lib/rolldown-config/config.js +83 -0
- package/lib/rolldown-config/config.js.map +1 -0
- package/lib/rolldown-config/constants.cjs +31 -0
- package/lib/rolldown-config/constants.cjs.map +1 -0
- package/lib/rolldown-config/constants.d.ts +8 -0
- package/lib/rolldown-config/constants.js +26 -0
- package/lib/rolldown-config/constants.js.map +1 -0
- package/lib/rolldown-config/helpers.cjs +37 -0
- package/lib/rolldown-config/helpers.cjs.map +1 -0
- package/lib/rolldown-config/helpers.d.ts +2 -0
- package/lib/rolldown-config/helpers.js +34 -0
- package/lib/rolldown-config/helpers.js.map +1 -0
- package/lib/rolldown-config/index.cjs +22 -0
- package/lib/rolldown-config/index.cjs.map +1 -0
- package/lib/rolldown-config/index.d.ts +3 -0
- package/lib/rolldown-config/index.js +13 -0
- package/lib/rolldown-config/index.js.map +1 -0
- package/lib/rolldown-config/input.cjs +13 -0
- package/lib/rolldown-config/input.cjs.map +1 -0
- package/lib/rolldown-config/input.d.ts +2 -0
- package/lib/rolldown-config/input.js +11 -0
- package/lib/rolldown-config/input.js.map +1 -0
- package/lib/rolldown-config/output.cjs +23 -0
- package/lib/rolldown-config/output.cjs.map +1 -0
- package/lib/rolldown-config/output.d.ts +15 -0
- package/lib/rolldown-config/output.js +22 -0
- package/lib/rolldown-config/output.js.map +1 -0
- package/lib/rolldown-config/plugins/alias.cjs +17 -0
- package/lib/rolldown-config/plugins/alias.cjs.map +1 -0
- package/lib/rolldown-config/plugins/alias.d.ts +25 -0
- package/lib/rolldown-config/plugins/alias.js +14 -0
- package/lib/rolldown-config/plugins/alias.js.map +1 -0
- package/lib/rolldown-config/plugins/circulars.cjs +37 -0
- package/lib/rolldown-config/plugins/circulars.cjs.map +1 -0
- package/lib/rolldown-config/plugins/circulars.d.ts +11 -0
- package/lib/rolldown-config/plugins/circulars.js +35 -0
- package/lib/rolldown-config/plugins/circulars.js.map +1 -0
- package/lib/rolldown-config/plugins/clean.cjs +45 -0
- package/lib/rolldown-config/plugins/clean.cjs.map +1 -0
- package/lib/rolldown-config/plugins/clean.d.ts +15 -0
- package/lib/rolldown-config/plugins/clean.js +43 -0
- package/lib/rolldown-config/plugins/clean.js.map +1 -0
- package/lib/rolldown-config/plugins/externals.cjs +16 -0
- package/lib/rolldown-config/plugins/externals.cjs.map +1 -0
- package/lib/rolldown-config/plugins/externals.d.ts +9 -0
- package/lib/rolldown-config/plugins/externals.js +14 -0
- package/lib/rolldown-config/plugins/externals.js.map +1 -0
- package/lib/rolldown-config/plugins/index.cjs +29 -0
- package/lib/rolldown-config/plugins/index.cjs.map +1 -0
- package/lib/rolldown-config/plugins/index.d.ts +27 -0
- package/lib/rolldown-config/plugins/index.js +27 -0
- package/lib/rolldown-config/plugins/index.js.map +1 -0
- package/lib/rolldown-config/plugins/tsPaths.cjs +17 -0
- package/lib/rolldown-config/plugins/tsPaths.cjs.map +1 -0
- package/lib/rolldown-config/plugins/tsPaths.d.ts +9 -0
- package/lib/rolldown-config/plugins/tsPaths.js +14 -0
- package/lib/rolldown-config/plugins/tsPaths.js.map +1 -0
- package/lib/rolldown-config/plugins/typescript.cjs +56 -0
- package/lib/rolldown-config/plugins/typescript.cjs.map +1 -0
- package/lib/rolldown-config/plugins/typescript.config.cjs +58 -0
- package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -0
- package/lib/rolldown-config/plugins/typescript.config.d.ts +2 -0
- package/lib/rolldown-config/plugins/typescript.config.js +55 -0
- package/lib/rolldown-config/plugins/typescript.config.js.map +1 -0
- package/lib/rolldown-config/plugins/typescript.d.ts +9 -0
- package/lib/rolldown-config/plugins/typescript.js +53 -0
- package/lib/rolldown-config/plugins/typescript.js.map +1 -0
- package/lib/rolldown-config/types.d.ts +20 -0
- package/lib/rolldown-config/utils.cjs +11 -0
- package/lib/rolldown-config/utils.cjs.map +1 -0
- package/lib/rolldown-config/utils.d.ts +2 -0
- package/lib/rolldown-config/utils.js +10 -0
- package/lib/rolldown-config/utils.js.map +1 -0
- package/lib/utils/index.cjs +3 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/sleep.cjs +9 -0
- package/lib/utils/sleep.cjs.map +1 -0
- package/lib/utils/sleep.d.ts +1 -0
- package/lib/utils/sleep.js +8 -0
- package/lib/utils/sleep.js.map +1 -0
- package/lib/utils/types.d.ts +1 -0
- package/lib/vitest-alias/index.cjs +19 -0
- package/lib/vitest-alias/index.cjs.map +1 -0
- package/lib/vitest-alias/index.d.ts +1 -0
- package/lib/vitest-alias/index.js +11 -0
- package/lib/vitest-alias/index.js.map +1 -0
- package/lib/vitest-alias/vitest.cjs +77 -0
- package/lib/vitest-alias/vitest.cjs.map +1 -0
- package/lib/vitest-alias/vitest.d.ts +38 -0
- package/lib/vitest-alias/vitest.js +74 -0
- package/lib/vitest-alias/vitest.js.map +1 -0
- package/lib/vitest-exclude/constants.cjs +7 -0
- package/lib/vitest-exclude/constants.cjs.map +1 -0
- package/lib/vitest-exclude/constants.d.ts +1 -0
- package/lib/vitest-exclude/constants.js +6 -0
- package/lib/vitest-exclude/constants.js.map +1 -0
- package/lib/vitest-exclude/index.cjs +15 -0
- package/lib/vitest-exclude/index.cjs.map +1 -0
- package/lib/vitest-exclude/index.d.ts +1 -0
- package/lib/vitest-exclude/index.js +8 -0
- package/lib/vitest-exclude/index.js.map +1 -0
- package/lib/vitest-exclude/types.d.ts +14 -0
- package/lib/vitest-exclude/vitest.cjs +57 -0
- package/lib/vitest-exclude/vitest.cjs.map +1 -0
- package/lib/vitest-exclude/vitest.d.ts +16 -0
- package/lib/vitest-exclude/vitest.js +56 -0
- package/lib/vitest-exclude/vitest.js.map +1 -0
- package/lib/vitest-exclude/vitest.utils.cjs +31 -0
- package/lib/vitest-exclude/vitest.utils.cjs.map +1 -0
- package/lib/vitest-exclude/vitest.utils.d.ts +4 -0
- package/lib/vitest-exclude/vitest.utils.js +26 -0
- package/lib/vitest-exclude/vitest.utils.js.map +1 -0
- package/lib/vitest-extended/acceptation.cjs +24 -0
- package/lib/vitest-extended/acceptation.cjs.map +1 -0
- package/lib/vitest-extended/acceptation.d.ts +7 -0
- package/lib/vitest-extended/acceptation.js +21 -0
- package/lib/vitest-extended/acceptation.js.map +1 -0
- package/lib/vitest-extended/bemedev/globals/types.d.ts +3 -0
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.cjs +17 -0
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.cjs.map +1 -0
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.d.ts +11 -0
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.js +16 -0
- package/lib/vitest-extended/bemedev/globals/utils/_unknown.js.map +1 -0
- package/lib/vitest-extended/createTests.cjs +89 -0
- package/lib/vitest-extended/createTests.cjs.map +1 -0
- package/lib/vitest-extended/createTests.d.ts +58 -0
- package/lib/vitest-extended/createTests.js +87 -0
- package/lib/vitest-extended/createTests.js.map +1 -0
- package/lib/vitest-extended/createTests.types.d.ts +10 -0
- package/lib/vitest-extended/done.cjs +81 -0
- package/lib/vitest-extended/done.cjs.map +1 -0
- package/lib/vitest-extended/done.d.ts +14 -0
- package/lib/vitest-extended/done.js +79 -0
- package/lib/vitest-extended/done.js.map +1 -0
- package/lib/vitest-extended/each/error.cjs +23 -0
- package/lib/vitest-extended/each/error.cjs.map +1 -0
- package/lib/vitest-extended/each/error.d.ts +3 -0
- package/lib/vitest-extended/each/error.js +20 -0
- package/lib/vitest-extended/each/error.js.map +1 -0
- package/lib/vitest-extended/each/error.types.d.ts +5 -0
- package/lib/vitest-extended/each/index.cjs +7 -0
- package/lib/vitest-extended/each/index.d.ts +2 -0
- package/lib/vitest-extended/each/index.js +3 -0
- package/lib/vitest-extended/each/pass.cjs +56 -0
- package/lib/vitest-extended/each/pass.cjs.map +1 -0
- package/lib/vitest-extended/each/pass.d.ts +32 -0
- package/lib/vitest-extended/each/pass.js +53 -0
- package/lib/vitest-extended/each/pass.js.map +1 -0
- package/lib/vitest-extended/each/pass.types.d.ts +6 -0
- package/lib/vitest-extended/fakeWaiter.cjs +29 -0
- package/lib/vitest-extended/fakeWaiter.cjs.map +1 -0
- package/lib/vitest-extended/fakeWaiter.d.ts +9 -0
- package/lib/vitest-extended/fakeWaiter.js +28 -0
- package/lib/vitest-extended/fakeWaiter.js.map +1 -0
- package/lib/vitest-extended/fixtures/coverage.cjs +11 -0
- package/lib/vitest-extended/fixtures/coverage.cjs.map +1 -0
- package/lib/vitest-extended/fixtures/coverage.js +8 -0
- package/lib/vitest-extended/fixtures/coverage.js.map +1 -0
- package/lib/vitest-extended/fixtures/partialCall.cjs +19 -0
- package/lib/vitest-extended/fixtures/partialCall.cjs.map +1 -0
- package/lib/vitest-extended/fixtures/partialCall.js +18 -0
- package/lib/vitest-extended/fixtures/partialCall.js.map +1 -0
- package/lib/vitest-extended/fixtures/toUpper.cjs +13 -0
- package/lib/vitest-extended/fixtures/toUpper.cjs.map +1 -0
- package/lib/vitest-extended/fixtures/toUpper.js +11 -0
- package/lib/vitest-extended/fixtures/toUpper.js.map +1 -0
- package/lib/vitest-extended/fixtures/vitest.cjs +7 -0
- package/lib/vitest-extended/fixtures/vitest.cjs.map +1 -0
- package/lib/vitest-extended/fixtures/vitest.js +6 -0
- package/lib/vitest-extended/fixtures/vitest.js.map +1 -0
- package/lib/vitest-extended/fixtures/zod.cjs +23 -0
- package/lib/vitest-extended/fixtures/zod.cjs.map +1 -0
- package/lib/vitest-extended/fixtures/zod.js +19 -0
- package/lib/vitest-extended/fixtures/zod.js.map +1 -0
- package/lib/vitest-extended/identity.cjs +14 -0
- package/lib/vitest-extended/identity.cjs.map +1 -0
- package/lib/vitest-extended/identity.d.ts +2 -0
- package/lib/vitest-extended/identity.js +11 -0
- package/lib/vitest-extended/identity.js.map +1 -0
- package/lib/vitest-extended/index.cjs +39 -0
- package/lib/vitest-extended/index.cjs.map +1 -0
- package/lib/vitest-extended/index.d.ts +6 -0
- package/lib/vitest-extended/index.js +24 -0
- package/lib/vitest-extended/index.js.map +1 -0
- package/lib/vitest-extended/isDefined.cjs +9 -0
- package/lib/vitest-extended/isDefined.cjs.map +1 -0
- package/lib/vitest-extended/isDefined.d.ts +2 -0
- package/lib/vitest-extended/isDefined.js +8 -0
- package/lib/vitest-extended/isDefined.js.map +1 -0
- package/lib/vitest-extended/isFunction.cjs +12 -0
- package/lib/vitest-extended/isFunction.cjs.map +1 -0
- package/lib/vitest-extended/isFunction.d.ts +1 -0
- package/lib/vitest-extended/isFunction.js +11 -0
- package/lib/vitest-extended/isFunction.js.map +1 -0
- package/lib/vitest-extended/toArray.cjs +35 -0
- package/lib/vitest-extended/toArray.cjs.map +1 -0
- package/lib/vitest-extended/toArray.d.ts +3 -0
- package/lib/vitest-extended/toArray.js +33 -0
- package/lib/vitest-extended/toArray.js.map +1 -0
- package/lib/vitest-extended/toStringFlat.cjs +18 -0
- package/lib/vitest-extended/toStringFlat.cjs.map +1 -0
- package/lib/vitest-extended/toStringFlat.d.ts +2 -0
- package/lib/vitest-extended/toStringFlat.js +17 -0
- package/lib/vitest-extended/toStringFlat.js.map +1 -0
- package/lib/vitest-extended/types.d.ts +64 -0
- package/package.json +149 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Fn } from './bemedev/globals/types';
|
|
2
|
+
import type { ToError_F } from './each/error.types';
|
|
3
|
+
import type { Identity, NextFn } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates tests for function in a better way
|
|
6
|
+
* NB : We use strict-equality, {@link useEach|see}
|
|
7
|
+
* @param library The test library
|
|
8
|
+
* @param f The function to test
|
|
9
|
+
* @param
|
|
10
|
+
* @returns A test.each like function to tests many cases
|
|
11
|
+
*
|
|
12
|
+
* NB: If the first argument is an array, wrap the value in another array,
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // ./add.ts
|
|
16
|
+
*export const add = (args: string[]) => args.reduce(
|
|
17
|
+
* (acc, value) => {
|
|
18
|
+
* acc+=value
|
|
19
|
+
* return acc;
|
|
20
|
+
* },
|
|
21
|
+
* 0)
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* // .add.test.ts
|
|
25
|
+
*import { createTests } from '@bemedev/vitest-extended';
|
|
26
|
+
*import { add } from './add';
|
|
27
|
+
*
|
|
28
|
+
*const useTests = createTests(add)
|
|
29
|
+
*
|
|
30
|
+
*useTests(
|
|
31
|
+
* {
|
|
32
|
+
* invite: 'For : 1,2,3,4,5,6,7,8,9',
|
|
33
|
+
* parameters: [[1, 2, 3, 4, 5, 6, 7, 8, 9]], // like this!
|
|
34
|
+
* }
|
|
35
|
+
*)
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
export declare const createTests: {
|
|
39
|
+
<F extends Fn, T extends NextFn<F> = Identity<F>>(func: F, args?: {
|
|
40
|
+
transform?: T;
|
|
41
|
+
toError?: ToError_F<F>;
|
|
42
|
+
}): {
|
|
43
|
+
acceptation: () => void;
|
|
44
|
+
success: (...cases: import("./types").TestArgs<import("./types").ChainedFn<F, T>>) => () => void;
|
|
45
|
+
fails: (...cases: import("./types").TestErrors<import("./types").ChainedFn<F, T>>) => () => void;
|
|
46
|
+
};
|
|
47
|
+
withImplementation<F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, { instanciation, name, transform, toError, }: {
|
|
48
|
+
instanciation: () => Promise<F> | F;
|
|
49
|
+
name: string;
|
|
50
|
+
transform?: T;
|
|
51
|
+
toError?: ToError_F<F>;
|
|
52
|
+
}): {
|
|
53
|
+
acceptation: () => void;
|
|
54
|
+
success: (...cases: import("./types").TestArgs<import("./types").ChainedFn<import("vitest").Mock<F>, NextFn<import("vitest").Mock<F>>>>) => () => void;
|
|
55
|
+
fails: (...cases: import("./types").TestErrors<import("./types").ChainedFn<import("vitest").Mock<F>, NextFn<import("vitest").Mock<F>>>>) => () => void;
|
|
56
|
+
};
|
|
57
|
+
withoutImplementation: /*elided*/ any;
|
|
58
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useTFA } from "./acceptation.js";
|
|
2
|
+
import { useErrorAsyncEach } from "./each/error.js";
|
|
3
|
+
import { useEachAsync } from "./each/pass.js";
|
|
4
|
+
import { toStringFlat } from "./toStringFlat.js";
|
|
5
|
+
import { beforeAll, vi } from "vitest";
|
|
6
|
+
//#region src/vitest-extended/createTests.ts
|
|
7
|
+
const _create = (func, transform, toError, name) => {
|
|
8
|
+
return {
|
|
9
|
+
acceptation: () => useTFA(func, name),
|
|
10
|
+
fails: (...cases) => {
|
|
11
|
+
const length = cases.length;
|
|
12
|
+
return () => {
|
|
13
|
+
return useErrorAsyncEach(func, transform, toError)(...cases.map(({ invite: _invite, parameters, error }, index) => {
|
|
14
|
+
return {
|
|
15
|
+
invite: `#${toStringFlat(index + 1, length)} => ${_invite}`,
|
|
16
|
+
parameters,
|
|
17
|
+
error
|
|
18
|
+
};
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
success: (...cases) => {
|
|
23
|
+
const length = cases.length;
|
|
24
|
+
return () => {
|
|
25
|
+
return useEachAsync(func, transform)(...cases.map(({ invite: _invite, parameters, expected, test }, index) => {
|
|
26
|
+
return {
|
|
27
|
+
invite: `#${toStringFlat(index + 1, length)} => ${_invite}`,
|
|
28
|
+
parameters,
|
|
29
|
+
expected,
|
|
30
|
+
test
|
|
31
|
+
};
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Creates tests for function in a better way
|
|
39
|
+
* NB : We use strict-equality, {@link useEach|see}
|
|
40
|
+
* @param library The test library
|
|
41
|
+
* @param f The function to test
|
|
42
|
+
* @param
|
|
43
|
+
* @returns A test.each like function to tests many cases
|
|
44
|
+
*
|
|
45
|
+
* NB: If the first argument is an array, wrap the value in another array,
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // ./add.ts
|
|
49
|
+
*export const add = (args: string[]) => args.reduce(
|
|
50
|
+
* (acc, value) => {
|
|
51
|
+
* acc+=value
|
|
52
|
+
* return acc;
|
|
53
|
+
* },
|
|
54
|
+
* 0)
|
|
55
|
+
*
|
|
56
|
+
*
|
|
57
|
+
* // .add.test.ts
|
|
58
|
+
*import { createTests } from '@bemedev/vitest-extended';
|
|
59
|
+
*import { add } from './add';
|
|
60
|
+
*
|
|
61
|
+
*const useTests = createTests(add)
|
|
62
|
+
*
|
|
63
|
+
*useTests(
|
|
64
|
+
* {
|
|
65
|
+
* invite: 'For : 1,2,3,4,5,6,7,8,9',
|
|
66
|
+
* parameters: [[1, 2, 3, 4, 5, 6, 7, 8, 9]], // like this!
|
|
67
|
+
* }
|
|
68
|
+
*)
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
const createTests = (func, args) => {
|
|
72
|
+
const { transform, toError } = args || {};
|
|
73
|
+
return _create(func, transform, toError);
|
|
74
|
+
};
|
|
75
|
+
createTests.withImplementation = (f, { instanciation, name, transform, toError }) => {
|
|
76
|
+
const func = vi.fn(f);
|
|
77
|
+
if (instanciation) beforeAll(async () => {
|
|
78
|
+
const impl = await instanciation();
|
|
79
|
+
func.mockImplementation(impl);
|
|
80
|
+
});
|
|
81
|
+
return _create(func, transform, toError, name);
|
|
82
|
+
};
|
|
83
|
+
createTests.withoutImplementation = createTests;
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createTests };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=createTests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTests.js","names":[],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import type { Fn } from './bemedev/globals/types';\nimport { beforeAll, vi } from 'vitest';\nimport { useTFA } from './acceptation';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport type { ToError_F } from './each/error.types';\nimport {\n useEachAsync,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n type useEach,\n} from './each/pass';\nimport { toStringFlat } from './toStringFlat';\nimport type { Identity, NextFn } from './types';\n\nconst _create: _CreateTests_F = (func, transform, toError, name) => {\n return {\n acceptation: () => useTFA(func, name),\n\n fails: (...cases) => {\n const length = cases.length;\n\n return () => {\n const useTests = useErrorAsyncEach(func, transform, toError);\n\n const _cases: any = cases.map(\n ({ invite: _invite, parameters, error }, index) => {\n const invite = `#${toStringFlat(index + 1, length)} => ${_invite}`;\n const out = { invite, parameters, error };\n return out;\n },\n );\n\n return useTests(..._cases);\n };\n },\n\n success: (...cases) => {\n const length = cases.length;\n return () => {\n const useTests = useEachAsync(func, transform);\n\n const _cases: any = cases.map(\n ({ invite: _invite, parameters, expected, test }, index) => {\n const invite = `#${toStringFlat(index + 1, length)} => ${_invite}`;\n const out = { invite, parameters, expected, test };\n return out;\n },\n );\n\n return useTests(..._cases);\n };\n },\n };\n};\n\n/**\n * Creates tests for function in a better way\n * NB : We use strict-equality, {@link useEach|see}\n * @param library The test library\n * @param f The function to test\n * @param\n * @returns A test.each like function to tests many cases\n *\n * NB: If the first argument is an array, wrap the value in another array,\n *\n * @example\n * // ./add.ts\n *export const add = (args: string[]) => args.reduce(\n * (acc, value) => {\n * acc+=value\n * return acc;\n * },\n * 0)\n *\n *\n * // .add.test.ts\n *import { createTests } from '@bemedev/vitest-extended';\n *import { add } from './add';\n *\n *const useTests = createTests(add)\n *\n *useTests(\n * {\n * invite: 'For : 1,2,3,4,5,6,7,8,9',\n * parameters: [[1, 2, 3, 4, 5, 6, 7, 8, 9]], // like this!\n * }\n *)\n *\n */\nexport const createTests = <\n F extends Fn,\n T extends NextFn<F> = Identity<F>,\n>(\n func: F,\n args?: { transform?: T; toError?: ToError_F<F> },\n) => {\n const { transform, toError } = args || {};\n return _create(func, transform, toError);\n};\n\ncreateTests.withImplementation = <\n F extends Fn,\n T extends NextFn<F> = Identity<F>,\n>(\n f: F,\n {\n instanciation,\n name,\n transform,\n toError,\n }: {\n instanciation: () => Promise<F> | F;\n name: string;\n transform?: T;\n toError?: ToError_F<F>;\n },\n) => {\n const func = vi.fn(f);\n\n if (instanciation) {\n beforeAll(async () => {\n const impl = await instanciation();\n func.mockImplementation(impl);\n });\n }\n\n return _create(func, transform, toError, name);\n};\n\ncreateTests.withoutImplementation = createTests;\n"],"mappings":";;;;;;AAcA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;AAClE,QAAO;EACL,mBAAmB,OAAO,MAAM,KAAK;EAErC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;AAErB,gBAAa;AAWX,WAViB,kBAAkB,MAAM,WAAW,QAAQ,CAU5C,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,SAAS,UAAU;AAGjD,YADY;MAAE,QADC,IAAI,aAAa,QAAQ,GAAG,OAAO,CAAC,MAAM;MACnC;MAAY;MAAO;MAG5C,CAEyB;;;EAI9B,UAAU,GAAG,UAAU;GACrB,MAAM,SAAS,MAAM;AACrB,gBAAa;AAWX,WAViB,aAAa,MAAM,UAAU,CAU9B,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,UAAU,QAAQ,UAAU;AAG1D,YADY;MAAE,QADC,IAAI,aAAa,QAAQ,GAAG,OAAO,CAAC,MAAM;MACnC;MAAY;MAAU;MAAM;MAGrD,CAEyB;;;EAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCH,MAAa,eAIX,MACA,SACG;CACH,MAAM,EAAE,WAAW,YAAY,QAAQ,EAAE;AACzC,QAAO,QAAQ,MAAM,WAAW,QAAQ;;AAG1C,YAAY,sBAIV,GACA,EACE,eACA,MACA,WACA,cAOC;CACH,MAAM,OAAO,GAAG,GAAG,EAAE;AAErB,KAAI,cACF,WAAU,YAAY;EACpB,MAAM,OAAO,MAAM,eAAe;AAClC,OAAK,mBAAmB,KAAK;GAC7B;AAGJ,QAAO,QAAQ,MAAM,WAAW,SAAS,KAAK;;AAGhD,YAAY,wBAAwB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Fn } from './bemedev/globals/types';
|
|
2
|
+
import type { ToError_F } from './each/error.types';
|
|
3
|
+
import type { ChainedFn, Identity, NextFn, TestArgs, TestErrors } from './types';
|
|
4
|
+
type ReturnR<F extends Fn> = {
|
|
5
|
+
acceptation: () => void;
|
|
6
|
+
success: (...cases: TestArgs<F>) => () => void;
|
|
7
|
+
fails: (...cases: TestErrors<F>) => () => void;
|
|
8
|
+
};
|
|
9
|
+
export type _CreateTests_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(func: F, transform?: T, toError?: ToError_F<F>, name?: string) => ReturnR<ChainedFn<F, T>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_utils_sleep = require("../utils/sleep.cjs");
|
|
4
|
+
let vitest = require("vitest");
|
|
5
|
+
//#region src/vitest-extended/done.ts
|
|
6
|
+
const useDone = (ms = 0) => {
|
|
7
|
+
let executed = false;
|
|
8
|
+
const done = () => executed = true;
|
|
9
|
+
const testDone = async () => {
|
|
10
|
+
await require_utils_sleep.sleep(ms);
|
|
11
|
+
(0, vitest.expect)(executed).toBe(true);
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
done,
|
|
15
|
+
testDone
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const min100 = (ms = 0) => Math.max(100, ms);
|
|
19
|
+
const getTimeout = (options) => {
|
|
20
|
+
if (typeof options === "number") return min100(options);
|
|
21
|
+
return min100(options?.timeout);
|
|
22
|
+
};
|
|
23
|
+
const objectify = (options) => {
|
|
24
|
+
const _timeout = getTimeout(options);
|
|
25
|
+
const timeout = _timeout + 100;
|
|
26
|
+
let _options = { timeout };
|
|
27
|
+
if (!(typeof options === "number")) _options = {
|
|
28
|
+
...options,
|
|
29
|
+
timeout
|
|
30
|
+
};
|
|
31
|
+
return [_options, _timeout];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Build a test with a done function with a timeout
|
|
35
|
+
* @param invite The description of the test
|
|
36
|
+
* @param fn Where you can test, Don't async this function
|
|
37
|
+
* @param options Options for the test like TestAPI from vitest
|
|
38
|
+
* @returns a vitest test
|
|
39
|
+
*/
|
|
40
|
+
const doneTest = (invite, fn, options = 100) => {
|
|
41
|
+
const [_options, ms] = objectify(options);
|
|
42
|
+
return (0, vitest.test)(invite, _options, () => {
|
|
43
|
+
const { done, testDone } = useDone(ms);
|
|
44
|
+
fn(done);
|
|
45
|
+
return testDone();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Build a test that fails with a done function with a timeout
|
|
50
|
+
* @param invite The description of the test
|
|
51
|
+
* @param fn Where you can test, Don't async this function
|
|
52
|
+
* @param options Options for the test like TestAPI from vitest
|
|
53
|
+
* @returns a vitest test
|
|
54
|
+
*/
|
|
55
|
+
doneTest.fails = (invite, fn, options = 100) => {
|
|
56
|
+
const [_options, ms] = objectify(options);
|
|
57
|
+
return vitest.test.fails(invite, _options, () => {
|
|
58
|
+
const { done, testDone } = useDone(ms);
|
|
59
|
+
fn(done);
|
|
60
|
+
return testDone();
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Build a concurrent test with a done function with a timeout
|
|
65
|
+
* @param invite The description of the test
|
|
66
|
+
* @param fn Where you can test, Don't async this function
|
|
67
|
+
* @param options Options for the test like TestAPI from vitest
|
|
68
|
+
* @returns a vitest test
|
|
69
|
+
*/
|
|
70
|
+
doneTest.concurrent = (invite, fn, options = 100) => {
|
|
71
|
+
const [_options, ms] = objectify(options);
|
|
72
|
+
return vitest.test.concurrent(invite, _options, () => {
|
|
73
|
+
const { done, testDone } = useDone(ms);
|
|
74
|
+
fn(done);
|
|
75
|
+
return testDone();
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
exports.doneTest = doneTest;
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=done.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"done.cjs","names":["sleep","test"],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { sleep } from '../utils/sleep';\nimport { expect, test, type TestOptions } from 'vitest';\nimport type { TestDoneFunction } from './types';\n\nconst useDone = (ms = 0) => {\n let executed = false;\n const done = () => (executed = true);\n\n const testDone = async () => {\n await sleep(ms);\n expect(executed).toBe(true);\n };\n\n return { done, testDone };\n};\n\nconst min100 = (ms = 0) => Math.max(100, ms);\n\n// #region Preparation\nconst getTimeout = (options?: TestOptions | number) => {\n if (typeof options === 'number') return min100(options);\n return min100(options?.timeout);\n};\n\nconst objectify = (\n options?: TestOptions | number,\n): [TestOptions, number] => {\n const _timeout = getTimeout(options);\n const timeout = _timeout + 100;\n\n let _options = { timeout };\n if (!(typeof options === 'number')) {\n _options = { ...options, timeout };\n }\n\n return [_options, _timeout];\n};\n// #endregion\n\n/**\n * Build a test with a done function with a timeout\n * @param invite The description of the test\n * @param fn Where you can test, Don't async this function\n * @param options Options for the test like TestAPI from vitest\n * @returns a vitest test\n */\nexport const doneTest = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a test that fails with a done function with a timeout\n * @param invite The description of the test\n * @param fn Where you can test, Don't async this function\n * @param options Options for the test like TestAPI from vitest\n * @returns a vitest test\n */\ndoneTest.fails = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.fails(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a concurrent test with a done function with a timeout\n * @param invite The description of the test\n * @param fn Where you can test, Don't async this function\n * @param options Options for the test like TestAPI from vitest\n * @returns a vitest test\n */\ndoneTest.concurrent = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.concurrent(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n"],"mappings":";;;;;AAIA,MAAM,WAAW,KAAK,MAAM;CAC1B,IAAI,WAAW;CACf,MAAM,aAAc,WAAW;CAE/B,MAAM,WAAW,YAAY;AAC3B,QAAMA,oBAAAA,MAAM,GAAG;AACf,GAAA,GAAA,OAAA,QAAO,SAAS,CAAC,KAAK,KAAK;;AAG7B,QAAO;EAAE;EAAM;EAAU;;AAG3B,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,KAAK,GAAG;AAG5C,MAAM,cAAc,YAAmC;AACrD,KAAI,OAAO,YAAY,SAAU,QAAO,OAAO,QAAQ;AACvD,QAAO,OAAO,SAAS,QAAQ;;AAGjC,MAAM,aACJ,YAC0B;CAC1B,MAAM,WAAW,WAAW,QAAQ;CACpC,MAAM,UAAU,WAAW;CAE3B,IAAI,WAAW,EAAE,SAAS;AAC1B,KAAI,EAAE,OAAO,YAAY,UACvB,YAAW;EAAE,GAAG;EAAS;EAAS;AAGpC,QAAO,CAAC,UAAU,SAAS;;;;;;;;;AAW7B,MAAa,YACX,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,QAAQ;AAEzC,SAAA,GAAA,OAAA,MAAY,QAAQ,gBAAgB;EAClC,MAAM,EAAE,MAAM,aAAa,QAAQ,GAAG;AACtC,KAAG,KAAK;AACR,SAAO,UAAU;GACjB;;;;;;;;;AAUJ,SAAS,SACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,QAAQ;AAEzC,QAAOC,OAAAA,KAAK,MAAM,QAAQ,gBAAgB;EACxC,MAAM,EAAE,MAAM,aAAa,QAAQ,GAAG;AACtC,KAAG,KAAK;AACR,SAAO,UAAU;GACjB;;;;;;;;;AAUJ,SAAS,cACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,QAAQ;AAEzC,QAAOA,OAAAA,KAAK,WAAW,QAAQ,gBAAgB;EAC7C,MAAM,EAAE,MAAM,aAAa,QAAQ,GAAG;AACtC,KAAG,KAAK;AACR,SAAO,UAAU;GACjB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TestOptions } from 'vitest';
|
|
2
|
+
import type { TestDoneFunction } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Build a test with a done function with a timeout
|
|
5
|
+
* @param invite The description of the test
|
|
6
|
+
* @param fn Where you can test, Don't async this function
|
|
7
|
+
* @param options Options for the test like TestAPI from vitest
|
|
8
|
+
* @returns a vitest test
|
|
9
|
+
*/
|
|
10
|
+
export declare const doneTest: {
|
|
11
|
+
(invite: string, fn: TestDoneFunction, options?: number | TestOptions): void;
|
|
12
|
+
fails(invite: string, fn: TestDoneFunction, options?: number | TestOptions): void;
|
|
13
|
+
concurrent(invite: string, fn: TestDoneFunction, options?: number | TestOptions): void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { sleep } from "../utils/sleep.js";
|
|
2
|
+
import { expect, test } from "vitest";
|
|
3
|
+
//#region src/vitest-extended/done.ts
|
|
4
|
+
const useDone = (ms = 0) => {
|
|
5
|
+
let executed = false;
|
|
6
|
+
const done = () => executed = true;
|
|
7
|
+
const testDone = async () => {
|
|
8
|
+
await sleep(ms);
|
|
9
|
+
expect(executed).toBe(true);
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
done,
|
|
13
|
+
testDone
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const min100 = (ms = 0) => Math.max(100, ms);
|
|
17
|
+
const getTimeout = (options) => {
|
|
18
|
+
if (typeof options === "number") return min100(options);
|
|
19
|
+
return min100(options?.timeout);
|
|
20
|
+
};
|
|
21
|
+
const objectify = (options) => {
|
|
22
|
+
const _timeout = getTimeout(options);
|
|
23
|
+
const timeout = _timeout + 100;
|
|
24
|
+
let _options = { timeout };
|
|
25
|
+
if (!(typeof options === "number")) _options = {
|
|
26
|
+
...options,
|
|
27
|
+
timeout
|
|
28
|
+
};
|
|
29
|
+
return [_options, _timeout];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Build a test with a done function with a timeout
|
|
33
|
+
* @param invite The description of the test
|
|
34
|
+
* @param fn Where you can test, Don't async this function
|
|
35
|
+
* @param options Options for the test like TestAPI from vitest
|
|
36
|
+
* @returns a vitest test
|
|
37
|
+
*/
|
|
38
|
+
const doneTest = (invite, fn, options = 100) => {
|
|
39
|
+
const [_options, ms] = objectify(options);
|
|
40
|
+
return test(invite, _options, () => {
|
|
41
|
+
const { done, testDone } = useDone(ms);
|
|
42
|
+
fn(done);
|
|
43
|
+
return testDone();
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Build a test that fails with a done function with a timeout
|
|
48
|
+
* @param invite The description of the test
|
|
49
|
+
* @param fn Where you can test, Don't async this function
|
|
50
|
+
* @param options Options for the test like TestAPI from vitest
|
|
51
|
+
* @returns a vitest test
|
|
52
|
+
*/
|
|
53
|
+
doneTest.fails = (invite, fn, options = 100) => {
|
|
54
|
+
const [_options, ms] = objectify(options);
|
|
55
|
+
return test.fails(invite, _options, () => {
|
|
56
|
+
const { done, testDone } = useDone(ms);
|
|
57
|
+
fn(done);
|
|
58
|
+
return testDone();
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Build a concurrent test with a done function with a timeout
|
|
63
|
+
* @param invite The description of the test
|
|
64
|
+
* @param fn Where you can test, Don't async this function
|
|
65
|
+
* @param options Options for the test like TestAPI from vitest
|
|
66
|
+
* @returns a vitest test
|
|
67
|
+
*/
|
|
68
|
+
doneTest.concurrent = (invite, fn, options = 100) => {
|
|
69
|
+
const [_options, ms] = objectify(options);
|
|
70
|
+
return test.concurrent(invite, _options, () => {
|
|
71
|
+
const { done, testDone } = useDone(ms);
|
|
72
|
+
fn(done);
|
|
73
|
+
return testDone();
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { doneTest };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=done.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"done.js","names":[],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { sleep } from '../utils/sleep';\nimport { expect, test, type TestOptions } from 'vitest';\nimport type { TestDoneFunction } from './types';\n\nconst useDone = (ms = 0) => {\n let executed = false;\n const done = () => (executed = true);\n\n const testDone = async () => {\n await sleep(ms);\n expect(executed).toBe(true);\n };\n\n return { done, testDone };\n};\n\nconst min100 = (ms = 0) => Math.max(100, ms);\n\n// #region Preparation\nconst getTimeout = (options?: TestOptions | number) => {\n if (typeof options === 'number') return min100(options);\n return min100(options?.timeout);\n};\n\nconst objectify = (\n options?: TestOptions | number,\n): [TestOptions, number] => {\n const _timeout = getTimeout(options);\n const timeout = _timeout + 100;\n\n let _options = { timeout };\n if (!(typeof options === 'number')) {\n _options = { ...options, timeout };\n }\n\n return [_options, _timeout];\n};\n// #endregion\n\n/**\n * Build a test with a done function with a timeout\n * @param invite The description of the test\n * @param fn Where you can test, Don't async this function\n * @param options Options for the test like TestAPI from vitest\n * @returns a vitest test\n */\nexport const doneTest = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a test that fails with a done function with a timeout\n * @param invite The description of the test\n * @param fn Where you can test, Don't async this function\n * @param options Options for the test like TestAPI from vitest\n * @returns a vitest test\n */\ndoneTest.fails = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.fails(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n\n/**\n * Build a concurrent test with a done function with a timeout\n * @param invite The description of the test\n * @param fn Where you can test, Don't async this function\n * @param options Options for the test like TestAPI from vitest\n * @returns a vitest test\n */\ndoneTest.concurrent = (\n invite: string,\n fn: TestDoneFunction,\n options: number | TestOptions = 100,\n) => {\n const [_options, ms] = objectify(options);\n\n return test.concurrent(invite, _options, () => {\n const { done, testDone } = useDone(ms);\n fn(done);\n return testDone();\n });\n};\n"],"mappings":";;;AAIA,MAAM,WAAW,KAAK,MAAM;CAC1B,IAAI,WAAW;CACf,MAAM,aAAc,WAAW;CAE/B,MAAM,WAAW,YAAY;AAC3B,QAAM,MAAM,GAAG;AACf,SAAO,SAAS,CAAC,KAAK,KAAK;;AAG7B,QAAO;EAAE;EAAM;EAAU;;AAG3B,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,KAAK,GAAG;AAG5C,MAAM,cAAc,YAAmC;AACrD,KAAI,OAAO,YAAY,SAAU,QAAO,OAAO,QAAQ;AACvD,QAAO,OAAO,SAAS,QAAQ;;AAGjC,MAAM,aACJ,YAC0B;CAC1B,MAAM,WAAW,WAAW,QAAQ;CACpC,MAAM,UAAU,WAAW;CAE3B,IAAI,WAAW,EAAE,SAAS;AAC1B,KAAI,EAAE,OAAO,YAAY,UACvB,YAAW;EAAE,GAAG;EAAS;EAAS;AAGpC,QAAO,CAAC,UAAU,SAAS;;;;;;;;;AAW7B,MAAa,YACX,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,QAAQ;AAEzC,QAAO,KAAK,QAAQ,gBAAgB;EAClC,MAAM,EAAE,MAAM,aAAa,QAAQ,GAAG;AACtC,KAAG,KAAK;AACR,SAAO,UAAU;GACjB;;;;;;;;;AAUJ,SAAS,SACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,QAAQ;AAEzC,QAAO,KAAK,MAAM,QAAQ,gBAAgB;EACxC,MAAM,EAAE,MAAM,aAAa,QAAQ,GAAG;AACtC,KAAG,KAAK;AACR,SAAO,UAAU;GACjB;;;;;;;;;AAUJ,SAAS,cACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,QAAQ;AAEzC,QAAO,KAAK,WAAW,QAAQ,gBAAgB;EAC7C,MAAM,EAAE,MAAM,aAAa,QAAQ,GAAG;AACtC,KAAG,KAAK;AACR,SAAO,UAAU;GACjB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_vitest_extended_identity = require("../identity.cjs");
|
|
4
|
+
const require_vitest_extended_toArray = require("../toArray.cjs");
|
|
5
|
+
let vitest = require("vitest");
|
|
6
|
+
//#region src/vitest-extended/each/error.ts
|
|
7
|
+
const useErrorAsyncEachCases = (f, transform = require_vitest_extended_identity.identity, toError = () => void 0, ...cases) => {
|
|
8
|
+
vitest.test.concurrent.each(require_vitest_extended_toArray.toArrayVitest.error(cases))("%s", async (_, args, _error) => {
|
|
9
|
+
const actual = async () => {
|
|
10
|
+
return transform(await f(...args));
|
|
11
|
+
};
|
|
12
|
+
const error = _error === void 0 ? toError(...args) : _error;
|
|
13
|
+
await (0, vitest.expect)(actual).rejects.toThrowError(error);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const useErrorAsyncEach = (f, transform, toError) => {
|
|
17
|
+
return (...cases) => useErrorAsyncEachCases(f, transform, toError, ...cases);
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.useErrorAsyncEach = useErrorAsyncEach;
|
|
21
|
+
exports.useErrorAsyncEachCases = useErrorAsyncEachCases;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=error.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.cjs","names":["identity","toArrayVitest"],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\nexport const useErrorAsyncEachCases: _UseErrorEach_F = (\n f,\n transform = identity as any,\n toError = () => undefined,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest.error(cases))(\n '%s',\n async (_, args, _error) => {\n const actual = async () => {\n const out = await f(...args);\n return transform(out);\n };\n const check = _error === undefined;\n const error = check ? toError(...args) : _error;\n\n await expect(actual).rejects.toThrowError(error);\n },\n );\n};\n\nexport const useErrorAsyncEach: UseErrorEach_F = (\n f,\n transform,\n toError,\n) => {\n return (...cases) =>\n useErrorAsyncEachCases(f, transform, toError, ...cases);\n};\n"],"mappings":";;;;;;AAKA,MAAa,0BACX,GACA,YAAYA,iCAAAA,UACZ,gBAAgB,KAAA,GAChB,GAAG,UACA;AACH,QAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,MAAM,MAAM,CAAC,CAC9C,MACA,OAAO,GAAG,MAAM,WAAW;EACzB,MAAM,SAAS,YAAY;AAEzB,UAAO,UADK,MAAM,EAAE,GAAG,KAAK,CACP;;EAGvB,MAAM,QADQ,WAAW,KAAA,IACH,QAAQ,GAAG,KAAK,GAAG;AAEzC,SAAA,GAAA,OAAA,QAAa,OAAO,CAAC,QAAQ,aAAa,MAAM;GAEnD;;AAGH,MAAa,qBACX,GACA,WACA,YACG;AACH,SAAQ,GAAG,UACT,uBAAuB,GAAG,WAAW,SAAS,GAAG,MAAM"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { identity } from "../identity.js";
|
|
2
|
+
import { toArrayVitest } from "../toArray.js";
|
|
3
|
+
import { expect, test } from "vitest";
|
|
4
|
+
//#region src/vitest-extended/each/error.ts
|
|
5
|
+
const useErrorAsyncEachCases = (f, transform = identity, toError = () => void 0, ...cases) => {
|
|
6
|
+
test.concurrent.each(toArrayVitest.error(cases))("%s", async (_, args, _error) => {
|
|
7
|
+
const actual = async () => {
|
|
8
|
+
return transform(await f(...args));
|
|
9
|
+
};
|
|
10
|
+
const error = _error === void 0 ? toError(...args) : _error;
|
|
11
|
+
await expect(actual).rejects.toThrowError(error);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const useErrorAsyncEach = (f, transform, toError) => {
|
|
15
|
+
return (...cases) => useErrorAsyncEachCases(f, transform, toError, ...cases);
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useErrorAsyncEach, useErrorAsyncEachCases };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\nexport const useErrorAsyncEachCases: _UseErrorEach_F = (\n f,\n transform = identity as any,\n toError = () => undefined,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest.error(cases))(\n '%s',\n async (_, args, _error) => {\n const actual = async () => {\n const out = await f(...args);\n return transform(out);\n };\n const check = _error === undefined;\n const error = check ? toError(...args) : _error;\n\n await expect(actual).rejects.toThrowError(error);\n },\n );\n};\n\nexport const useErrorAsyncEach: UseErrorEach_F = (\n f,\n transform,\n toError,\n) => {\n return (...cases) =>\n useErrorAsyncEachCases(f, transform, toError, ...cases);\n};\n"],"mappings":";;;;AAKA,MAAa,0BACX,GACA,YAAY,UACZ,gBAAgB,KAAA,GAChB,GAAG,UACA;AACH,MAAK,WAAW,KAAK,cAAc,MAAM,MAAM,CAAC,CAC9C,MACA,OAAO,GAAG,MAAM,WAAW;EACzB,MAAM,SAAS,YAAY;AAEzB,UAAO,UADK,MAAM,EAAE,GAAG,KAAK,CACP;;EAGvB,MAAM,QADQ,WAAW,KAAA,IACH,QAAQ,GAAG,KAAK,GAAG;AAEzC,QAAM,OAAO,OAAO,CAAC,QAAQ,aAAa,MAAM;GAEnD;;AAGH,MAAa,qBACX,GACA,WACA,YACG;AACH,SAAQ,GAAG,UACT,uBAAuB,GAAG,WAAW,SAAS,GAAG,MAAM"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Fn } from '../bemedev/globals/types';
|
|
2
|
+
import type { Identity, NextFn, TestErrors } from '../types';
|
|
3
|
+
export type ToError_F<F extends Fn> = (...params: Parameters<F>) => string | undefined;
|
|
4
|
+
export type _UseErrorEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, toError?: ToError_F<F>, ...cases: TestErrors<F>) => void;
|
|
5
|
+
export type UseErrorEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, toError?: ToError_F<F>) => Fn<TestErrors<F>, void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_vitest_extended_each_error = require("./error.cjs");
|
|
3
|
+
const require_vitest_extended_each_pass = require("./pass.cjs");
|
|
4
|
+
exports.useEach = require_vitest_extended_each_pass.useEach;
|
|
5
|
+
exports.useEachAsync = require_vitest_extended_each_pass.useEachAsync;
|
|
6
|
+
exports.useErrorAsyncEach = require_vitest_extended_each_error.useErrorAsyncEach;
|
|
7
|
+
exports.useErrorAsyncEachCases = require_vitest_extended_each_error.useErrorAsyncEachCases;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_vitest_extended_identity = require("../identity.cjs");
|
|
4
|
+
const require_vitest_extended_toArray = require("../toArray.cjs");
|
|
5
|
+
let vitest = require("vitest");
|
|
6
|
+
//#region src/vitest-extended/each/pass.ts
|
|
7
|
+
const useEachCases = (func, transform = require_vitest_extended_identity.identity, ...cases) => {
|
|
8
|
+
vitest.test.concurrent.each(require_vitest_extended_toArray.toArrayVitest(cases))("%s", (_, args, expected, test = require_vitest_extended_identity.defaultEquality) => {
|
|
9
|
+
return test(transform(func(...args)), expected);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A better version of **test.each**
|
|
14
|
+
*
|
|
15
|
+
* Type parameters
|
|
16
|
+
*
|
|
17
|
+
* @type A Parameters of the function, extends Array type
|
|
18
|
+
* @type R ReturnType of the function
|
|
19
|
+
*
|
|
20
|
+
* @if R are not provided, the return is a function to test with TestArgs arguments
|
|
21
|
+
*
|
|
22
|
+
* @else It tests every cases provided
|
|
23
|
+
*
|
|
24
|
+
* @param func The function to test
|
|
25
|
+
* @param cases The cases to test, The invite is the first arguments.
|
|
26
|
+
* It's an array of Array.
|
|
27
|
+
* * #1 The first arg is the invite of the test
|
|
28
|
+
*
|
|
29
|
+
* * #2 The second arg is the parameters to to pass to the function. It's an array (param array).
|
|
30
|
+
*
|
|
31
|
+
* * #3 The third arg is the expected result
|
|
32
|
+
*
|
|
33
|
+
* Example: For a function like ***(arg1: string)=>any***, the second arg with be : ***[string]***
|
|
34
|
+
* */
|
|
35
|
+
const useEach = (func, transform) => {
|
|
36
|
+
return (...cases) => useEachCases(func, transform, ...cases);
|
|
37
|
+
};
|
|
38
|
+
const useEachAsyncCases = (f, transform = require_vitest_extended_identity.identity, ...cases) => {
|
|
39
|
+
vitest.test.concurrent.each(require_vitest_extended_toArray.toArrayVitest(cases))("%s", async (_, args, expected, test = require_vitest_extended_identity.defaultEquality) => {
|
|
40
|
+
return test(transform(await f(...args)), expected);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Same as ***useEach***
|
|
45
|
+
*
|
|
46
|
+
* But for async functions
|
|
47
|
+
*
|
|
48
|
+
* */
|
|
49
|
+
const useEachAsync = (func, transform) => {
|
|
50
|
+
return (...cases) => useEachAsyncCases(func, transform, ...cases);
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.useEach = useEach;
|
|
54
|
+
exports.useEachAsync = useEachAsync;
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=pass.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pass.cjs","names":["identity","toArrayVitest","defaultEquality"],"sources":["../../../src/vitest-extended/each/pass.ts"],"sourcesContent":["import { test } from 'vitest';\nimport { defaultEquality, identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type {\n _UseAsyncEach_F,\n _UseEach_F,\n UseAsyncEach_F,\n UseEach_F,\n} from './pass.types';\n\n// #region Sync\nconst useEachCases: _UseEach_F = (\n func,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n (_, args, expected, test = defaultEquality) => {\n const value = transform(func(...args));\n return test(value, expected);\n },\n );\n};\n\n/**\n * A better version of **test.each**\n *\n * Type parameters\n *\n * @type A Parameters of the function, extends Array type\n * @type R ReturnType of the function\n *\n * @if R are not provided, the return is a function to test with TestArgs arguments\n *\n * @else It tests every cases provided\n *\n * @param func The function to test\n * @param cases The cases to test, The invite is the first arguments.\n * It's an array of Array.\n * * #1 The first arg is the invite of the test\n *\n * * #2 The second arg is the parameters to to pass to the function. It's an array (param array).\n *\n * * #3 The third arg is the expected result\n *\n * Example: For a function like ***(arg1: string)=>any***, the second arg with be : ***[string]***\n * */\nexport const useEach: UseEach_F = (func, transform) => {\n return (...cases) => useEachCases(func, transform, ...cases);\n};\n// #endregion\n\n// #region Async\nconst useEachAsyncCases: _UseAsyncEach_F = (\n f,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n async (_, args, expected, test = defaultEquality) => {\n const _value = await f(...args);\n const value = transform(_value);\n return test(value, expected);\n },\n );\n};\n\n/**\n * Same as ***useEach***\n *\n * But for async functions\n *\n * */\nexport const useEachAsync: UseAsyncEach_F = (func, transform) => {\n return (...cases) => useEachAsyncCases(func, transform, ...cases);\n};\n// #endregion\n"],"mappings":";;;;;;AAWA,MAAM,gBACJ,MACA,YAAYA,iCAAAA,UACZ,GAAG,UACA;AACH,QAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,MAAM,CAAC,CACxC,OACC,GAAG,MAAM,UAAU,OAAOC,iCAAAA,oBAAoB;AAE7C,SAAO,KADO,UAAU,KAAK,GAAG,KAAK,CAAC,EACnB,SAAS;GAE/B;;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,MAAa,WAAsB,MAAM,cAAc;AACrD,SAAQ,GAAG,UAAU,aAAa,MAAM,WAAW,GAAG,MAAM;;AAK9D,MAAM,qBACJ,GACA,YAAYF,iCAAAA,UACZ,GAAG,UACA;AACH,QAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,MAAM,CAAC,CACxC,MACA,OAAO,GAAG,MAAM,UAAU,OAAOC,iCAAAA,oBAAoB;AAGnD,SAAO,KADO,UADC,MAAM,EAAE,GAAG,KAAK,CACA,EACZ,SAAS;GAE/B;;;;;;;;AASH,MAAa,gBAAgC,MAAM,cAAc;AAC/D,SAAQ,GAAG,UAAU,kBAAkB,MAAM,WAAW,GAAG,MAAM"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { UseAsyncEach_F, UseEach_F } from './pass.types';
|
|
2
|
+
/**
|
|
3
|
+
* A better version of **test.each**
|
|
4
|
+
*
|
|
5
|
+
* Type parameters
|
|
6
|
+
*
|
|
7
|
+
* @type A Parameters of the function, extends Array type
|
|
8
|
+
* @type R ReturnType of the function
|
|
9
|
+
*
|
|
10
|
+
* @if R are not provided, the return is a function to test with TestArgs arguments
|
|
11
|
+
*
|
|
12
|
+
* @else It tests every cases provided
|
|
13
|
+
*
|
|
14
|
+
* @param func The function to test
|
|
15
|
+
* @param cases The cases to test, The invite is the first arguments.
|
|
16
|
+
* It's an array of Array.
|
|
17
|
+
* * #1 The first arg is the invite of the test
|
|
18
|
+
*
|
|
19
|
+
* * #2 The second arg is the parameters to to pass to the function. It's an array (param array).
|
|
20
|
+
*
|
|
21
|
+
* * #3 The third arg is the expected result
|
|
22
|
+
*
|
|
23
|
+
* Example: For a function like ***(arg1: string)=>any***, the second arg with be : ***[string]***
|
|
24
|
+
* */
|
|
25
|
+
export declare const useEach: UseEach_F;
|
|
26
|
+
/**
|
|
27
|
+
* Same as ***useEach***
|
|
28
|
+
*
|
|
29
|
+
* But for async functions
|
|
30
|
+
*
|
|
31
|
+
* */
|
|
32
|
+
export declare const useEachAsync: UseAsyncEach_F;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defaultEquality, identity } from "../identity.js";
|
|
2
|
+
import { toArrayVitest } from "../toArray.js";
|
|
3
|
+
import { test } from "vitest";
|
|
4
|
+
//#region src/vitest-extended/each/pass.ts
|
|
5
|
+
const useEachCases = (func, transform = identity, ...cases) => {
|
|
6
|
+
test.concurrent.each(toArrayVitest(cases))("%s", (_, args, expected, test = defaultEquality) => {
|
|
7
|
+
return test(transform(func(...args)), expected);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A better version of **test.each**
|
|
12
|
+
*
|
|
13
|
+
* Type parameters
|
|
14
|
+
*
|
|
15
|
+
* @type A Parameters of the function, extends Array type
|
|
16
|
+
* @type R ReturnType of the function
|
|
17
|
+
*
|
|
18
|
+
* @if R are not provided, the return is a function to test with TestArgs arguments
|
|
19
|
+
*
|
|
20
|
+
* @else It tests every cases provided
|
|
21
|
+
*
|
|
22
|
+
* @param func The function to test
|
|
23
|
+
* @param cases The cases to test, The invite is the first arguments.
|
|
24
|
+
* It's an array of Array.
|
|
25
|
+
* * #1 The first arg is the invite of the test
|
|
26
|
+
*
|
|
27
|
+
* * #2 The second arg is the parameters to to pass to the function. It's an array (param array).
|
|
28
|
+
*
|
|
29
|
+
* * #3 The third arg is the expected result
|
|
30
|
+
*
|
|
31
|
+
* Example: For a function like ***(arg1: string)=>any***, the second arg with be : ***[string]***
|
|
32
|
+
* */
|
|
33
|
+
const useEach = (func, transform) => {
|
|
34
|
+
return (...cases) => useEachCases(func, transform, ...cases);
|
|
35
|
+
};
|
|
36
|
+
const useEachAsyncCases = (f, transform = identity, ...cases) => {
|
|
37
|
+
test.concurrent.each(toArrayVitest(cases))("%s", async (_, args, expected, test = defaultEquality) => {
|
|
38
|
+
return test(transform(await f(...args)), expected);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Same as ***useEach***
|
|
43
|
+
*
|
|
44
|
+
* But for async functions
|
|
45
|
+
*
|
|
46
|
+
* */
|
|
47
|
+
const useEachAsync = (func, transform) => {
|
|
48
|
+
return (...cases) => useEachAsyncCases(func, transform, ...cases);
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { useEach, useEachAsync };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=pass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pass.js","names":[],"sources":["../../../src/vitest-extended/each/pass.ts"],"sourcesContent":["import { test } from 'vitest';\nimport { defaultEquality, identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type {\n _UseAsyncEach_F,\n _UseEach_F,\n UseAsyncEach_F,\n UseEach_F,\n} from './pass.types';\n\n// #region Sync\nconst useEachCases: _UseEach_F = (\n func,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n (_, args, expected, test = defaultEquality) => {\n const value = transform(func(...args));\n return test(value, expected);\n },\n );\n};\n\n/**\n * A better version of **test.each**\n *\n * Type parameters\n *\n * @type A Parameters of the function, extends Array type\n * @type R ReturnType of the function\n *\n * @if R are not provided, the return is a function to test with TestArgs arguments\n *\n * @else It tests every cases provided\n *\n * @param func The function to test\n * @param cases The cases to test, The invite is the first arguments.\n * It's an array of Array.\n * * #1 The first arg is the invite of the test\n *\n * * #2 The second arg is the parameters to to pass to the function. It's an array (param array).\n *\n * * #3 The third arg is the expected result\n *\n * Example: For a function like ***(arg1: string)=>any***, the second arg with be : ***[string]***\n * */\nexport const useEach: UseEach_F = (func, transform) => {\n return (...cases) => useEachCases(func, transform, ...cases);\n};\n// #endregion\n\n// #region Async\nconst useEachAsyncCases: _UseAsyncEach_F = (\n f,\n transform = identity as any,\n ...cases\n) => {\n test.concurrent.each(toArrayVitest(cases))(\n '%s',\n async (_, args, expected, test = defaultEquality) => {\n const _value = await f(...args);\n const value = transform(_value);\n return test(value, expected);\n },\n );\n};\n\n/**\n * Same as ***useEach***\n *\n * But for async functions\n *\n * */\nexport const useEachAsync: UseAsyncEach_F = (func, transform) => {\n return (...cases) => useEachAsyncCases(func, transform, ...cases);\n};\n// #endregion\n"],"mappings":";;;;AAWA,MAAM,gBACJ,MACA,YAAY,UACZ,GAAG,UACA;AACH,MAAK,WAAW,KAAK,cAAc,MAAM,CAAC,CACxC,OACC,GAAG,MAAM,UAAU,OAAO,oBAAoB;AAE7C,SAAO,KADO,UAAU,KAAK,GAAG,KAAK,CAAC,EACnB,SAAS;GAE/B;;;;;;;;;;;;;;;;;;;;;;;;;AA0BH,MAAa,WAAsB,MAAM,cAAc;AACrD,SAAQ,GAAG,UAAU,aAAa,MAAM,WAAW,GAAG,MAAM;;AAK9D,MAAM,qBACJ,GACA,YAAY,UACZ,GAAG,UACA;AACH,MAAK,WAAW,KAAK,cAAc,MAAM,CAAC,CACxC,MACA,OAAO,GAAG,MAAM,UAAU,OAAO,oBAAoB;AAGnD,SAAO,KADO,UADC,MAAM,EAAE,GAAG,KAAK,CACA,EACZ,SAAS;GAE/B;;;;;;;;AASH,MAAa,gBAAgC,MAAM,cAAc;AAC/D,SAAQ,GAAG,UAAU,kBAAkB,MAAM,WAAW,GAAG,MAAM"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Fn } from '../bemedev/globals/types';
|
|
2
|
+
import type { ChainedFn, Identity, NextFn, TestArgs } from '../types';
|
|
3
|
+
export type _UseEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, ...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
4
|
+
export type UseEach_F = <F extends Fn, T extends NextFn<F> = Identity<F>>(f: F, transform?: T) => (...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
5
|
+
export type _UseAsyncEach_F = <F extends Fn<any, Promise<any>>, T extends NextFn<F> = Identity<F>>(f: F, transform?: T, ...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
6
|
+
export type UseAsyncEach_F = <F extends Fn<any, Promise<any>>, T extends NextFn<F> = Identity<F>>(f: F, transform?: T) => (...cases: TestArgs<ChainedFn<F, T>>) => void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_sleep = require("../utils/sleep.cjs");
|
|
3
|
+
//#region src/vitest-extended/fakeWaiter.ts
|
|
4
|
+
const buildInvite = (index = 0, ms = 0, times = 1) => `#${index} Wait for ${ms}ms times ${times}`;
|
|
5
|
+
const createFakeWaiter = (vi) => {
|
|
6
|
+
return async (ms = 0, times = 1) => {
|
|
7
|
+
const check = vi.isFakeTimers();
|
|
8
|
+
for (let i = 0; i < times; i++) if (check) await vi.advanceTimersByTimeAsync(ms);
|
|
9
|
+
else await require_utils_sleep.sleep(ms);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
createFakeWaiter.withDefaultDelay = (vi, ms = 0) => {
|
|
13
|
+
return (index, times = 1) => {
|
|
14
|
+
const invite = buildInvite(index, ms, times);
|
|
15
|
+
const fn = () => createFakeWaiter(vi)(ms, times);
|
|
16
|
+
return [invite, fn];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
createFakeWaiter.all = (vi) => {
|
|
20
|
+
return (index, ms = 0, times = 1) => {
|
|
21
|
+
const invite = buildInvite(index, ms, times);
|
|
22
|
+
const fn = () => createFakeWaiter(vi)(ms, times);
|
|
23
|
+
return [invite, fn];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.createFakeWaiter = createFakeWaiter;
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=fakeWaiter.cjs.map
|