@bemedev/dev-utils 1.1.1 → 1.3.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/README.md +121 -0
- package/lib/_virtual/_rolldown/runtime.cjs +1 -1
- package/lib/build-tests/addTarball.cjs +5 -1
- package/lib/build-tests/addTarball.cjs.map +1 -1
- package/lib/build-tests/addTarball.d.ts +3 -0
- package/lib/build-tests/addTarball.js +5 -1
- package/lib/build-tests/addTarball.js.map +1 -1
- package/lib/build-tests/buildPackageJson.cjs +17 -9
- package/lib/build-tests/buildPackageJson.cjs.map +1 -1
- package/lib/build-tests/buildPackageJson.d.ts +5 -0
- package/lib/build-tests/buildPackageJson.js +17 -9
- package/lib/build-tests/buildPackageJson.js.map +1 -1
- package/lib/build-tests/cleanup.cjs +3 -0
- package/lib/build-tests/cleanup.cjs.map +1 -1
- package/lib/build-tests/cleanup.d.ts +3 -0
- package/lib/build-tests/cleanup.js +3 -0
- package/lib/build-tests/cleanup.js.map +1 -1
- package/lib/build-tests/cli/cli.cjs +6 -0
- package/lib/build-tests/cli/cli.cjs.map +1 -1
- package/lib/build-tests/cli/cli.d.ts +6 -0
- package/lib/build-tests/cli/cli.js +6 -0
- package/lib/build-tests/cli/cli.js.map +1 -1
- package/lib/build-tests/cli/index.cjs.map +1 -1
- package/lib/build-tests/cli/post.cjs +3 -0
- package/lib/build-tests/cli/post.cjs.map +1 -1
- package/lib/build-tests/cli/post.d.ts +3 -0
- package/lib/build-tests/cli/post.js +3 -0
- package/lib/build-tests/cli/post.js.map +1 -1
- package/lib/build-tests/cli/pre.cjs +3 -0
- package/lib/build-tests/cli/pre.cjs.map +1 -1
- package/lib/build-tests/cli/pre.d.ts +3 -0
- package/lib/build-tests/cli/pre.js +3 -0
- package/lib/build-tests/cli/pre.js.map +1 -1
- package/lib/build-tests/cli/test.cjs +3 -0
- package/lib/build-tests/cli/test.cjs.map +1 -1
- package/lib/build-tests/cli/test.d.ts +3 -0
- package/lib/build-tests/cli/test.js +3 -0
- package/lib/build-tests/cli/test.js.map +1 -1
- package/lib/build-tests/constants.cjs +42 -0
- package/lib/build-tests/constants.cjs.map +1 -1
- package/lib/build-tests/constants.d.ts +42 -0
- package/lib/build-tests/constants.js +42 -0
- package/lib/build-tests/constants.js.map +1 -1
- package/lib/build-tests/getRelativePath.cjs +7 -0
- package/lib/build-tests/getRelativePath.cjs.map +1 -1
- package/lib/build-tests/getRelativePath.d.ts +7 -0
- package/lib/build-tests/getRelativePath.js +7 -0
- package/lib/build-tests/getRelativePath.js.map +1 -1
- package/lib/build-tests/getTypescriptOutdir.cjs +5 -0
- package/lib/build-tests/getTypescriptOutdir.cjs.map +1 -1
- package/lib/build-tests/getTypescriptOutdir.d.ts +5 -0
- package/lib/build-tests/getTypescriptOutdir.js +5 -0
- package/lib/build-tests/getTypescriptOutdir.js.map +1 -1
- package/lib/build-tests/import.cjs +9 -0
- package/lib/build-tests/import.cjs.map +1 -1
- package/lib/build-tests/import.d.ts +9 -0
- package/lib/build-tests/import.js +9 -0
- package/lib/build-tests/import.js.map +1 -1
- package/lib/build-tests/imports/create.cjs +7 -0
- package/lib/build-tests/imports/create.cjs.map +1 -1
- package/lib/build-tests/imports/create.d.ts +13 -0
- package/lib/build-tests/imports/create.js +7 -0
- package/lib/build-tests/imports/create.js.map +1 -1
- package/lib/build-tests/imports/helper.cjs +9 -0
- package/lib/build-tests/imports/helper.cjs.map +1 -1
- package/lib/build-tests/imports/helper.d.ts +12 -0
- package/lib/build-tests/imports/helper.js +9 -0
- package/lib/build-tests/imports/helper.js.map +1 -1
- package/lib/build-tests/pack.cjs +7 -1
- package/lib/build-tests/pack.cjs.map +1 -1
- package/lib/build-tests/pack.d.ts +5 -0
- package/lib/build-tests/pack.js +7 -1
- package/lib/build-tests/pack.js.map +1 -1
- package/lib/plugins/hmr.cjs +72 -0
- package/lib/plugins/hmr.cjs.map +1 -0
- package/lib/plugins/hmr.d.ts +22 -0
- package/lib/plugins/hmr.js +71 -0
- package/lib/plugins/hmr.js.map +1 -0
- package/lib/plugins/index.cjs +5 -0
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +3 -0
- package/lib/plugins/suppressWarnings.cjs +37 -0
- package/lib/plugins/suppressWarnings.cjs.map +1 -0
- package/lib/plugins/suppressWarnings.d.ts +12 -0
- package/lib/plugins/suppressWarnings.js +36 -0
- package/lib/plugins/suppressWarnings.js.map +1 -0
- package/lib/rolldown-config/config.cjs +13 -5
- package/lib/rolldown-config/config.cjs.map +1 -1
- package/lib/rolldown-config/config.d.ts +7 -0
- package/lib/rolldown-config/config.js +13 -5
- package/lib/rolldown-config/config.js.map +1 -1
- package/lib/rolldown-config/constants.cjs +15 -0
- package/lib/rolldown-config/constants.cjs.map +1 -1
- package/lib/rolldown-config/constants.d.ts +15 -0
- package/lib/rolldown-config/constants.js +15 -0
- package/lib/rolldown-config/constants.js.map +1 -1
- package/lib/rolldown-config/helpers.cjs +16 -1
- package/lib/rolldown-config/helpers.cjs.map +1 -1
- package/lib/rolldown-config/helpers.d.ts +14 -0
- package/lib/rolldown-config/helpers.js +16 -1
- package/lib/rolldown-config/helpers.js.map +1 -1
- package/lib/rolldown-config/input.cjs +8 -0
- package/lib/rolldown-config/input.cjs.map +1 -1
- package/lib/rolldown-config/input.d.ts +8 -0
- package/lib/rolldown-config/input.js +8 -0
- package/lib/rolldown-config/input.js.map +1 -1
- package/lib/rolldown-config/output.cjs +8 -0
- package/lib/rolldown-config/output.cjs.map +1 -1
- package/lib/rolldown-config/output.d.ts +8 -0
- package/lib/rolldown-config/output.js +8 -0
- package/lib/rolldown-config/output.js.map +1 -1
- package/lib/rolldown-config/plugins/circulars.cjs +5 -5
- package/lib/rolldown-config/plugins/circulars.cjs.map +1 -1
- package/lib/rolldown-config/plugins/circulars.d.ts +10 -6
- package/lib/rolldown-config/plugins/circulars.js +5 -5
- package/lib/rolldown-config/plugins/circulars.js.map +1 -1
- package/lib/rolldown-config/plugins/clean.cjs +10 -1
- package/lib/rolldown-config/plugins/clean.cjs.map +1 -1
- package/lib/rolldown-config/plugins/clean.d.ts +10 -0
- package/lib/rolldown-config/plugins/clean.js +10 -1
- package/lib/rolldown-config/plugins/clean.js.map +1 -1
- package/lib/rolldown-config/plugins/externals.cjs +4 -3
- package/lib/rolldown-config/plugins/externals.cjs.map +1 -1
- package/lib/rolldown-config/plugins/externals.d.ts +7 -3
- package/lib/rolldown-config/plugins/externals.js +4 -3
- package/lib/rolldown-config/plugins/externals.js.map +1 -1
- package/lib/rolldown-config/plugins/index.cjs +6 -0
- package/lib/rolldown-config/plugins/index.cjs.map +1 -1
- package/lib/rolldown-config/plugins/index.d.ts +6 -0
- package/lib/rolldown-config/plugins/index.js +6 -0
- package/lib/rolldown-config/plugins/index.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.cjs +7 -0
- package/lib/rolldown-config/plugins/typescript.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.cjs +15 -0
- package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.d.ts +15 -0
- package/lib/rolldown-config/plugins/typescript.config.js +15 -0
- package/lib/rolldown-config/plugins/typescript.config.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.d.ts +10 -0
- package/lib/rolldown-config/plugins/typescript.fast.cjs +9 -1
- package/lib/rolldown-config/plugins/typescript.fast.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.fast.d.ts +10 -0
- package/lib/rolldown-config/plugins/typescript.fast.js +9 -1
- package/lib/rolldown-config/plugins/typescript.fast.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.js +7 -0
- package/lib/rolldown-config/plugins/typescript.js.map +1 -1
- package/lib/rolldown-config/types.d.ts +18 -0
- package/lib/utils/array.cjs +7 -0
- package/lib/utils/array.cjs.map +1 -1
- package/lib/utils/array.d.ts +8 -0
- package/lib/utils/array.js +7 -0
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/bemedev/globals/types.d.ts +20 -0
- package/lib/utils/bemedev/globals/utils/expandFn.cjs +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.cjs.map +1 -1
- package/lib/utils/bemedev/globals/utils/expandFn.d.ts +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.js +11 -0
- package/lib/utils/bemedev/globals/utils/expandFn.js.map +1 -1
- package/lib/utils/clamp.cjs +18 -0
- package/lib/utils/clamp.cjs.map +1 -0
- package/lib/utils/clamp.d.ts +10 -0
- package/lib/utils/clamp.js +17 -0
- package/lib/utils/clamp.js.map +1 -0
- package/lib/utils/identity.cjs +9 -0
- package/lib/utils/identity.cjs.map +1 -1
- package/lib/utils/identity.d.ts +9 -0
- package/lib/utils/identity.js +9 -0
- package/lib/utils/identity.js.map +1 -1
- package/lib/utils/index.cjs +2 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -1
- package/lib/utils/sleep.cjs +7 -0
- package/lib/utils/sleep.cjs.map +1 -1
- package/lib/utils/sleep.d.ts +7 -0
- package/lib/utils/sleep.js +7 -0
- package/lib/utils/sleep.js.map +1 -1
- package/lib/utils/types.d.ts +17 -1
- package/lib/vitest-exclude/constants.cjs +3 -0
- package/lib/vitest-exclude/constants.cjs.map +1 -1
- package/lib/vitest-exclude/constants.d.ts +3 -0
- package/lib/vitest-exclude/constants.js +3 -0
- package/lib/vitest-exclude/constants.js.map +1 -1
- package/lib/vitest-exclude/types.d.ts +11 -0
- package/lib/vitest-exclude/vitest.cjs +25 -12
- package/lib/vitest-exclude/vitest.cjs.map +1 -1
- package/lib/vitest-exclude/vitest.d.ts +9 -8
- package/lib/vitest-exclude/vitest.js +25 -12
- package/lib/vitest-exclude/vitest.js.map +1 -1
- package/lib/vitest-exclude/vitest.utils.cjs +30 -0
- package/lib/vitest-exclude/vitest.utils.cjs.map +1 -1
- package/lib/vitest-exclude/vitest.utils.d.ts +30 -0
- package/lib/vitest-exclude/vitest.utils.js +30 -0
- package/lib/vitest-exclude/vitest.utils.js.map +1 -1
- package/lib/vitest-extended/acceptation.cjs +11 -2
- package/lib/vitest-extended/acceptation.cjs.map +1 -1
- package/lib/vitest-extended/acceptation.d.ts +9 -1
- package/lib/vitest-extended/acceptation.js +11 -2
- package/lib/vitest-extended/acceptation.js.map +1 -1
- package/lib/vitest-extended/createTests.cjs +34 -27
- package/lib/vitest-extended/createTests.cjs.map +1 -1
- package/lib/vitest-extended/createTests.d.ts +20 -37
- package/lib/vitest-extended/createTests.js +34 -27
- package/lib/vitest-extended/createTests.js.map +1 -1
- package/lib/vitest-extended/createTests.types.d.ts +13 -2
- package/lib/vitest-extended/done.cjs +18 -15
- package/lib/vitest-extended/done.cjs.map +1 -1
- package/lib/vitest-extended/done.d.ts +6 -5
- package/lib/vitest-extended/done.js +18 -15
- package/lib/vitest-extended/done.js.map +1 -1
- package/lib/vitest-extended/each/error.cjs +12 -0
- package/lib/vitest-extended/each/error.cjs.map +1 -1
- package/lib/vitest-extended/each/error.d.ts +12 -0
- package/lib/vitest-extended/each/error.js +12 -0
- package/lib/vitest-extended/each/error.js.map +1 -1
- package/lib/vitest-extended/each/error.types.d.ts +17 -0
- package/lib/vitest-extended/each/pass.cjs +9 -20
- package/lib/vitest-extended/each/pass.cjs.map +1 -1
- package/lib/vitest-extended/each/pass.d.ts +9 -20
- package/lib/vitest-extended/each/pass.js +9 -20
- package/lib/vitest-extended/each/pass.js.map +1 -1
- package/lib/vitest-extended/each/pass.types.d.ts +24 -0
- package/lib/vitest-extended/fakeWaiter.cjs +7 -0
- package/lib/vitest-extended/fakeWaiter.cjs.map +1 -1
- package/lib/vitest-extended/fakeWaiter.d.ts +32 -0
- package/lib/vitest-extended/fakeWaiter.js +7 -0
- package/lib/vitest-extended/fakeWaiter.js.map +1 -1
- package/lib/vitest-extended/fixtures/coverage.cjs +11 -0
- package/lib/vitest-extended/fixtures/coverage.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/coverage.js +11 -0
- package/lib/vitest-extended/fixtures/coverage.js.map +1 -1
- package/lib/vitest-extended/fixtures/partialCall.cjs +9 -4
- package/lib/vitest-extended/fixtures/partialCall.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/partialCall.js +9 -4
- package/lib/vitest-extended/fixtures/partialCall.js.map +1 -1
- package/lib/vitest-extended/fixtures/toUpper.cjs +18 -0
- package/lib/vitest-extended/fixtures/toUpper.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/toUpper.js +18 -0
- package/lib/vitest-extended/fixtures/toUpper.js.map +1 -1
- package/lib/vitest-extended/fixtures/vitest.cjs +3 -0
- package/lib/vitest-extended/fixtures/vitest.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/vitest.js +3 -0
- package/lib/vitest-extended/fixtures/vitest.js.map +1 -1
- package/lib/vitest-extended/fixtures/zod.cjs +22 -0
- package/lib/vitest-extended/fixtures/zod.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/zod.js +22 -0
- package/lib/vitest-extended/fixtures/zod.js.map +1 -1
- package/lib/vitest-extended/identity.cjs +18 -0
- package/lib/vitest-extended/identity.cjs.map +1 -1
- package/lib/vitest-extended/identity.d.ts +18 -0
- package/lib/vitest-extended/identity.js +18 -0
- package/lib/vitest-extended/identity.js.map +1 -1
- package/lib/vitest-extended/isDefined.cjs +9 -0
- package/lib/vitest-extended/isDefined.cjs.map +1 -1
- package/lib/vitest-extended/isDefined.d.ts +9 -0
- package/lib/vitest-extended/isDefined.js +9 -0
- package/lib/vitest-extended/isDefined.js.map +1 -1
- package/lib/vitest-extended/isFunction.cjs +7 -0
- package/lib/vitest-extended/isFunction.cjs.map +1 -1
- package/lib/vitest-extended/isFunction.d.ts +7 -0
- package/lib/vitest-extended/isFunction.js +7 -0
- package/lib/vitest-extended/isFunction.js.map +1 -1
- package/lib/vitest-extended/project.cjs +7 -0
- package/lib/vitest-extended/project.cjs.map +1 -1
- package/lib/vitest-extended/project.d.ts +7 -0
- package/lib/vitest-extended/project.js +7 -0
- package/lib/vitest-extended/project.js.map +1 -1
- package/lib/vitest-extended/toArray.cjs +6 -0
- package/lib/vitest-extended/toArray.cjs.map +1 -1
- package/lib/vitest-extended/toArray.d.ts +6 -0
- package/lib/vitest-extended/toArray.js +6 -0
- package/lib/vitest-extended/toArray.js.map +1 -1
- package/lib/vitest-extended/toStringFlat.cjs +8 -0
- package/lib/vitest-extended/toStringFlat.cjs.map +1 -1
- package/lib/vitest-extended/toStringFlat.d.ts +8 -0
- package/lib/vitest-extended/toStringFlat.js +8 -0
- package/lib/vitest-extended/toStringFlat.js.map +1 -1
- package/lib/vitest-extended/types.d.ts +64 -0
- package/package.json +14 -9
|
@@ -36,42 +36,49 @@ const _create = (func, transform, toError, name) => {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
* Creates
|
|
40
|
-
* {@link useEach|see}
|
|
39
|
+
* Creates structured test suites with acceptation, success, and failure runners.
|
|
41
40
|
*
|
|
42
|
-
* @
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* (acc, value) => {
|
|
46
|
-
* acc+=value
|
|
47
|
-
* return acc;
|
|
48
|
-
* },
|
|
49
|
-
* 0)
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* // .add.test.ts
|
|
53
|
-
* *import { createTests } from '@bemedev/vitest-extended';
|
|
54
|
-
* *import { add } from './add';
|
|
41
|
+
* @template `F0` - Function parameters array type.
|
|
42
|
+
* @template `F1` - Function return value type.
|
|
43
|
+
* @template `F2` - Transformed return value type, defaults to `F1`.
|
|
55
44
|
*
|
|
56
|
-
*
|
|
45
|
+
* @param func - Function under test of type {@linkcode Fn}.
|
|
46
|
+
* @param args - Configuration options.
|
|
47
|
+
* @param args.transform - Optional output transformer of type {@linkcode Fn}.
|
|
48
|
+
* @param args.toError - Optional error mapping function of type {@linkcode Fn}.
|
|
57
49
|
*
|
|
58
|
-
*
|
|
59
|
-
* {
|
|
60
|
-
* invite: 'For : 1,2,3,4,5,6,7,8,9',
|
|
61
|
-
* parameters: [[1, 2, 3, 4, 5, 6, 7, 8, 9]], // like this!
|
|
62
|
-
* }
|
|
63
|
-
* )
|
|
50
|
+
* @returns Test suite object with acceptation, success, and fails methods.
|
|
64
51
|
*
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const useTests = createTests(add);
|
|
55
|
+
* useTests.success({
|
|
56
|
+
* invite: 'For : 1,2,3',
|
|
57
|
+
* parameters: [[1, 2, 3]],
|
|
58
|
+
* expected: 6,
|
|
59
|
+
* })();
|
|
60
|
+
* ```
|
|
70
61
|
*/
|
|
71
62
|
const createTests = (func, args) => {
|
|
72
63
|
const { transform, toError } = args || {};
|
|
73
64
|
return _create(func, transform, toError);
|
|
74
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Creates structured test suites with an async instantiation or mock implementation.
|
|
68
|
+
*
|
|
69
|
+
* @template `F0` - Function parameters array type.
|
|
70
|
+
* @template `F1` - Function return value type.
|
|
71
|
+
* @template `F2` - Transformed return value type, defaults to `F1`.
|
|
72
|
+
*
|
|
73
|
+
* @param f - Fallback or default function of type {@linkcode Fn}.
|
|
74
|
+
* @param options - Configuration options for instantiation and formatting.
|
|
75
|
+
* @param options.instanciation - Async function returning the target implementation.
|
|
76
|
+
* @param options.name - Name identifier for test descriptions.
|
|
77
|
+
* @param options.transform - Optional output transformer.
|
|
78
|
+
* @param options.toError - Optional error mapping function.
|
|
79
|
+
*
|
|
80
|
+
* @returns Test suite object with acceptation, success, and fails methods.
|
|
81
|
+
*/
|
|
75
82
|
createTests.withImplementation = (f, { instanciation, name, transform, toError }) => {
|
|
76
83
|
const func = vitest.vi.fn(f);
|
|
77
84
|
if (instanciation) (0, vitest.beforeAll)(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTests.cjs","names":["useTFA","useErrorAsyncEach","toStringFlat","useEachAsync","vi"],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import { beforeAll, vi } from 'vitest';\n\nimport type { Fn } from '../utils/bemedev/globals/types';\nimport { useTFA } from './acceptation';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport {
|
|
1
|
+
{"version":3,"file":"createTests.cjs","names":["useTFA","useErrorAsyncEach","toStringFlat","useEachAsync","vi"],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import { beforeAll, vi } from 'vitest';\n\nimport type { Fn } from '../utils/bemedev/globals/types';\nimport { useTFA } from './acceptation';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport { useEachAsync } from './each/pass';\nimport { toStringFlat } from './toStringFlat';\n\nexport type { _CreateTests_F };\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(\n func,\n transform as any,\n toError,\n );\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 as any, 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 structured test suites with acceptation, success, and failure runners.\n *\n * @template `F0` - Function parameters array type.\n * @template `F1` - Function return value type.\n * @template `F2` - Transformed return value type, defaults to `F1`.\n *\n * @param func - Function under test of type {@linkcode Fn}.\n * @param args - Configuration options.\n * @param args.transform - Optional output transformer of type {@linkcode Fn}.\n * @param args.toError - Optional error mapping function of type {@linkcode Fn}.\n *\n * @returns Test suite object with acceptation, success, and fails methods.\n *\n * @example\n * ```ts\n * const useTests = createTests(add);\n * useTests.success({\n * invite: 'For : 1,2,3',\n * parameters: [[1, 2, 3]],\n * expected: 6,\n * })();\n * ```\n */\nexport const createTests = <F0 extends any[], F1, F2 = F1>(\n func: Fn<F0, F1>,\n args?: {\n transform?: Fn<[Awaited<F1>], F2>;\n toError?: Fn<F0, string | undefined>;\n },\n) => {\n const { transform, toError } = args || {};\n return _create(func, transform, toError);\n};\n\n/**\n * Creates structured test suites with an async instantiation or mock implementation.\n *\n * @template `F0` - Function parameters array type.\n * @template `F1` - Function return value type.\n * @template `F2` - Transformed return value type, defaults to `F1`.\n *\n * @param f - Fallback or default function of type {@linkcode Fn}.\n * @param options - Configuration options for instantiation and formatting.\n * @param options.instanciation - Async function returning the target implementation.\n * @param options.name - Name identifier for test descriptions.\n * @param options.transform - Optional output transformer.\n * @param options.toError - Optional error mapping function.\n *\n * @returns Test suite object with acceptation, success, and fails methods.\n */\ncreateTests.withImplementation = <F0 extends any[], F1, F2 = F1>(\n f: Fn<NoInfer<F0>, NoInfer<F1>>,\n {\n instanciation,\n name,\n transform,\n toError,\n }: {\n instanciation: () => Promise<Fn<F0, F1>> | Fn<F0, F1>;\n name: string;\n transform?: Fn<[Awaited<F1>], F2>;\n toError?: Fn<F0, string | undefined>;\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":";;;;;;;AAWA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;CAClE,OAAO;EACL,mBAAmBA,oCAAAA,OAAO,MAAM,IAAI;EAEpC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;GAErB,aAAa;IAeX,OAdiBC,mCAAAA,kBACf,MACA,WACA,OAWY,CAAC,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,SAAS,UAAU;KAGjD,OAAO;MADO,QAAA,IADKC,qCAAAA,aAAa,QAAQ,GAAG,MAAM,EAAE,MAAM;MACnC;MAAY;KACzB;IACX,CAGsB,CAAC;GAC3B;EACF;EAEA,UAAU,GAAG,UAAU;GACrB,MAAM,SAAS,MAAM;GACrB,aAAa;IAWX,OAViBC,kCAAAA,aAAa,MAAa,SAU7B,CAAC,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,UAAU,QAAQ,UAAU;KAG1D,OAAO;MADO,QAAA,IADKD,qCAAAA,aAAa,QAAQ,GAAG,MAAM,EAAE,MAAM;MACnC;MAAY;MAAU;KACnC;IACX,CAGsB,CAAC;GAC3B;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,eACX,MACA,SAIG;CACH,MAAM,EAAE,WAAW,YAAY,QAAQ,CAAC;CACxC,OAAO,QAAQ,MAAM,WAAW,OAAO;AACzC;;;;;;;;;;;;;;;;;AAkBA,YAAY,sBACV,GACA,EACE,eACA,MACA,WACA,cAOC;CACH,MAAM,OAAOE,OAAAA,GAAG,GAAG,CAAC;CAEpB,IAAI,eACF,CAAA,GAAA,OAAA,UAAA,CAAU,YAAY;EACpB,MAAM,OAAO,MAAM,cAAc;EACjC,KAAK,mBAAmB,IAAI;CAC9B,CAAC;CAGH,OAAO,QAAQ,MAAM,WAAW,SAAS,IAAI;AAC/C;AAEA,YAAY,wBAAwB"}
|
|
@@ -2,56 +2,39 @@ import type { Fn } from '../utils/bemedev/globals/types';
|
|
|
2
2
|
import type { _CreateTests_F } from './createTests.types';
|
|
3
3
|
export type { _CreateTests_F };
|
|
4
4
|
/**
|
|
5
|
-
* Creates
|
|
6
|
-
* {@link useEach|see}
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // ./add.ts
|
|
10
|
-
* *export const add = (args: string[]) => args.reduce(
|
|
11
|
-
* (acc, value) => {
|
|
12
|
-
* acc+=value
|
|
13
|
-
* return acc;
|
|
14
|
-
* },
|
|
15
|
-
* 0)
|
|
5
|
+
* Creates structured test suites with acceptation, success, and failure runners.
|
|
16
6
|
*
|
|
7
|
+
* @template `F0` - Function parameters array type.
|
|
8
|
+
* @template `F1` - Function return value type.
|
|
9
|
+
* @template `F2` - Transformed return value type, defaults to `F1`.
|
|
17
10
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
11
|
+
* @param func - Function under test of type {@linkcode Fn}.
|
|
12
|
+
* @param args - Configuration options.
|
|
13
|
+
* @param args.transform - Optional output transformer of type {@linkcode Fn}.
|
|
14
|
+
* @param args.toError - Optional error mapping function of type {@linkcode Fn}.
|
|
21
15
|
*
|
|
22
|
-
*
|
|
16
|
+
* @returns Test suite object with acceptation, success, and fails methods.
|
|
23
17
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @param *
|
|
34
|
-
* @returns A test.each like function to tests many cases NB: If the first
|
|
35
|
-
* argument is an array, wrap the value in another array,
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const useTests = createTests(add);
|
|
21
|
+
* useTests.success({
|
|
22
|
+
* invite: 'For : 1,2,3',
|
|
23
|
+
* parameters: [[1, 2, 3]],
|
|
24
|
+
* expected: 6,
|
|
25
|
+
* })();
|
|
26
|
+
* ```
|
|
36
27
|
*/
|
|
37
28
|
export declare const createTests: {
|
|
38
29
|
<F0 extends any[], F1, F2 = F1>(func: Fn<F0, F1>, args?: {
|
|
39
30
|
transform?: Fn<[Awaited<F1>], F2>;
|
|
40
31
|
toError?: Fn<F0, string | undefined>;
|
|
41
|
-
}):
|
|
42
|
-
acceptation: () => void;
|
|
43
|
-
success: (...cases: import("./types").TestArgs<Fn<F0, F2>>) => () => void;
|
|
44
|
-
fails: (...cases: import("./types").TestErrors<Fn<F0, F2>>) => () => void;
|
|
45
|
-
};
|
|
32
|
+
}): import("./createTests.types").ReturnR<Fn<F0, F2>>;
|
|
46
33
|
withImplementation<F0 extends any[], F1, F2 = F1>(f: Fn<NoInfer<F0>, NoInfer<F1>>, { instanciation, name, transform, toError, }: {
|
|
47
34
|
instanciation: () => Promise<Fn<F0, F1>> | Fn<F0, F1>;
|
|
48
35
|
name: string;
|
|
49
36
|
transform?: Fn<[Awaited<F1>], F2>;
|
|
50
37
|
toError?: Fn<F0, string | undefined>;
|
|
51
|
-
}):
|
|
52
|
-
acceptation: () => void;
|
|
53
|
-
success: (...cases: import("./types").TestArgs<Fn<F0, F2>>) => () => void;
|
|
54
|
-
fails: (...cases: import("./types").TestErrors<Fn<F0, F2>>) => () => void;
|
|
55
|
-
};
|
|
38
|
+
}): import("./createTests.types").ReturnR<Fn<F0, F2>>;
|
|
56
39
|
withoutImplementation: /*elided*/ any;
|
|
57
40
|
};
|
|
@@ -35,42 +35,49 @@ const _create = (func, transform, toError, name) => {
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
|
-
* Creates
|
|
39
|
-
* {@link useEach|see}
|
|
38
|
+
* Creates structured test suites with acceptation, success, and failure runners.
|
|
40
39
|
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* (acc, value) => {
|
|
45
|
-
* acc+=value
|
|
46
|
-
* return acc;
|
|
47
|
-
* },
|
|
48
|
-
* 0)
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* // .add.test.ts
|
|
52
|
-
* *import { createTests } from '@bemedev/vitest-extended';
|
|
53
|
-
* *import { add } from './add';
|
|
40
|
+
* @template `F0` - Function parameters array type.
|
|
41
|
+
* @template `F1` - Function return value type.
|
|
42
|
+
* @template `F2` - Transformed return value type, defaults to `F1`.
|
|
54
43
|
*
|
|
55
|
-
*
|
|
44
|
+
* @param func - Function under test of type {@linkcode Fn}.
|
|
45
|
+
* @param args - Configuration options.
|
|
46
|
+
* @param args.transform - Optional output transformer of type {@linkcode Fn}.
|
|
47
|
+
* @param args.toError - Optional error mapping function of type {@linkcode Fn}.
|
|
56
48
|
*
|
|
57
|
-
*
|
|
58
|
-
* {
|
|
59
|
-
* invite: 'For : 1,2,3,4,5,6,7,8,9',
|
|
60
|
-
* parameters: [[1, 2, 3, 4, 5, 6, 7, 8, 9]], // like this!
|
|
61
|
-
* }
|
|
62
|
-
* )
|
|
49
|
+
* @returns Test suite object with acceptation, success, and fails methods.
|
|
63
50
|
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const useTests = createTests(add);
|
|
54
|
+
* useTests.success({
|
|
55
|
+
* invite: 'For : 1,2,3',
|
|
56
|
+
* parameters: [[1, 2, 3]],
|
|
57
|
+
* expected: 6,
|
|
58
|
+
* })();
|
|
59
|
+
* ```
|
|
69
60
|
*/
|
|
70
61
|
const createTests = (func, args) => {
|
|
71
62
|
const { transform, toError } = args || {};
|
|
72
63
|
return _create(func, transform, toError);
|
|
73
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Creates structured test suites with an async instantiation or mock implementation.
|
|
67
|
+
*
|
|
68
|
+
* @template `F0` - Function parameters array type.
|
|
69
|
+
* @template `F1` - Function return value type.
|
|
70
|
+
* @template `F2` - Transformed return value type, defaults to `F1`.
|
|
71
|
+
*
|
|
72
|
+
* @param f - Fallback or default function of type {@linkcode Fn}.
|
|
73
|
+
* @param options - Configuration options for instantiation and formatting.
|
|
74
|
+
* @param options.instanciation - Async function returning the target implementation.
|
|
75
|
+
* @param options.name - Name identifier for test descriptions.
|
|
76
|
+
* @param options.transform - Optional output transformer.
|
|
77
|
+
* @param options.toError - Optional error mapping function.
|
|
78
|
+
*
|
|
79
|
+
* @returns Test suite object with acceptation, success, and fails methods.
|
|
80
|
+
*/
|
|
74
81
|
createTests.withImplementation = (f, { instanciation, name, transform, toError }) => {
|
|
75
82
|
const func = vi.fn(f);
|
|
76
83
|
if (instanciation) beforeAll(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTests.js","names":[],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import { beforeAll, vi } from 'vitest';\n\nimport type { Fn } from '../utils/bemedev/globals/types';\nimport { useTFA } from './acceptation';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport {
|
|
1
|
+
{"version":3,"file":"createTests.js","names":[],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import { beforeAll, vi } from 'vitest';\n\nimport type { Fn } from '../utils/bemedev/globals/types';\nimport { useTFA } from './acceptation';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport { useEachAsync } from './each/pass';\nimport { toStringFlat } from './toStringFlat';\n\nexport type { _CreateTests_F };\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(\n func,\n transform as any,\n toError,\n );\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 as any, 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 structured test suites with acceptation, success, and failure runners.\n *\n * @template `F0` - Function parameters array type.\n * @template `F1` - Function return value type.\n * @template `F2` - Transformed return value type, defaults to `F1`.\n *\n * @param func - Function under test of type {@linkcode Fn}.\n * @param args - Configuration options.\n * @param args.transform - Optional output transformer of type {@linkcode Fn}.\n * @param args.toError - Optional error mapping function of type {@linkcode Fn}.\n *\n * @returns Test suite object with acceptation, success, and fails methods.\n *\n * @example\n * ```ts\n * const useTests = createTests(add);\n * useTests.success({\n * invite: 'For : 1,2,3',\n * parameters: [[1, 2, 3]],\n * expected: 6,\n * })();\n * ```\n */\nexport const createTests = <F0 extends any[], F1, F2 = F1>(\n func: Fn<F0, F1>,\n args?: {\n transform?: Fn<[Awaited<F1>], F2>;\n toError?: Fn<F0, string | undefined>;\n },\n) => {\n const { transform, toError } = args || {};\n return _create(func, transform, toError);\n};\n\n/**\n * Creates structured test suites with an async instantiation or mock implementation.\n *\n * @template `F0` - Function parameters array type.\n * @template `F1` - Function return value type.\n * @template `F2` - Transformed return value type, defaults to `F1`.\n *\n * @param f - Fallback or default function of type {@linkcode Fn}.\n * @param options - Configuration options for instantiation and formatting.\n * @param options.instanciation - Async function returning the target implementation.\n * @param options.name - Name identifier for test descriptions.\n * @param options.transform - Optional output transformer.\n * @param options.toError - Optional error mapping function.\n *\n * @returns Test suite object with acceptation, success, and fails methods.\n */\ncreateTests.withImplementation = <F0 extends any[], F1, F2 = F1>(\n f: Fn<NoInfer<F0>, NoInfer<F1>>,\n {\n instanciation,\n name,\n transform,\n toError,\n }: {\n instanciation: () => Promise<Fn<F0, F1>> | Fn<F0, F1>;\n name: string;\n transform?: Fn<[Awaited<F1>], F2>;\n toError?: Fn<F0, string | undefined>;\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":";;;;;;AAWA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;CAClE,OAAO;EACL,mBAAmB,OAAO,MAAM,IAAI;EAEpC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;GAErB,aAAa;IAeX,OAdiB,kBACf,MACA,WACA,OAWY,CAAC,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,SAAS,UAAU;KAGjD,OAAO;MADO,QAAA,IADK,aAAa,QAAQ,GAAG,MAAM,EAAE,MAAM;MACnC;MAAY;KACzB;IACX,CAGsB,CAAC;GAC3B;EACF;EAEA,UAAU,GAAG,UAAU;GACrB,MAAM,SAAS,MAAM;GACrB,aAAa;IAWX,OAViB,aAAa,MAAa,SAU7B,CAAC,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,UAAU,QAAQ,UAAU;KAG1D,OAAO;MADO,QAAA,IADK,aAAa,QAAQ,GAAG,MAAM,EAAE,MAAM;MACnC;MAAY;MAAU;KACnC;IACX,CAGsB,CAAC;GAC3B;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,eACX,MACA,SAIG;CACH,MAAM,EAAE,WAAW,YAAY,QAAQ,CAAC;CACxC,OAAO,QAAQ,MAAM,WAAW,OAAO;AACzC;;;;;;;;;;;;;;;;;AAkBA,YAAY,sBACV,GACA,EACE,eACA,MACA,WACA,cAOC;CACH,MAAM,OAAO,GAAG,GAAG,CAAC;CAEpB,IAAI,eACF,UAAU,YAAY;EACpB,MAAM,OAAO,MAAM,cAAc;EACjC,KAAK,mBAAmB,IAAI;CAC9B,CAAC;CAGH,OAAO,QAAQ,MAAM,WAAW,SAAS,IAAI;AAC/C;AAEA,YAAY,wBAAwB"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { Fn } from '../utils/bemedev/globals/types';
|
|
2
2
|
import type { TestArgs, TestErrors } from './types';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Return interface for test suite generator containing acceptation, success, and fails methods.
|
|
5
|
+
*
|
|
6
|
+
* @template | {@linkcode Fn} `F` - Target test function type.
|
|
7
|
+
*/
|
|
8
|
+
export type ReturnR<F extends Fn> = {
|
|
4
9
|
acceptation: () => void;
|
|
5
10
|
success: (...cases: TestArgs<F>) => () => void;
|
|
6
11
|
fails: (...cases: TestErrors<F>) => () => void;
|
|
7
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Internal function signature for creating a test suite structure.
|
|
15
|
+
*
|
|
16
|
+
* @template `F0` - Function parameters array type.
|
|
17
|
+
* @template `F1` - Function return value type.
|
|
18
|
+
* @template `F2` - Transformed return type, defaults to `F1`.
|
|
19
|
+
*/
|
|
8
20
|
export type _CreateTests_F = <F0 extends any[], F1, F2 = F1>(func: Fn<F0, F1>, transform?: Fn<[Awaited<F1>], F2>, toError?: Fn<F0, string | undefined>, name?: string) => ReturnR<Fn<F0, F2>>;
|
|
9
|
-
export {};
|
|
@@ -30,12 +30,13 @@ const objectify = (options) => {
|
|
|
30
30
|
return [_options, _timeout];
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
* Build a test with a done function
|
|
33
|
+
* Build a test with a done callback function and a timeout.
|
|
34
34
|
*
|
|
35
|
-
* @param invite The description of the test
|
|
36
|
-
* @param fn
|
|
37
|
-
* @param options
|
|
38
|
-
*
|
|
35
|
+
* @param invite - The description of the test.
|
|
36
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
37
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
38
|
+
*
|
|
39
|
+
* @returns A Vitest test execution result.
|
|
39
40
|
*/
|
|
40
41
|
const doneTest = (invite, fn, options = 100) => {
|
|
41
42
|
const [_options, ms] = objectify(options);
|
|
@@ -46,12 +47,13 @@ const doneTest = (invite, fn, options = 100) => {
|
|
|
46
47
|
});
|
|
47
48
|
};
|
|
48
49
|
/**
|
|
49
|
-
* Build a test
|
|
50
|
+
* Build a test expected to fail with a done callback function and a timeout.
|
|
51
|
+
*
|
|
52
|
+
* @param invite - The description of the test.
|
|
53
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
54
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
50
55
|
*
|
|
51
|
-
* @
|
|
52
|
-
* @param fn Where you can test, Don't async this function
|
|
53
|
-
* @param options Options for the test like TestAPI from vitest
|
|
54
|
-
* @returns A vitest test
|
|
56
|
+
* @returns A Vitest test execution result.
|
|
55
57
|
*/
|
|
56
58
|
doneTest.fails = (invite, fn, options = 100) => {
|
|
57
59
|
const [_options, ms] = objectify(options);
|
|
@@ -62,12 +64,13 @@ doneTest.fails = (invite, fn, options = 100) => {
|
|
|
62
64
|
});
|
|
63
65
|
};
|
|
64
66
|
/**
|
|
65
|
-
* Build a concurrent test with a done function
|
|
67
|
+
* Build a concurrent test with a done callback function and a timeout.
|
|
68
|
+
*
|
|
69
|
+
* @param invite - The description of the test.
|
|
70
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
71
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
66
72
|
*
|
|
67
|
-
* @
|
|
68
|
-
* @param fn Where you can test, Don't async this function
|
|
69
|
-
* @param options Options for the test like TestAPI from vitest
|
|
70
|
-
* @returns A vitest test
|
|
73
|
+
* @returns A Vitest test execution result.
|
|
71
74
|
*/
|
|
72
75
|
doneTest.concurrent = (invite, fn, options = 100) => {
|
|
73
76
|
const [_options, ms] = objectify(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"done.cjs","names":["sleep","test"],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\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
|
|
1
|
+
{"version":3,"file":"done.cjs","names":["sleep","test"],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\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 callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\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 expected to fail with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\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 callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\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":";;;;AAMA,MAAM,WAAW,KAAK,MAAM;CAC1B,IAAI,WAAW;CACf,MAAM,aAAc,WAAW;CAE/B,MAAM,WAAW,YAAY;EAC3B,MAAMA,oBAAAA,MAAM,EAAE;EACd,CAAA,GAAA,OAAA,OAAA,CAAO,QAAQ,CAAC,CAAC,KAAK,IAAI;CAC5B;CAEA,OAAO;EAAE;EAAM;CAAS;AAC1B;AAEA,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;AAG3C,MAAM,cAAc,YAAmC;CACrD,IAAI,OAAO,YAAY,UAAU,OAAO,OAAO,OAAO;CACtD,OAAO,OAAO,SAAS,OAAO;AAChC;AAEA,MAAM,aACJ,YAC0B;CAC1B,MAAM,WAAW,WAAW,OAAO;CACnC,MAAM,UAAU,WAAW;CAE3B,IAAI,WAAW,EAAE,QAAQ;CACzB,IAAI,EAAE,OAAO,YAAY,WACvB,WAAW;EAAE,GAAG;EAAS;CAAQ;CAGnC,OAAO,CAAC,UAAU,QAAQ;AAC5B;;;;;;;;;;AAYA,MAAa,YACX,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,QAAA,GAAOC,OAAAA,KAAAA,CAAK,QAAQ,gBAAgB;EAClC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,SACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAOA,OAAAA,KAAK,MAAM,QAAQ,gBAAgB;EACxC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,cACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAOA,OAAAA,KAAK,WAAW,QAAQ,gBAAgB;EAC7C,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type TestOptions } from 'vitest';
|
|
2
2
|
import type { TestDoneFunction } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Build a test with a done function
|
|
4
|
+
* Build a test with a done callback function and a timeout.
|
|
5
5
|
*
|
|
6
|
-
* @param invite The description of the test
|
|
7
|
-
* @param fn
|
|
8
|
-
* @param options
|
|
9
|
-
*
|
|
6
|
+
* @param invite - The description of the test.
|
|
7
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
8
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
9
|
+
*
|
|
10
|
+
* @returns A Vitest test execution result.
|
|
10
11
|
*/
|
|
11
12
|
export declare const doneTest: {
|
|
12
13
|
(invite: string, fn: TestDoneFunction, options?: number | TestOptions): void;
|
|
@@ -29,12 +29,13 @@ const objectify = (options) => {
|
|
|
29
29
|
return [_options, _timeout];
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
* Build a test with a done function
|
|
32
|
+
* Build a test with a done callback function and a timeout.
|
|
33
33
|
*
|
|
34
|
-
* @param invite The description of the test
|
|
35
|
-
* @param fn
|
|
36
|
-
* @param options
|
|
37
|
-
*
|
|
34
|
+
* @param invite - The description of the test.
|
|
35
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
36
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
37
|
+
*
|
|
38
|
+
* @returns A Vitest test execution result.
|
|
38
39
|
*/
|
|
39
40
|
const doneTest = (invite, fn, options = 100) => {
|
|
40
41
|
const [_options, ms] = objectify(options);
|
|
@@ -45,12 +46,13 @@ const doneTest = (invite, fn, options = 100) => {
|
|
|
45
46
|
});
|
|
46
47
|
};
|
|
47
48
|
/**
|
|
48
|
-
* Build a test
|
|
49
|
+
* Build a test expected to fail with a done callback function and a timeout.
|
|
50
|
+
*
|
|
51
|
+
* @param invite - The description of the test.
|
|
52
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
53
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
49
54
|
*
|
|
50
|
-
* @
|
|
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
|
|
55
|
+
* @returns A Vitest test execution result.
|
|
54
56
|
*/
|
|
55
57
|
doneTest.fails = (invite, fn, options = 100) => {
|
|
56
58
|
const [_options, ms] = objectify(options);
|
|
@@ -61,12 +63,13 @@ doneTest.fails = (invite, fn, options = 100) => {
|
|
|
61
63
|
});
|
|
62
64
|
};
|
|
63
65
|
/**
|
|
64
|
-
* Build a concurrent test with a done function
|
|
66
|
+
* Build a concurrent test with a done callback function and a timeout.
|
|
67
|
+
*
|
|
68
|
+
* @param invite - The description of the test.
|
|
69
|
+
* @param fn - Test callback function of type {@linkcode TestDoneFunction}.
|
|
70
|
+
* @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.
|
|
65
71
|
*
|
|
66
|
-
* @
|
|
67
|
-
* @param fn Where you can test, Don't async this function
|
|
68
|
-
* @param options Options for the test like TestAPI from vitest
|
|
69
|
-
* @returns A vitest test
|
|
72
|
+
* @returns A Vitest test execution result.
|
|
70
73
|
*/
|
|
71
74
|
doneTest.concurrent = (invite, fn, options = 100) => {
|
|
72
75
|
const [_options, ms] = objectify(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"done.js","names":[],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\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
|
|
1
|
+
{"version":3,"file":"done.js","names":[],"sources":["../../src/vitest-extended/done.ts"],"sourcesContent":["import { expect, test, type TestOptions } from 'vitest';\n\nimport { sleep } from '#utils/sleep';\n\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 callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\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 expected to fail with a done callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\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 callback function and a timeout.\n *\n * @param invite - The description of the test.\n * @param fn - Test callback function of type {@linkcode TestDoneFunction}.\n * @param options - Timeout in milliseconds or test options of type {@linkcode TestOptions}.\n *\n * @returns A Vitest test execution result.\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":";;;AAMA,MAAM,WAAW,KAAK,MAAM;CAC1B,IAAI,WAAW;CACf,MAAM,aAAc,WAAW;CAE/B,MAAM,WAAW,YAAY;EAC3B,MAAM,MAAM,EAAE;EACd,OAAO,QAAQ,CAAC,CAAC,KAAK,IAAI;CAC5B;CAEA,OAAO;EAAE;EAAM;CAAS;AAC1B;AAEA,MAAM,UAAU,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;AAG3C,MAAM,cAAc,YAAmC;CACrD,IAAI,OAAO,YAAY,UAAU,OAAO,OAAO,OAAO;CACtD,OAAO,OAAO,SAAS,OAAO;AAChC;AAEA,MAAM,aACJ,YAC0B;CAC1B,MAAM,WAAW,WAAW,OAAO;CACnC,MAAM,UAAU,WAAW;CAE3B,IAAI,WAAW,EAAE,QAAQ;CACzB,IAAI,EAAE,OAAO,YAAY,WACvB,WAAW;EAAE,GAAG;EAAS;CAAQ;CAGnC,OAAO,CAAC,UAAU,QAAQ;AAC5B;;;;;;;;;;AAYA,MAAa,YACX,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAO,KAAK,QAAQ,gBAAgB;EAClC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,SACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAO,KAAK,MAAM,QAAQ,gBAAgB;EACxC,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH;;;;;;;;;;AAWA,SAAS,cACP,QACA,IACA,UAAgC,QAC7B;CACH,MAAM,CAAC,UAAU,MAAM,UAAU,OAAO;CAExC,OAAO,KAAK,WAAW,QAAQ,gBAAgB;EAC7C,MAAM,EAAE,MAAM,aAAa,QAAQ,EAAE;EACrC,GAAG,IAAI;EACP,OAAO,SAAS;CAClB,CAAC;AACH"}
|
|
@@ -3,6 +3,9 @@ const require_vitest_extended_toArray = require("../toArray.cjs");
|
|
|
3
3
|
const require_vitest_extended_identity = require("../identity.cjs");
|
|
4
4
|
let vitest = require("vitest");
|
|
5
5
|
//#region src/vitest-extended/each/error.ts
|
|
6
|
+
/**
|
|
7
|
+
* Runs error assertions for asynchronous test cases concurrently.
|
|
8
|
+
*/
|
|
6
9
|
const useErrorAsyncEachCases = (f, transform = require_vitest_extended_identity.identity, toError = () => void 0, ...cases) => {
|
|
7
10
|
vitest.test.concurrent.each(require_vitest_extended_toArray.toArrayVitest.error(cases))("%s", async (_, args, _error) => {
|
|
8
11
|
const actual = async () => {
|
|
@@ -12,6 +15,15 @@ const useErrorAsyncEachCases = (f, transform = require_vitest_extended_identity.
|
|
|
12
15
|
await (0, vitest.expect)(actual).rejects.toThrowError(error);
|
|
13
16
|
});
|
|
14
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Higher-order function returning a test runner for asynchronous error assertions.
|
|
20
|
+
*
|
|
21
|
+
* @param f - Function to test.
|
|
22
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
23
|
+
* @param toError - Optional function computing expected error message from arguments.
|
|
24
|
+
*
|
|
25
|
+
* @returns Function accepting error test cases to execute.
|
|
26
|
+
*/
|
|
15
27
|
const useErrorAsyncEach = (f, transform, toError) => {
|
|
16
28
|
return (...cases) => useErrorAsyncEachCases(f, transform, toError, ...cases);
|
|
17
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.cjs","names":["identity","toArrayVitest"],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\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":"
|
|
1
|
+
{"version":3,"file":"error.cjs","names":["identity","toArrayVitest","expect"],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\n/**\n * Runs error assertions for asynchronous test cases concurrently.\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\n/**\n * Higher-order function returning a test runner for asynchronous error assertions.\n *\n * @param f - Function to test.\n * @param transform - Optional transformer applied to the resolved return value.\n * @param toError - Optional function computing expected error message from arguments.\n *\n * @returns Function accepting error test cases to execute.\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":";;;;;;;;AASA,MAAa,0BACX,GACA,YAAYA,iCAAAA,UACZ,gBAAgB,KAAA,GAChB,GAAG,UACA;CACH,OAAA,KAAK,WAAW,KAAKC,gCAAAA,cAAc,MAAM,KAAK,CAAC,CAAC,CAC9C,MACA,OAAO,GAAG,MAAM,WAAW;EACzB,MAAM,SAAS,YAAY;GAEzB,OAAO,UAAU,MADC,EAAE,GAAG,IAAI,CACP;EACtB;EAEA,MAAM,QADQ,WAAW,KAAA,IACH,QAAQ,GAAG,IAAI,IAAI;EAEzC,OAAA,GAAMC,OAAAA,OAAAA,CAAO,MAAM,CAAC,CAAC,QAAQ,aAAa,KAAK;CACjD,CACF;AACF;;;;;;;;;;AAWA,MAAa,qBACX,GACA,WACA,YACG;CACH,QAAQ,GAAG,UACT,uBAAuB,GAAG,WAAW,SAAS,GAAG,KAAK;AAC1D"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import type { _UseErrorEach_F, UseErrorEach_F } from './error.types';
|
|
2
|
+
/**
|
|
3
|
+
* Runs error assertions for asynchronous test cases concurrently.
|
|
4
|
+
*/
|
|
2
5
|
export declare const useErrorAsyncEachCases: _UseErrorEach_F;
|
|
6
|
+
/**
|
|
7
|
+
* Higher-order function returning a test runner for asynchronous error assertions.
|
|
8
|
+
*
|
|
9
|
+
* @param f - Function to test.
|
|
10
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
11
|
+
* @param toError - Optional function computing expected error message from arguments.
|
|
12
|
+
*
|
|
13
|
+
* @returns Function accepting error test cases to execute.
|
|
14
|
+
*/
|
|
3
15
|
export declare const useErrorAsyncEach: UseErrorEach_F;
|
|
@@ -2,6 +2,9 @@ import { toArrayVitest } from "../toArray.js";
|
|
|
2
2
|
import { identity } from "../identity.js";
|
|
3
3
|
import { expect, test } from "vitest";
|
|
4
4
|
//#region src/vitest-extended/each/error.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runs error assertions for asynchronous test cases concurrently.
|
|
7
|
+
*/
|
|
5
8
|
const useErrorAsyncEachCases = (f, transform = identity, toError = () => void 0, ...cases) => {
|
|
6
9
|
test.concurrent.each(toArrayVitest.error(cases))("%s", async (_, args, _error) => {
|
|
7
10
|
const actual = async () => {
|
|
@@ -11,6 +14,15 @@ const useErrorAsyncEachCases = (f, transform = identity, toError = () => void 0,
|
|
|
11
14
|
await expect(actual).rejects.toThrowError(error);
|
|
12
15
|
});
|
|
13
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Higher-order function returning a test runner for asynchronous error assertions.
|
|
19
|
+
*
|
|
20
|
+
* @param f - Function to test.
|
|
21
|
+
* @param transform - Optional transformer applied to the resolved return value.
|
|
22
|
+
* @param toError - Optional function computing expected error message from arguments.
|
|
23
|
+
*
|
|
24
|
+
* @returns Function accepting error test cases to execute.
|
|
25
|
+
*/
|
|
14
26
|
const useErrorAsyncEach = (f, transform, toError) => {
|
|
15
27
|
return (...cases) => useErrorAsyncEachCases(f, transform, toError, ...cases);
|
|
16
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":[],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\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":"
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../../src/vitest-extended/each/error.ts"],"sourcesContent":["import { expect, test } from 'vitest';\n\nimport { identity } from '../identity';\nimport { toArrayVitest } from '../toArray';\nimport type { _UseErrorEach_F, UseErrorEach_F } from './error.types';\n\n/**\n * Runs error assertions for asynchronous test cases concurrently.\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\n/**\n * Higher-order function returning a test runner for asynchronous error assertions.\n *\n * @param f - Function to test.\n * @param transform - Optional transformer applied to the resolved return value.\n * @param toError - Optional function computing expected error message from arguments.\n *\n * @returns Function accepting error test cases to execute.\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":";;;;;;;AASA,MAAa,0BACX,GACA,YAAY,UACZ,gBAAgB,KAAA,GAChB,GAAG,UACA;CACH,KAAK,WAAW,KAAK,cAAc,MAAM,KAAK,CAAC,CAAC,CAC9C,MACA,OAAO,GAAG,MAAM,WAAW;EACzB,MAAM,SAAS,YAAY;GAEzB,OAAO,UAAU,MADC,EAAE,GAAG,IAAI,CACP;EACtB;EAEA,MAAM,QADQ,WAAW,KAAA,IACH,QAAQ,GAAG,IAAI,IAAI;EAEzC,MAAM,OAAO,MAAM,CAAC,CAAC,QAAQ,aAAa,KAAK;CACjD,CACF;AACF;;;;;;;;;;AAWA,MAAa,qBACX,GACA,WACA,YACG;CACH,QAAQ,GAAG,UACT,uBAAuB,GAAG,WAAW,SAAS,GAAG,KAAK;AAC1D"}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { Fn } from '../../utils/bemedev/globals/types';
|
|
2
2
|
import type { Identity, NextFn, TestErrors } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Function computing an expected error message from function parameters.
|
|
5
|
+
*
|
|
6
|
+
* @template | {@linkcode Fn} `F` - Function type.
|
|
7
|
+
*/
|
|
3
8
|
export type ToError_F<F extends Fn> = (...params: Parameters<F>) => string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Runner function signature for error assertion test cases.
|
|
11
|
+
*
|
|
12
|
+
* @template | {@linkcode Fn} `F` - Target function type.
|
|
13
|
+
* @template | {@linkcode NextFn} `T` - Transformer function type, defaults to {@linkcode Identity}.
|
|
14
|
+
*/
|
|
4
15
|
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;
|
|
16
|
+
/**
|
|
17
|
+
* Higher-order function returning a test runner for error assertion cases.
|
|
18
|
+
*
|
|
19
|
+
* @template | {@linkcode Fn} `F` - Target function type.
|
|
20
|
+
* @template | {@linkcode NextFn} `T` - Transformer function type, defaults to {@linkcode Identity}.
|
|
21
|
+
*/
|
|
5
22
|
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>;
|