@bemedev/dev-utils 1.5.3 → 1.6.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 +56 -4
- package/lib/vitest-extended/createImportTests.cjs +62 -0
- package/lib/vitest-extended/createImportTests.cjs.map +1 -0
- package/lib/vitest-extended/createImportTests.d.ts +33 -0
- package/lib/vitest-extended/createImportTests.js +61 -0
- package/lib/vitest-extended/createImportTests.js.map +1 -0
- package/lib/vitest-extended/createTests.cjs.map +1 -1
- package/lib/vitest-extended/createTests.d.ts +1 -2
- package/lib/vitest-extended/createTests.js.map +1 -1
- package/lib/vitest-extended/index.cjs +2 -0
- package/lib/vitest-extended/index.d.ts +1 -0
- package/lib/vitest-extended/index.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,9 +41,8 @@ npm install @bemedev/dev-utils
|
|
|
41
41
|
yarn add @bemedev/dev-utils
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
**Peer dependencies:** `
|
|
45
|
-
|
|
46
|
-
export.
|
|
44
|
+
**Peer dependencies:** `rolldown ^1.3.2`, `vitest 5.1.0`. `vite-plus ^1.7.0` is an
|
|
45
|
+
optional peer dependency, only required for the `pack` export.
|
|
47
46
|
|
|
48
47
|
<br/>
|
|
49
48
|
|
|
@@ -59,7 +58,11 @@ import { suppressWarnings, hmr } from '@bemedev/dev-utils/plugins';
|
|
|
59
58
|
import { defineConfig } from '@bemedev/dev-utils/rolldown';
|
|
60
59
|
import { clamp, toArray, identity, sleep } from '@bemedev/dev-utils/utils';
|
|
61
60
|
import { exclude } from '@bemedev/dev-utils/vitest-exclude';
|
|
62
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
createTests,
|
|
63
|
+
createFakeWaiter,
|
|
64
|
+
createImportTests,
|
|
65
|
+
} from '@bemedev/dev-utils/vitest-extended';
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
---
|
|
@@ -246,6 +249,55 @@ const { acceptation, success } = createTests.withImplementation(myFn, {
|
|
|
246
249
|
| `transform` | `NextFn<F> \| undefined` | Optional return-value transformer |
|
|
247
250
|
| `toError` | `ToError_F<F> \| undefined` | Optional error deriver |
|
|
248
251
|
|
|
252
|
+
#### Typing wrappers
|
|
253
|
+
|
|
254
|
+
`createTests` and `createTests.withImplementation` return a `ReturnR<F>` object.
|
|
255
|
+
`ReturnR` is exported so you can annotate reusable wrappers explicitly, which keeps
|
|
256
|
+
declaration emit portable (avoids TS2883):
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import type { ReturnR } from '@bemedev/dev-utils/vitest-extended';
|
|
260
|
+
|
|
261
|
+
export const createValibotTests: ReturnR<typeof validate> =
|
|
262
|
+
createTests.withImplementation(validate, {
|
|
263
|
+
name: 'valibot',
|
|
264
|
+
instanciation: async () => realValidate,
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### `createImportTests(packageName)`
|
|
271
|
+
|
|
272
|
+
Creates Vitest suites that check a module's public surface: every symbol listed in
|
|
273
|
+
`SUCCESS` must be exported, and every symbol listed in `FAILS` must be absent. Only
|
|
274
|
+
the existence of the symbols is checked, not their type.
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
import { createImportTests } from '@bemedev/dev-utils/vitest-extended';
|
|
278
|
+
|
|
279
|
+
const createTests = createImportTests('@bemedev/dev-utils');
|
|
280
|
+
|
|
281
|
+
describe(
|
|
282
|
+
...createTests({
|
|
283
|
+
path: 'vitest-extended',
|
|
284
|
+
SUCCESS: ['createTests', 'createImportTests', 'defineProject'],
|
|
285
|
+
FAILS: ['addTarball'],
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**Parameters (`args`)**
|
|
291
|
+
|
|
292
|
+
| Property | Type | Description |
|
|
293
|
+
| --------- | ----------------------- | ------------------------------------------------------------------ |
|
|
294
|
+
| `path` | `string \| undefined` | Sub-path appended to `packageName` (e.g. `'vitest-extended'`) |
|
|
295
|
+
| `SUCCESS` | `string[]` | Export names expected to exist; suite is skipped when empty |
|
|
296
|
+
| `FAILS` | `string[] \| undefined` | Export names expected to be missing; checked with `test.fails` |
|
|
297
|
+
|
|
298
|
+
**Returns** a `readonly [string, () => void]` tuple, ready to spread into
|
|
299
|
+
`describe(...)`.
|
|
300
|
+
|
|
249
301
|
---
|
|
250
302
|
|
|
251
303
|
### `doneTest(invite, fn, options?)`
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_vitest_extended_toStringFlat = require("./toStringFlat.cjs");
|
|
3
|
+
let vitest = require("vitest");
|
|
4
|
+
// src/vitest-extended/createImportTests.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates Vitest test suites verifying that symbols exist in a package module.
|
|
7
|
+
*
|
|
8
|
+
* Only the existence of the symbols is checked, not their type.
|
|
9
|
+
*
|
|
10
|
+
* @param packageName - Name of the package to import from.
|
|
11
|
+
*
|
|
12
|
+
* @returns Function creating a tuple of test description and test runner.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* describe(
|
|
17
|
+
* ...createPackageImportTests('@bemedev/dev-utils')({
|
|
18
|
+
* path: 'vitest-extended',
|
|
19
|
+
* SUCCESS: ['createTests'],
|
|
20
|
+
* FAILS: ['missingExport'],
|
|
21
|
+
* }),
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const createImportTests = (packageName) => {
|
|
26
|
+
return (args) => {
|
|
27
|
+
const path = args.path;
|
|
28
|
+
const target = path ? `${packageName}/${path}` : packageName;
|
|
29
|
+
const invite = `Importing from ${target}`;
|
|
30
|
+
const testFn = async (fn) => {
|
|
31
|
+
const mod = await import(target);
|
|
32
|
+
(0, vitest.expect)(mod[fn]).toBeDefined();
|
|
33
|
+
};
|
|
34
|
+
const fn = () => {
|
|
35
|
+
vitest.describe.skipIf(args.SUCCESS.length < 1)("#01 => Symbols are inside the module", () => {
|
|
36
|
+
const _index = (index) => {
|
|
37
|
+
return require_vitest_extended_toStringFlat.toStringFlat(index + 1, args.SUCCESS.length);
|
|
38
|
+
};
|
|
39
|
+
args.SUCCESS.forEach((fn, index) => {
|
|
40
|
+
(0, vitest.test)(`#${_index(index)} => should succeed with symbol ${fn}`, () => {
|
|
41
|
+
return testFn(fn);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (!args.FAILS || args.FAILS.length < 1) return;
|
|
46
|
+
(0, vitest.describe)("#02 => Symbols are not inside the module", () => {
|
|
47
|
+
const _index = (index) => {
|
|
48
|
+
return require_vitest_extended_toStringFlat.toStringFlat(index + 1, args.FAILS.length);
|
|
49
|
+
};
|
|
50
|
+
args.FAILS.forEach((fn, index) => {
|
|
51
|
+
vitest.test.fails(`#${_index(index)} => should fail with symbol ${fn}`, () => {
|
|
52
|
+
return testFn(fn);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return [invite, fn];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.createImportTests = createImportTests;
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=createImportTests.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImportTests.cjs","names":["expect","describe","toStringFlat","test"],"sources":["../../src/vitest-extended/createImportTests.ts"],"sourcesContent":["import { describe, expect, test } from 'vitest';\n\nimport { toStringFlat } from './toStringFlat';\n\n/**\n * Options defining expected exported and non-exported symbols.\n */\nexport type PackageImportArgs = {\n path?: string;\n FAILS?: string[];\n SUCCESS: string[];\n};\n\n/**\n * Function type creating import test suites for a package.\n */\nexport type CreatePackageImportTest_F = (\n args: PackageImportArgs,\n) => readonly [string, () => void];\n\n/**\n * Creates Vitest test suites verifying that symbols exist in a package module.\n *\n * Only the existence of the symbols is checked, not their type.\n *\n * @param packageName - Name of the package to import from.\n *\n * @returns Function creating a tuple of test description and test runner.\n *\n * @example\n * ```ts\n * describe(\n * ...createPackageImportTests('@bemedev/dev-utils')({\n * path: 'vitest-extended',\n * SUCCESS: ['createTests'],\n * FAILS: ['missingExport'],\n * }),\n * );\n * ```\n */\nexport const createImportTests = (\n packageName: string,\n): CreatePackageImportTest_F => {\n return args => {\n const path = args.path;\n const target = path ? `${packageName}/${path}` : packageName;\n const invite = `Importing from ${target}`;\n\n const testFn = async (fn: string) => {\n const mod = await import(target);\n expect(mod[fn]).toBeDefined();\n };\n\n const fn = () => {\n describe.skipIf(args.SUCCESS.length < 1)(\n '#01 => Symbols are inside the module',\n () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.SUCCESS.length);\n };\n\n args.SUCCESS.forEach((fn, index) => {\n test(`#${_index(index)} => should succeed with symbol ${fn}`, () => {\n return testFn(fn);\n });\n });\n },\n );\n\n if (!args.FAILS || args.FAILS.length < 1) return;\n\n describe('#02 => Symbols are not inside the module', () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.FAILS!.length);\n };\n\n args.FAILS!.forEach((fn, index) => {\n test.fails(`#${_index(index)} => should fail with symbol ${fn}`, () => {\n return testFn(fn);\n });\n });\n });\n };\n\n return [invite, fn] as const;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,qBACX,gBAC8B;CAC9B,QAAO,SAAQ;EACb,MAAM,OAAO,KAAK;EAClB,MAAM,SAAS,OAAO,GAAG,YAAY,GAAG,SAAS;EACjD,MAAM,SAAS,kBAAkB;EAEjC,MAAM,SAAS,OAAO,OAAe;GACnC,MAAM,MAAM,MAAM,OAAO;GACzBA,CAAAA,GAAAA,OAAAA,OAAAA,CAAO,IAAI,GAAG,CAAC,CAAC,YAAY;EAC9B;EAEA,MAAM,WAAW;GACfC,OAAAA,SAAS,OAAO,KAAK,QAAQ,SAAS,CAAC,CAAC,CACtC,8CACM;IACJ,MAAM,UAAU,UAAkB;KAChC,OAAOC,qCAAAA,aAAa,QAAQ,GAAG,KAAK,QAAQ,MAAM;IACpD;IAEA,KAAK,QAAQ,SAAS,IAAI,UAAU;KAClCC,CAAAA,GAAAA,OAAAA,KAAAA,CAAK,IAAI,OAAO,KAAK,EAAE,iCAAiC,YAAY;MAClE,OAAO,OAAO,EAAE;KAClB,CAAC;IACH,CAAC;GACH,CACF;GAEA,IAAI,CAAC,KAAK,SAAS,KAAK,MAAM,SAAS,GAAG;GAE1CF,CAAAA,GAAAA,OAAAA,SAAAA,CAAS,kDAAkD;IACzD,MAAM,UAAU,UAAkB;KAChC,OAAOC,qCAAAA,aAAa,QAAQ,GAAG,KAAK,MAAO,MAAM;IACnD;IAEA,KAAK,MAAO,SAAS,IAAI,UAAU;KACjCC,OAAAA,KAAK,MAAM,IAAI,OAAO,KAAK,EAAE,8BAA8B,YAAY;MACrE,OAAO,OAAO,EAAE;KAClB,CAAC;IACH,CAAC;GACH,CAAC;EACH;EAEA,OAAO,CAAC,QAAQ,EAAE;CACpB;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options defining expected exported and non-exported symbols.
|
|
3
|
+
*/
|
|
4
|
+
export type PackageImportArgs = {
|
|
5
|
+
path?: string;
|
|
6
|
+
FAILS?: string[];
|
|
7
|
+
SUCCESS: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Function type creating import test suites for a package.
|
|
11
|
+
*/
|
|
12
|
+
export type CreatePackageImportTest_F = (args: PackageImportArgs) => readonly [string, () => void];
|
|
13
|
+
/**
|
|
14
|
+
* Creates Vitest test suites verifying that symbols exist in a package module.
|
|
15
|
+
*
|
|
16
|
+
* Only the existence of the symbols is checked, not their type.
|
|
17
|
+
*
|
|
18
|
+
* @param packageName - Name of the package to import from.
|
|
19
|
+
*
|
|
20
|
+
* @returns Function creating a tuple of test description and test runner.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* describe(
|
|
25
|
+
* ...createPackageImportTests('@bemedev/dev-utils')({
|
|
26
|
+
* path: 'vitest-extended',
|
|
27
|
+
* SUCCESS: ['createTests'],
|
|
28
|
+
* FAILS: ['missingExport'],
|
|
29
|
+
* }),
|
|
30
|
+
* );
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const createImportTests: (packageName: string) => CreatePackageImportTest_F;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { toStringFlat } from "./toStringFlat.js";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
// src/vitest-extended/createImportTests.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates Vitest test suites verifying that symbols exist in a package module.
|
|
6
|
+
*
|
|
7
|
+
* Only the existence of the symbols is checked, not their type.
|
|
8
|
+
*
|
|
9
|
+
* @param packageName - Name of the package to import from.
|
|
10
|
+
*
|
|
11
|
+
* @returns Function creating a tuple of test description and test runner.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* describe(
|
|
16
|
+
* ...createPackageImportTests('@bemedev/dev-utils')({
|
|
17
|
+
* path: 'vitest-extended',
|
|
18
|
+
* SUCCESS: ['createTests'],
|
|
19
|
+
* FAILS: ['missingExport'],
|
|
20
|
+
* }),
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const createImportTests = (packageName) => {
|
|
25
|
+
return (args) => {
|
|
26
|
+
const path = args.path;
|
|
27
|
+
const target = path ? `${packageName}/${path}` : packageName;
|
|
28
|
+
const invite = `Importing from ${target}`;
|
|
29
|
+
const testFn = async (fn) => {
|
|
30
|
+
const mod = await import(target);
|
|
31
|
+
expect(mod[fn]).toBeDefined();
|
|
32
|
+
};
|
|
33
|
+
const fn = () => {
|
|
34
|
+
describe.skipIf(args.SUCCESS.length < 1)("#01 => Symbols are inside the module", () => {
|
|
35
|
+
const _index = (index) => {
|
|
36
|
+
return toStringFlat(index + 1, args.SUCCESS.length);
|
|
37
|
+
};
|
|
38
|
+
args.SUCCESS.forEach((fn, index) => {
|
|
39
|
+
test(`#${_index(index)} => should succeed with symbol ${fn}`, () => {
|
|
40
|
+
return testFn(fn);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
if (!args.FAILS || args.FAILS.length < 1) return;
|
|
45
|
+
describe("#02 => Symbols are not inside the module", () => {
|
|
46
|
+
const _index = (index) => {
|
|
47
|
+
return toStringFlat(index + 1, args.FAILS.length);
|
|
48
|
+
};
|
|
49
|
+
args.FAILS.forEach((fn, index) => {
|
|
50
|
+
test.fails(`#${_index(index)} => should fail with symbol ${fn}`, () => {
|
|
51
|
+
return testFn(fn);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return [invite, fn];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export { createImportTests };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=createImportTests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImportTests.js","names":[],"sources":["../../src/vitest-extended/createImportTests.ts"],"sourcesContent":["import { describe, expect, test } from 'vitest';\n\nimport { toStringFlat } from './toStringFlat';\n\n/**\n * Options defining expected exported and non-exported symbols.\n */\nexport type PackageImportArgs = {\n path?: string;\n FAILS?: string[];\n SUCCESS: string[];\n};\n\n/**\n * Function type creating import test suites for a package.\n */\nexport type CreatePackageImportTest_F = (\n args: PackageImportArgs,\n) => readonly [string, () => void];\n\n/**\n * Creates Vitest test suites verifying that symbols exist in a package module.\n *\n * Only the existence of the symbols is checked, not their type.\n *\n * @param packageName - Name of the package to import from.\n *\n * @returns Function creating a tuple of test description and test runner.\n *\n * @example\n * ```ts\n * describe(\n * ...createPackageImportTests('@bemedev/dev-utils')({\n * path: 'vitest-extended',\n * SUCCESS: ['createTests'],\n * FAILS: ['missingExport'],\n * }),\n * );\n * ```\n */\nexport const createImportTests = (\n packageName: string,\n): CreatePackageImportTest_F => {\n return args => {\n const path = args.path;\n const target = path ? `${packageName}/${path}` : packageName;\n const invite = `Importing from ${target}`;\n\n const testFn = async (fn: string) => {\n const mod = await import(target);\n expect(mod[fn]).toBeDefined();\n };\n\n const fn = () => {\n describe.skipIf(args.SUCCESS.length < 1)(\n '#01 => Symbols are inside the module',\n () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.SUCCESS.length);\n };\n\n args.SUCCESS.forEach((fn, index) => {\n test(`#${_index(index)} => should succeed with symbol ${fn}`, () => {\n return testFn(fn);\n });\n });\n },\n );\n\n if (!args.FAILS || args.FAILS.length < 1) return;\n\n describe('#02 => Symbols are not inside the module', () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.FAILS!.length);\n };\n\n args.FAILS!.forEach((fn, index) => {\n test.fails(`#${_index(index)} => should fail with symbol ${fn}`, () => {\n return testFn(fn);\n });\n });\n });\n };\n\n return [invite, fn] as const;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,qBACX,gBAC8B;CAC9B,QAAO,SAAQ;EACb,MAAM,OAAO,KAAK;EAClB,MAAM,SAAS,OAAO,GAAG,YAAY,GAAG,SAAS;EACjD,MAAM,SAAS,kBAAkB;EAEjC,MAAM,SAAS,OAAO,OAAe;GACnC,MAAM,MAAM,MAAM,OAAO;GACzB,OAAO,IAAI,GAAG,CAAC,CAAC,YAAY;EAC9B;EAEA,MAAM,WAAW;GACf,SAAS,OAAO,KAAK,QAAQ,SAAS,CAAC,CAAC,CACtC,8CACM;IACJ,MAAM,UAAU,UAAkB;KAChC,OAAO,aAAa,QAAQ,GAAG,KAAK,QAAQ,MAAM;IACpD;IAEA,KAAK,QAAQ,SAAS,IAAI,UAAU;KAClC,KAAK,IAAI,OAAO,KAAK,EAAE,iCAAiC,YAAY;MAClE,OAAO,OAAO,EAAE;KAClB,CAAC;IACH,CAAC;GACH,CACF;GAEA,IAAI,CAAC,KAAK,SAAS,KAAK,MAAM,SAAS,GAAG;GAE1C,SAAS,kDAAkD;IACzD,MAAM,UAAU,UAAkB;KAChC,OAAO,aAAa,QAAQ,GAAG,KAAK,MAAO,MAAM;IACnD;IAEA,KAAK,MAAO,SAAS,IAAI,UAAU;KACjC,KAAK,MAAM,IAAI,OAAO,KAAK,EAAE,8BAA8B,YAAY;MACrE,OAAO,OAAO,EAAE;KAClB,CAAC;IACH,CAAC;GACH,CAAC;EACH;EAEA,OAAO,CAAC,QAAQ,EAAE;CACpB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTests.cjs","names":["useTFA","useErrorAsyncEach","toStringFlat","useEachAsync","vi","beforeAll"],"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
|
|
1
|
+
{"version":3,"file":"createTests.cjs","names":["useTFA","useErrorAsyncEach","toStringFlat","useEachAsync","vi","beforeAll"],"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 * from './createTests.types';\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 as any, 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 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?: { transform?: Fn<[Awaited<F1>], F2>; toError?: Fn<F0, string | undefined> },\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":";;;;;;;AAUA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;CAClE,OAAO;EACL,mBAAmBA,oCAAAA,OAAO,MAAM,IAAI;EAEpC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;GAErB,aAAa;IAWX,OAViBC,mCAAAA,kBAAkB,MAAM,WAAkB,OAU7C,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,SACG;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,eACFC,CAAAA,GAAAA,OAAAA,UAAAA,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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Fn } from '../utils/bemedev/globals/types';
|
|
2
|
-
|
|
3
|
-
export type { _CreateTests_F };
|
|
2
|
+
export type * from './createTests.types';
|
|
4
3
|
/**
|
|
5
4
|
* Creates structured test suites with acceptation, success, and failure runners.
|
|
6
5
|
*
|
|
@@ -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 { useEachAsync } from './each/pass';\nimport { toStringFlat } from './toStringFlat';\n\nexport type
|
|
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 * from './createTests.types';\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 as any, 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 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?: { transform?: Fn<[Awaited<F1>], F2>; toError?: Fn<F0, string | undefined> },\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":";;;;;;AAUA,MAAM,WAA2B,MAAM,WAAW,SAAS,SAAS;CAClE,OAAO;EACL,mBAAmB,OAAO,MAAM,IAAI;EAEpC,QAAQ,GAAG,UAAU;GACnB,MAAM,SAAS,MAAM;GAErB,aAAa;IAWX,OAViB,kBAAkB,MAAM,WAAkB,OAU7C,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,SACG;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,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_vitest_extended_acceptation = require("./acceptation.cjs");
|
|
3
|
+
const require_vitest_extended_createImportTests = require("./createImportTests.cjs");
|
|
3
4
|
const require_vitest_extended_createTests = require("./createTests.cjs");
|
|
4
5
|
const require_vitest_extended_each_error = require("./each/error.cjs");
|
|
5
6
|
const require_vitest_extended_each_pass = require("./each/pass.cjs");
|
|
@@ -8,6 +9,7 @@ require("./each/index.cjs");
|
|
|
8
9
|
const require_vitest_extended_fakeWaiter = require("./fakeWaiter.cjs");
|
|
9
10
|
const require_vitest_extended_project = require("./project.cjs");
|
|
10
11
|
exports.createFakeWaiter = require_vitest_extended_fakeWaiter.createFakeWaiter;
|
|
12
|
+
exports.createImportTests = require_vitest_extended_createImportTests.createImportTests;
|
|
11
13
|
exports.createTests = require_vitest_extended_createTests.createTests;
|
|
12
14
|
exports.defineProject = require_vitest_extended_project.defineProject;
|
|
13
15
|
exports.doneTest = require_vitest_extended_done.doneTest;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useTFA, useTestFunctionAcceptation } from "./acceptation.js";
|
|
2
|
+
import { createImportTests } from "./createImportTests.js";
|
|
2
3
|
import { createTests } from "./createTests.js";
|
|
3
4
|
import { useErrorAsyncEach, useErrorAsyncEachCases } from "./each/error.js";
|
|
4
5
|
import { useEach, useEachAsync } from "./each/pass.js";
|
|
@@ -6,4 +7,4 @@ import { doneTest } from "./done.js";
|
|
|
6
7
|
import "./each/index.js";
|
|
7
8
|
import { createFakeWaiter } from "./fakeWaiter.js";
|
|
8
9
|
import { defineProject } from "./project.js";
|
|
9
|
-
export { createFakeWaiter, createTests, defineProject, doneTest, useEach, useEachAsync, useErrorAsyncEach, useErrorAsyncEachCases, useTFA, useTestFunctionAcceptation };
|
|
10
|
+
export { createFakeWaiter, createImportTests, createTests, defineProject, doneTest, useEach, useEachAsync, useErrorAsyncEach, useErrorAsyncEachCases, useTFA, useTestFunctionAcceptation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemedev/dev-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "A collection of utilities for Node.js development, including build tools, testing utilities, and configuration management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"build-tools",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"vitest": "5.1.0"
|
|
115
115
|
},
|
|
116
116
|
"optionalDependencies": {
|
|
117
|
-
"vite-plus": "^1.
|
|
117
|
+
"vite-plus": "^1.7.0"
|
|
118
118
|
},
|
|
119
119
|
"size-limit": [
|
|
120
120
|
{
|