@bemedev/dev-utils 1.5.4 → 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 CHANGED
@@ -41,9 +41,8 @@ npm install @bemedev/dev-utils
41
41
  yarn add @bemedev/dev-utils
42
42
  ```
43
43
 
44
- **Peer dependencies:** `typescript ^5 || ^6`, `rolldown ^1.3.0`, `vitest 5.1.0`.
45
- `vite-plus ^1.5.0` is an optional peer dependency, only required for the `pack`
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 { createTests, createFakeWaiter } from '@bemedev/dev-utils/vitest-extended';
61
+ import {
62
+ createTests,
63
+ createFakeWaiter,
64
+ createImportTests,
65
+ } from '@bemedev/dev-utils/vitest-extended';
63
66
  ```
64
67
 
65
68
  ---
@@ -264,6 +267,39 @@ export const createValibotTests: ReturnR<typeof validate> =
264
267
 
265
268
  ---
266
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
+
301
+ ---
302
+
267
303
  ### `doneTest(invite, fn, options?)`
268
304
 
269
305
  Wraps a callback-style (done-based) test into a Vitest `test`. The test passes only
@@ -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,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
  export * from './acceptation';
2
+ export * from './createImportTests';
2
3
  export * from './createTests';
3
4
  export * from './done';
4
5
  export * from './each';
@@ -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.5.4",
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",