@bemedev/dev-utils 0.6.3 → 0.6.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTests.cjs","names":["useTFA","useErrorAsyncEach","toStringFlat","useEachAsync","vi"],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"createTests.cjs","names":["useTFA","useErrorAsyncEach","toStringFlat","useEachAsync","vi"],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import { beforeAll, vi } from 'vitest';\nimport { useTFA } from './acceptation';\nimport type { Fn } from './bemedev/globals/types';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport {\n useEachAsync,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n type useEach,\n} 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 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 = <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\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":";;;;;;;;AAcA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;AAClE,QAAO;EACL,mBAAmBA,oCAAAA,OAAO,MAAM,KAAK;EAErC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;AAErB,gBAAa;AAeX,WAdiBC,mCAAAA,kBACf,MACA,WACA,QAWa,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,SAAS,UAAU;AAGjD,YAAO;MADO,QAAA,IADKC,qCAAAA,aAAa,QAAQ,GAAG,OAAO,CAAC,MAAM;MACnC;MAAY;MACxB;MAIW,CAAC;;;EAI9B,UAAU,GAAG,UAAU;GACrB,MAAM,SAAS,MAAM;AACrB,gBAAa;AAWX,WAViBC,kCAAAA,aAAa,MAAa,UAU5B,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,UAAU,QAAQ,UAAU;AAG1D,YAAO;MADO,QAAA,IADKD,qCAAAA,aAAa,QAAQ,GAAG,OAAO,CAAC,MAAM;MACnC;MAAY;MAAU;MAClC;MAIW,CAAC;;;EAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCH,MAAa,eACX,MACA,SAIG;CACH,MAAM,EAAE,WAAW,YAAY,QAAQ,EAAE;AACzC,QAAO,QAAQ,MAAM,WAAW,QAAQ;;AAG1C,YAAY,sBACV,GACA,EACE,eACA,MACA,WACA,cAOC;CACH,MAAM,OAAOE,OAAAA,GAAG,GAAG,EAAE;AAErB,KAAI,cACF,EAAA,GAAA,OAAA,WAAU,YAAY;EACpB,MAAM,OAAO,MAAM,eAAe;AAClC,OAAK,mBAAmB,KAAK;GAC7B;AAGJ,QAAO,QAAQ,MAAM,WAAW,SAAS,KAAK;;AAGhD,YAAY,wBAAwB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Fn } from './bemedev/globals/types';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { _CreateTests_F } from './createTests.types';
|
|
3
|
+
export type { _CreateTests_F };
|
|
4
4
|
/**
|
|
5
5
|
* Creates tests for function in a better way
|
|
6
6
|
* NB : We use strict-equality, {@link useEach|see}
|
|
@@ -36,23 +36,23 @@ import type { Identity, NextFn } from './types';
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
export declare const createTests: {
|
|
39
|
-
<
|
|
40
|
-
transform?:
|
|
41
|
-
toError?:
|
|
39
|
+
<F0 extends any[], F1, F2 = F1>(func: Fn<F0, F1>, args?: {
|
|
40
|
+
transform?: Fn<[Awaited<F1>], F2>;
|
|
41
|
+
toError?: Fn<F0, string | undefined>;
|
|
42
42
|
}): {
|
|
43
43
|
acceptation: () => void;
|
|
44
|
-
success: (...cases: import("./types").TestArgs<
|
|
45
|
-
fails: (...cases: import("./types").TestErrors<
|
|
44
|
+
success: (...cases: import("./types").TestArgs<Fn<F0, F2>>) => () => void;
|
|
45
|
+
fails: (...cases: import("./types").TestErrors<Fn<F0, F2>>) => () => void;
|
|
46
46
|
};
|
|
47
|
-
withImplementation<
|
|
48
|
-
instanciation: () => Promise<
|
|
47
|
+
withImplementation<F0 extends any[], F1, F2 = F1>(f: Fn<NoInfer<F0>, NoInfer<F1>>, { instanciation, name, transform, toError, }: {
|
|
48
|
+
instanciation: () => Promise<Fn<F0, F1>> | Fn<F0, F1>;
|
|
49
49
|
name: string;
|
|
50
|
-
transform?:
|
|
51
|
-
toError?:
|
|
50
|
+
transform?: Fn<[Awaited<F1>], F2>;
|
|
51
|
+
toError?: Fn<F0, string | undefined>;
|
|
52
52
|
}): {
|
|
53
53
|
acceptation: () => void;
|
|
54
|
-
success: (...cases: import("./types").TestArgs<
|
|
55
|
-
fails: (...cases: import("./types").TestErrors<
|
|
54
|
+
success: (...cases: import("./types").TestArgs<Fn<F0, F2>>) => () => void;
|
|
55
|
+
fails: (...cases: import("./types").TestErrors<Fn<F0, F2>>) => () => void;
|
|
56
56
|
};
|
|
57
57
|
withoutImplementation: /*elided*/ any;
|
|
58
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTests.js","names":[],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"createTests.js","names":[],"sources":["../../src/vitest-extended/createTests.ts"],"sourcesContent":["import { beforeAll, vi } from 'vitest';\nimport { useTFA } from './acceptation';\nimport type { Fn } from './bemedev/globals/types';\nimport type { _CreateTests_F } from './createTests.types';\nimport { useErrorAsyncEach } from './each/error';\nimport {\n useEachAsync,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n type useEach,\n} 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 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 = <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\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":";;;;;;AAcA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;AAClE,QAAO;EACL,mBAAmB,OAAO,MAAM,KAAK;EAErC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;AAErB,gBAAa;AAeX,WAdiB,kBACf,MACA,WACA,QAWa,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,SAAS,UAAU;AAGjD,YAAO;MADO,QAAA,IADK,aAAa,QAAQ,GAAG,OAAO,CAAC,MAAM;MACnC;MAAY;MACxB;MAIW,CAAC;;;EAI9B,UAAU,GAAG,UAAU;GACrB,MAAM,SAAS,MAAM;AACrB,gBAAa;AAWX,WAViB,aAAa,MAAa,UAU5B,CAAC,GARI,MAAM,KACvB,EAAE,QAAQ,SAAS,YAAY,UAAU,QAAQ,UAAU;AAG1D,YAAO;MADO,QAAA,IADK,aAAa,QAAQ,GAAG,OAAO,CAAC,MAAM;MACnC;MAAY;MAAU;MAClC;MAIW,CAAC;;;EAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCH,MAAa,eACX,MACA,SAIG;CACH,MAAM,EAAE,WAAW,YAAY,QAAQ,EAAE;AACzC,QAAO,QAAQ,MAAM,WAAW,QAAQ;;AAG1C,YAAY,sBACV,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"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Fn } from './bemedev/globals/types';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ChainedFn, Identity, NextFn, TestArgs, TestErrors } from './types';
|
|
2
|
+
import type { TestArgs, TestErrors } from './types';
|
|
4
3
|
type ReturnR<F extends Fn> = {
|
|
5
4
|
acceptation: () => void;
|
|
6
5
|
success: (...cases: TestArgs<F>) => () => void;
|
|
7
6
|
fails: (...cases: TestErrors<F>) => () => void;
|
|
8
7
|
};
|
|
9
|
-
export type _CreateTests_F = <
|
|
8
|
+
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>>;
|
|
10
9
|
export {};
|
package/package.json
CHANGED