@bemedev/dev-utils 0.8.0 → 0.8.1

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.
Files changed (142) hide show
  1. package/lib/build-tests/addTarball.cjs.map +1 -1
  2. package/lib/build-tests/addTarball.js.map +1 -1
  3. package/lib/build-tests/buildPackageJson.cjs.map +1 -1
  4. package/lib/build-tests/buildPackageJson.js.map +1 -1
  5. package/lib/build-tests/cleanup.cjs.map +1 -1
  6. package/lib/build-tests/cleanup.js.map +1 -1
  7. package/lib/build-tests/cli/cli.cjs +1 -0
  8. package/lib/build-tests/cli/cli.cjs.map +1 -1
  9. package/lib/build-tests/cli/cli.js.map +1 -1
  10. package/lib/build-tests/cli/index.cjs +1 -0
  11. package/lib/build-tests/cli/index.cjs.map +1 -1
  12. package/lib/build-tests/cli/index.js.map +1 -1
  13. package/lib/build-tests/cli/post.cjs +1 -0
  14. package/lib/build-tests/cli/post.cjs.map +1 -1
  15. package/lib/build-tests/cli/post.js.map +1 -1
  16. package/lib/build-tests/cli/pre.cjs +1 -0
  17. package/lib/build-tests/cli/pre.cjs.map +1 -1
  18. package/lib/build-tests/cli/pre.js.map +1 -1
  19. package/lib/build-tests/cli/test.cjs.map +1 -1
  20. package/lib/build-tests/cli/test.js.map +1 -1
  21. package/lib/build-tests/constants.cjs.map +1 -1
  22. package/lib/build-tests/constants.js.map +1 -1
  23. package/lib/build-tests/getRelativePath.cjs +1 -0
  24. package/lib/build-tests/getRelativePath.cjs.map +1 -1
  25. package/lib/build-tests/getRelativePath.js.map +1 -1
  26. package/lib/build-tests/getTypescriptOutdir.cjs +10 -2
  27. package/lib/build-tests/getTypescriptOutdir.cjs.map +1 -1
  28. package/lib/build-tests/getTypescriptOutdir.js +9 -2
  29. package/lib/build-tests/getTypescriptOutdir.js.map +1 -1
  30. package/lib/build-tests/import.cjs.map +1 -1
  31. package/lib/build-tests/import.js.map +1 -1
  32. package/lib/build-tests/imports/create.cjs +1 -0
  33. package/lib/build-tests/imports/create.cjs.map +1 -1
  34. package/lib/build-tests/imports/create.js.map +1 -1
  35. package/lib/build-tests/imports/helper.cjs +1 -0
  36. package/lib/build-tests/imports/helper.cjs.map +1 -1
  37. package/lib/build-tests/imports/helper.js.map +1 -1
  38. package/lib/build-tests/pack.cjs.map +1 -1
  39. package/lib/build-tests/pack.js.map +1 -1
  40. package/lib/rolldown-config/config.cjs +4 -3
  41. package/lib/rolldown-config/config.cjs.map +1 -1
  42. package/lib/rolldown-config/config.js +3 -3
  43. package/lib/rolldown-config/config.js.map +1 -1
  44. package/lib/rolldown-config/constants.cjs.map +1 -1
  45. package/lib/rolldown-config/constants.js.map +1 -1
  46. package/lib/rolldown-config/helpers.cjs +1 -0
  47. package/lib/rolldown-config/helpers.cjs.map +1 -1
  48. package/lib/rolldown-config/helpers.js.map +1 -1
  49. package/lib/rolldown-config/index.d.ts +1 -0
  50. package/lib/rolldown-config/input.cjs +1 -0
  51. package/lib/rolldown-config/input.cjs.map +1 -1
  52. package/lib/rolldown-config/input.js.map +1 -1
  53. package/lib/rolldown-config/output.cjs +2 -1
  54. package/lib/rolldown-config/output.cjs.map +1 -1
  55. package/lib/rolldown-config/output.d.ts +1 -1
  56. package/lib/rolldown-config/output.js +2 -1
  57. package/lib/rolldown-config/output.js.map +1 -1
  58. package/lib/rolldown-config/plugins/alias.cjs.map +1 -1
  59. package/lib/rolldown-config/plugins/alias.js.map +1 -1
  60. package/lib/rolldown-config/plugins/circulars.cjs +1 -0
  61. package/lib/rolldown-config/plugins/circulars.cjs.map +1 -1
  62. package/lib/rolldown-config/plugins/circulars.js.map +1 -1
  63. package/lib/rolldown-config/plugins/clean.cjs +10 -3
  64. package/lib/rolldown-config/plugins/clean.cjs.map +1 -1
  65. package/lib/rolldown-config/plugins/clean.d.ts +1 -1
  66. package/lib/rolldown-config/plugins/clean.js +8 -3
  67. package/lib/rolldown-config/plugins/clean.js.map +1 -1
  68. package/lib/rolldown-config/plugins/externals.cjs +1 -0
  69. package/lib/rolldown-config/plugins/externals.cjs.map +1 -1
  70. package/lib/rolldown-config/plugins/externals.js.map +1 -1
  71. package/lib/rolldown-config/plugins/index.cjs.map +1 -1
  72. package/lib/rolldown-config/plugins/index.d.ts +2 -2
  73. package/lib/rolldown-config/plugins/index.js.map +1 -1
  74. package/lib/rolldown-config/plugins/tsPaths.cjs.map +1 -1
  75. package/lib/rolldown-config/plugins/tsPaths.js.map +1 -1
  76. package/lib/rolldown-config/plugins/typescript.cjs +3 -1
  77. package/lib/rolldown-config/plugins/typescript.cjs.map +1 -1
  78. package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -1
  79. package/lib/rolldown-config/plugins/typescript.config.js.map +1 -1
  80. package/lib/rolldown-config/plugins/typescript.d.ts +1 -1
  81. package/lib/rolldown-config/plugins/typescript.js +3 -1
  82. package/lib/rolldown-config/plugins/typescript.js.map +1 -1
  83. package/lib/rolldown-config/utils.cjs.map +1 -1
  84. package/lib/rolldown-config/utils.js.map +1 -1
  85. package/lib/utils/sleep.cjs.map +1 -1
  86. package/lib/utils/sleep.js.map +1 -1
  87. package/lib/vitest-exclude/vitest.cjs +39 -14
  88. package/lib/vitest-exclude/vitest.cjs.map +1 -1
  89. package/lib/vitest-exclude/vitest.d.ts +4 -3
  90. package/lib/vitest-exclude/vitest.js +39 -14
  91. package/lib/vitest-exclude/vitest.js.map +1 -1
  92. package/lib/vitest-exclude/vitest.utils.cjs +9 -8
  93. package/lib/vitest-exclude/vitest.utils.cjs.map +1 -1
  94. package/lib/vitest-exclude/vitest.utils.d.ts +4 -4
  95. package/lib/vitest-exclude/vitest.utils.js +8 -8
  96. package/lib/vitest-exclude/vitest.utils.js.map +1 -1
  97. package/lib/vitest-extended/acceptation.cjs +1 -0
  98. package/lib/vitest-extended/acceptation.cjs.map +1 -1
  99. package/lib/vitest-extended/acceptation.js.map +1 -1
  100. package/lib/vitest-extended/createTests.cjs +1 -0
  101. package/lib/vitest-extended/createTests.cjs.map +1 -1
  102. package/lib/vitest-extended/createTests.js.map +1 -1
  103. package/lib/vitest-extended/done.cjs +1 -0
  104. package/lib/vitest-extended/done.cjs.map +1 -1
  105. package/lib/vitest-extended/done.js.map +1 -1
  106. package/lib/vitest-extended/each/error.cjs +1 -0
  107. package/lib/vitest-extended/each/error.cjs.map +1 -1
  108. package/lib/vitest-extended/each/error.js.map +1 -1
  109. package/lib/vitest-extended/each/pass.cjs +1 -0
  110. package/lib/vitest-extended/each/pass.cjs.map +1 -1
  111. package/lib/vitest-extended/each/pass.js.map +1 -1
  112. package/lib/vitest-extended/fakeWaiter.cjs.map +1 -1
  113. package/lib/vitest-extended/fakeWaiter.js.map +1 -1
  114. package/lib/vitest-extended/fixtures/coverage.cjs.map +1 -1
  115. package/lib/vitest-extended/fixtures/coverage.js.map +1 -1
  116. package/lib/vitest-extended/fixtures/partialCall.cjs.map +1 -1
  117. package/lib/vitest-extended/fixtures/partialCall.js.map +1 -1
  118. package/lib/vitest-extended/fixtures/toUpper.cjs.map +1 -1
  119. package/lib/vitest-extended/fixtures/toUpper.js.map +1 -1
  120. package/lib/vitest-extended/fixtures/zod.cjs.map +1 -1
  121. package/lib/vitest-extended/fixtures/zod.js.map +1 -1
  122. package/lib/vitest-extended/identity.cjs +1 -0
  123. package/lib/vitest-extended/identity.cjs.map +1 -1
  124. package/lib/vitest-extended/identity.js.map +1 -1
  125. package/lib/vitest-extended/isDefined.cjs.map +1 -1
  126. package/lib/vitest-extended/isDefined.js.map +1 -1
  127. package/lib/vitest-extended/isFunction.cjs.map +1 -1
  128. package/lib/vitest-extended/isFunction.js.map +1 -1
  129. package/lib/vitest-extended/toArray.cjs.map +1 -1
  130. package/lib/vitest-extended/toArray.js.map +1 -1
  131. package/lib/vitest-extended/toStringFlat.cjs.map +1 -1
  132. package/lib/vitest-extended/toStringFlat.js.map +1 -1
  133. package/package.json +17 -59
  134. package/README.md +0 -700
  135. package/lib/vitest-alias/index.cjs +0 -4
  136. package/lib/vitest-alias/index.d.ts +0 -1
  137. package/lib/vitest-alias/index.js +0 -2
  138. package/lib/vitest-alias/vitest.cjs +0 -86
  139. package/lib/vitest-alias/vitest.cjs.map +0 -1
  140. package/lib/vitest-alias/vitest.d.ts +0 -33
  141. package/lib/vitest-alias/vitest.js +0 -82
  142. package/lib/vitest-alias/vitest.js.map +0 -1
package/README.md DELETED
@@ -1,700 +0,0 @@
1
- # @bemedev/dev-utils
2
-
3
- A collection of utilities for Node.js development, including build tools,
4
- testing utilities, and configuration management.
5
-
6
- ## Modules
7
-
8
- | Module | Description |
9
- | ----------------------------------- | --------------------------------------------- |
10
- | [`vitestAlias`](#vitestalias) | Vitest plugin to inject tsconfig path aliases |
11
- | [`vitestExclude`](#vitestexclude) | Vitest plugin for glob-based include/exclude |
12
- | [`vitestExtended`](#vitestextended) | Extended test helpers for Vitest |
13
- | [`rolldownConfig`](#rolldownconfig) | Rolldown bundler configuration factory |
14
- | [`buildTests`](#buildtests) | CLI tooling to build and test packages |
15
-
16
- <br/>
17
-
18
- ## Installation
19
-
20
- ```bash
21
- pnpm add @bemedev/dev-utils
22
- # or
23
- npm install @bemedev/dev-utils
24
- # or
25
- yarn add @bemedev/dev-utils
26
- ```
27
-
28
- **Peer dependencies:** `typescript ^5 || ^6`
29
-
30
- <br/>
31
-
32
- ## Usage
33
-
34
- Each module is available as a dedicated sub-path export — there is no root
35
- barrel export:
36
-
37
- ```typescript
38
- import { createAlias, aliasTs } from '@bemedev/dev-utils/vitest-alias';
39
- import { exclude } from '@bemedev/dev-utils/vitest-exclude';
40
- import {
41
- createTests,
42
- createFakeWaiter,
43
- } from '@bemedev/dev-utils/vitest-extended';
44
- import { defineConfig } from '@bemedev/dev-utils/rolldown';
45
- import { addTarball, cleanup } from '@bemedev/dev-utils/build-tests';
46
- ```
47
-
48
- ---
49
-
50
- ## `vitestAlias`
51
-
52
- Vitest plugin that reads your `tsconfig.json` path mappings and injects
53
- them as Vitest/Vite aliases — no manual duplication needed.
54
-
55
- ### `createAlias(tsconfig?)`
56
-
57
- Converts `compilerOptions.paths` (and optional `baseUrl`) from a tsconfig
58
- object or a tsconfig file path (loads `tsconfig.json` by default if
59
- omitted) into a Vite-compatible alias map.
60
-
61
- ```typescript
62
- import { createAlias } from '@bemedev/dev-utils/vitest-alias';
63
-
64
- // vitest.config.ts
65
- export default defineConfig({
66
- test: {
67
- // Automatically loads tsconfig.json from project root
68
- alias: createAlias(),
69
- },
70
- });
71
- ```
72
-
73
- **Parameters**
74
-
75
- | Name | Type | Description |
76
- | ---------- | ------------------------------- | ------------------------------------------------------------------------------------ |
77
- | `tsconfig` | `string \| TsConf \| undefined` | Parsed tsconfig JSON object or path to a tsconfig file (defaults to `tsconfig.json`) |
78
-
79
- **Returns** `Record<string, string>` — alias map ready for `test.alias`.
80
-
81
- ---
82
-
83
- ### `aliasTs(tsconfig?)`
84
-
85
- A Vitest/Vite plugin that automatically calls `createAlias` and merges the
86
- result into `test.alias`.
87
-
88
- > **Note:** Make sure `"resolveJsonModule": true` is set in your
89
- > `compilerOptions` if passing a parsed JSON object directly, or pass a
90
- > file path (or nothing) to load it via TypeScript's file reader.
91
-
92
- ```typescript
93
- import { aliasTs } from '@bemedev/dev-utils/vitest-alias';
94
-
95
- // vitest.config.ts
96
- export default defineConfig({
97
- plugins: [
98
- // Automatically loads tsconfig.json from project root
99
- aliasTs(),
100
- ],
101
- });
102
- ```
103
-
104
- **Parameters**
105
-
106
- | Name | Type | Description |
107
- | ---------- | ------------------------------- | ------------------------------------------------------------------------------------ |
108
- | `tsconfig` | `string \| TsConf \| undefined` | Parsed tsconfig JSON object or path to a tsconfig file (defaults to `tsconfig.json`) |
109
-
110
- **Returns** a Vitest `Plugin`.
111
-
112
- ---
113
-
114
- ## `vitestExclude`
115
-
116
- Vitest plugin that uses glob patterns to dynamically build `test.include`
117
- and `coverage.include` lists — no need to maintain `test.exclude` manually.
118
-
119
- ### `exclude(args?)`
120
-
121
- Uses default patterns (`src/**/*.ts` for coverage,
122
- `src/**/*.{test,spec}.{ts,js,tsx,jsx}` for tests) and applies optional
123
- ignore lists.
124
-
125
- ```typescript
126
- import { exclude } from '@bemedev/dev-utils/vitest-exclude';
127
-
128
- // vitest.config.ts
129
- export default defineConfig({
130
- plugins: [
131
- exclude({
132
- ignoreTestFiles: ['src/fixtures/**'],
133
- ignoreCoverageFiles: ['src/**/*.types.ts'],
134
- }),
135
- ],
136
- });
137
- ```
138
-
139
- **Parameters (`args`)**
140
-
141
- | Property | Type | Description |
142
- | --------------------- | ----------------------- | -------------------------------------------- |
143
- | `ignoreTestFiles` | `string[] \| undefined` | Glob patterns to exclude from test discovery |
144
- | `ignoreCoverageFiles` | `string[] \| undefined` | Glob patterns to exclude from coverage |
145
-
146
- **Returns** a Vitest `Plugin`.
147
-
148
- ---
149
-
150
- ### `exclude.withPattern(patterns, args)`
151
-
152
- Same as `exclude`, but lets you provide custom glob patterns instead of the
153
- defaults.
154
-
155
- ```typescript
156
- exclude.withPattern(
157
- {
158
- patternTest: 'tests/**/*.test.ts',
159
- patternCov: 'src/**/*.ts',
160
- },
161
- { ignoreTestFiles: ['tests/fixtures/**'] },
162
- );
163
- ```
164
-
165
- **Parameters**
166
-
167
- | Name | Type | Description |
168
- | ------------- | -------------------- | ----------------------------------- |
169
- | `patternTest` | `string \| string[]` | Glob(s) for test file discovery |
170
- | `patternCov` | `string \| string[]` | Glob(s) for coverage file discovery |
171
- | `args` | same as `exclude` | Optional ignore lists |
172
-
173
- **Returns** a Vitest `Plugin`.
174
-
175
- ---
176
-
177
- ### `create(args?)`
178
-
179
- Plain async function (not a plugin) that resolves glob patterns and returns
180
- `{ files, coverage }` string arrays using the default patterns.
181
-
182
- ```typescript
183
- import { create } from '@bemedev/dev-utils/vitest-exclude';
184
-
185
- const { files, coverage } = await create({
186
- ignoreTestFiles: ['src/fixtures/**'],
187
- ignoreCoverageFiles: ['src/**/*.types.ts'],
188
- });
189
- ```
190
-
191
- **Parameters (`args`)**
192
-
193
- | Property | Type | Description |
194
- | --------------------- | ----------------------- | -------------------------------------------- |
195
- | `ignoreTestFiles` | `string[] \| undefined` | Glob patterns to exclude from test discovery |
196
- | `ignoreCoverageFiles` | `string[] \| undefined` | Glob patterns to exclude from coverage |
197
-
198
- **Returns** `Promise<{ files: string[]; coverage: string[] }>`.
199
-
200
- ---
201
-
202
- ### `create.withPattern(patterns, args)`
203
-
204
- Same as `create`, but accepts custom glob patterns for both test and
205
- coverage discovery.
206
-
207
- ```typescript
208
- import { create } from '@bemedev/dev-utils/vitest-exclude';
209
-
210
- const { files, coverage } = await create.withPattern(
211
- {
212
- patternTest: 'tests/**/*.test.ts',
213
- patternCov: 'src/**/*.ts',
214
- },
215
- { ignoreTestFiles: ['tests/fixtures/**'] },
216
- );
217
- ```
218
-
219
- **Parameters**
220
-
221
- | Name | Type | Description |
222
- | ------------- | -------------------- | ----------------------------------- |
223
- | `patternTest` | `string \| string[]` | Glob(s) for test file discovery |
224
- | `patternCov` | `string \| string[]` | Glob(s) for coverage file discovery |
225
- | `args` | same as `create` | Optional ignore lists |
226
-
227
- **Returns** `Promise<{ files: string[]; coverage: string[] }>`.
228
-
229
- ---
230
-
231
- ## `vitestExtended`
232
-
233
- Extended helpers for writing structured, type-safe Vitest tests.
234
-
235
- ### `createTests(func, args?)`
236
-
237
- Creates a reusable test suite for a function with `acceptation`, `success`,
238
- and `fails` runners.
239
-
240
- ```typescript
241
- import { createTests } from '@bemedev/dev-utils/vitest-extended';
242
-
243
- // add.ts
244
- export const add = (a: number, b: number) => a + b;
245
-
246
- // add.test.ts
247
- const { acceptation, success, fails } = createTests(add);
248
-
249
- describe('add', () => {
250
- describe('acceptation', acceptation());
251
-
252
- describe(
253
- 'success',
254
- success(
255
- { invite: '1 + 2 = 3', parameters: [1, 2], expected: 3 },
256
- { invite: '0 + 0 = 0', parameters: [0, 0], expected: 0 },
257
- ),
258
- );
259
- });
260
- ```
261
-
262
- > **Note:** When the first parameter is an array, wrap it in another array:
263
- > `parameters: [[1, 2, 3]]`.
264
-
265
- **Parameters**
266
-
267
- | Name | Type | Description |
268
- | ---------------- | --------------------------- | --------------------------------------------------------------- |
269
- | `func` | `Fn` | The function under test |
270
- | `args.transform` | `NextFn<F> \| undefined` | Optional transformer applied to the return value |
271
- | `args.toError` | `ToError_F<F> \| undefined` | Optional function that derives an expected error from the input |
272
-
273
- **Returns** `{ acceptation, success, fails }`:
274
-
275
- | Method | Signature | Description |
276
- | ------------------- | ------------ | ------------------------------------------------------ |
277
- | `acceptation()` | `() => void` | Runs two checks: function is defined and is a function |
278
- | `success(...cases)` | `() => void` | Runs `test.concurrent.each` for passing cases |
279
- | `fails(...cases)` | `() => void` | Runs `test.concurrent.each` and expects thrown errors |
280
-
281
- ---
282
-
283
- ### `createTests.withImplementation(f, opts)`
284
-
285
- Same as `createTests` but replaces the implementation with a `vi.fn()` mock
286
- before the test suite runs.
287
-
288
- ```typescript
289
- const { acceptation, success } = createTests.withImplementation(myFn, {
290
- name: 'myFn',
291
- instanciation: async () => realImpl,
292
- });
293
- ```
294
-
295
- **`opts` properties**
296
-
297
- | Property | Type | Description |
298
- | --------------- | --------------------------- | -------------------------------------------------------- |
299
- | `instanciation` | `() => Promise<F> \| F` | Factory called in `beforeAll` to set mock implementation |
300
- | `name` | `string` | Display name used in acceptation tests |
301
- | `transform` | `NextFn<F> \| undefined` | Optional return-value transformer |
302
- | `toError` | `ToError_F<F> \| undefined` | Optional error deriver |
303
-
304
- ---
305
-
306
- ### `doneTest(invite, fn, options?)`
307
-
308
- Wraps a callback-style (done-based) test into a Vitest `test`. The test
309
- passes only when `done()` is called within the timeout. Supports both sync
310
- and async test functions.
311
-
312
- ```typescript
313
- import { doneTest } from '@bemedev/dev-utils/vitest-extended';
314
-
315
- // Async example with await
316
- doneTest('async callback', async done => {
317
- await service.start();
318
- await service.send('event');
319
- });
320
-
321
- // Sync example
322
- doneTest('fires callback', done => {
323
- emitter.once('event', done);
324
- emitter.emit('event');
325
- });
326
- ```
327
-
328
- **Parameters**
329
-
330
- | Name | Type | Default | Description |
331
- | --------- | --------------------------------------------- | ------- | ------------------------------------------ |
332
- | `invite` | `string` | — | Test description |
333
- | `fn` | `(done: () => void) => void \| Promise<void>` | — | Test body (sync or async, receives `done`) |
334
- | `options` | `number \| TestOptions` | `100` | Timeout in ms or Vitest `TestOptions` |
335
-
336
- **Variants**
337
-
338
- | Variant | Description |
339
- | ------------------------------------------- | -------------------------- |
340
- | `doneTest.fails(invite, fn, options?)` | Expects the test to fail |
341
- | `doneTest.concurrent(invite, fn, options?)` | Runs the test concurrently |
342
-
343
- ---
344
-
345
- ### `createFakeWaiter(vi)`
346
-
347
- Creates a fake-timer-aware async waiter. If fake timers are active it
348
- advances them; otherwise it uses a real `sleep`.
349
-
350
- ```typescript
351
- import { createFakeWaiter } from '@bemedev/dev-utils/vitest-extended';
352
-
353
- const wait = createFakeWaiter(vi);
354
-
355
- test('advances time', async () => {
356
- vi.useFakeTimers();
357
- await wait(500); // advances fake timers by 500 ms
358
- });
359
- ```
360
-
361
- **Parameters**
362
-
363
- | Name | Type | Description |
364
- | ---- | ------------- | ------------------ |
365
- | `vi` | `VitestUtils` | Vitest `vi` object |
366
-
367
- **Returns** `(ms?: number, times?: number) => Promise<void>`
368
-
369
- **Variants**
370
-
371
- | Variant | Signature | Description |
372
- | -------------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------------- |
373
- | `createFakeWaiter.withDefaultDelay(vi, ms?)` | `(index, times?) => [string, () => Promise<void>]` | Returns a labelled waiter with a fixed delay |
374
- | `createFakeWaiter.all(vi)` | `(index, ms?, times?) => [string, () => Promise<void>]` | Returns a labelled waiter with configurable delay and repetitions |
375
-
376
- ---
377
-
378
- ### `useEach(func, transform?)`
379
-
380
- A typed wrapper around `test.concurrent.each` for synchronous functions.
381
-
382
- ```typescript
383
- import { useEach } from '@bemedev/dev-utils/vitest-extended';
384
-
385
- const run = useEach(add);
386
-
387
- run(['1+2', [1, 2], 3], ['0+0', [0, 0], 0]);
388
- ```
389
-
390
- **Parameters**
391
-
392
- | Name | Type | Description |
393
- | ----------- | ------------------------ | --------------------------------- |
394
- | `func` | `Fn` | Function under test |
395
- | `transform` | `NextFn<F> \| undefined` | Optional return-value transformer |
396
-
397
- **Returns** `(...cases: TestArgs2<F>) => void`
398
-
399
- ---
400
-
401
- ### `useEachAsync(func, transform?)`
402
-
403
- Same as `useEach` but awaits the function result.
404
-
405
- ---
406
-
407
- ### `useErrorAsyncEach(func, transform?, toError?)`
408
-
409
- Runs async error cases using `expect(fn).rejects.toThrowError(error)`.
410
-
411
- ```typescript
412
- const runErrors = vitestExtended.useErrorAsyncEach(
413
- divide,
414
- undefined,
415
- ([_, b]) => (b === 0 ? 'Division by zero' : undefined),
416
- );
417
-
418
- runErrors(['divide by 0', [1, 0], undefined]);
419
- ```
420
-
421
- ---
422
-
423
- ### `useTestFunctionAcceptation(f, name?)` / `useTFA`
424
-
425
- Runs two acceptation checks: the function is defined and is actually a
426
- function.
427
-
428
- ```typescript
429
- vitestExtended.useTFA(myFunction, 'myFunction');
430
- ```
431
-
432
- ---
433
-
434
- ### Utility helpers
435
-
436
- | Export | Signature | Description |
437
- | ---------------------------------- | ----------------------------------- | ------------------------------------------------- |
438
- | `isDefined(value?)` | `(value?: T \| null) => value is T` | Type guard — not `undefined` or `null` |
439
- | `isFunction(arg)` | `(arg: any) => boolean` | Type guard — checks if arg is a callable function |
440
- | `identity(value)` | `<T>(value: T) => T` | Returns the value unchanged |
441
- | `defaultEquality(value, expected)` | `(a, b) => void` | Strict equality; sorts arrays before comparing |
442
-
443
- ---
444
-
445
- ## `rolldownConfig`
446
-
447
- Rolldown bundler configuration factory with built-in plugins for TypeScript
448
- declarations, path aliasing, circular dependency detection, and
449
- tree-shaking externals.
450
-
451
- ### `defineConfig(additionals?)`
452
-
453
- Shorthand for `defineConfig.default`.
454
-
455
- ### `defineConfig.default(params?)`
456
-
457
- Produces a full Rolldown config with the default plugin pipeline:
458
-
459
- 1. **alias** — resolves tsconfig path aliases (`rollup-plugin-tsc-alias`)
460
- 2. **tsPaths** — resolves tsconfig path imports at bundle time
461
- (`rollup-plugin-tsconfig-paths`)
462
- 3. **circulars** — warns on circular dependencies
463
- (`rollup-plugin-circular-dependency`)
464
- 4. **externals** — marks `dependencies` and `peerDependencies` as external
465
- (`rollup-plugin-node-externals`)
466
- 5. **typescript** — emits `.d.ts` declarations via the TypeScript compiler
467
- API
468
- 6. **clean** — removes JS outputs for files that produce empty chunks
469
-
470
- ```typescript
471
- // rolldown.config.ts
472
- import { defineConfig } from '@bemedev/dev-utils/rolldown';
473
-
474
- export default defineConfig.default({
475
- dir: 'lib',
476
- sourcemap: true,
477
- excludesTS: ['src/fixtures/**/*.ts'],
478
- });
479
- ```
480
-
481
- **`Params` properties**
482
-
483
- | Property | Type | Default | Description |
484
- | ---------------- | --------------------------------------- | ------------- | ------------------------------------------------------- |
485
- | `dir` | `string` | `'lib'` | Output directory |
486
- | `sourcemap` | `boolean` | `false` | Emit sourcemaps |
487
- | `declarationMap` | `boolean` | `undefined` | Emit declaration maps |
488
- | `excludesTS` | `string \| string[]` | `[]` | Extra TS files to exclude from declaration emit |
489
- | `circularDeps` | `string \| string[]` | `[]` | Extra patterns exempt from circular-dep warnings |
490
- | `ignoresJS` | `string \| string[]` | `[]` | Patterns whose empty-bundle warnings are suppressed |
491
- | `externals` | `string \| string[]` | `[]` | Additional packages to mark as external |
492
- | `plugins` | `(RolldownPluginOption \| PluginKey)[]` | default order | Custom plugin list; string keys select built-in plugins |
493
-
494
- **Default excluded files** (always applied):
495
-
496
- ```
497
- **/node_modules/**/*
498
- **/__tests__/**/*
499
- **/*.test.ts / **/*.test-d.ts
500
- **/*.fixtures.ts / **/fixtures.ts
501
- src/fixtures/**/*.ts
502
- ```
503
-
504
- **Output format:** both `esm` (`.js`) and `cjs` (`.cjs`), with
505
- `preserveModules: true`.
506
-
507
- ---
508
-
509
- ### `defineConfig.bemedev(params?)`
510
-
511
- Opinionated preset that extends `defineConfig.default` with:
512
-
513
- - Sourcemaps **enabled by default**
514
- - `DEFAULT_CIRCULAR_DEPS` merged into `circularDeps` (`**/types.ts`,
515
- `**/*.types.ts`, …)
516
- - `DEFAULT_EXCLUDE` merged into `excludesTS`
517
- - `DEFAULT_CIRCULAR_DEPS` merged into `ignoresJS`
518
-
519
- ```typescript
520
- export default defineConfig.bemedev({
521
- excludesTS: ['src/my-fixtures/**'],
522
- });
523
- ```
524
-
525
- ---
526
-
527
- ### Plugin builders (`PLUGIN_BUILDERS`)
528
-
529
- Individual plugin factories are available for custom pipeline assembly:
530
-
531
- | Key | Function | Wraps |
532
- | ------------ | ---------------------- | ------------------------------------- |
533
- | `alias` | `alias(options?)` | `rollup-plugin-tsc-alias` |
534
- | `tsPaths` | `tsPaths(options?)` | `rollup-plugin-tsconfig-paths` |
535
- | `circulars` | `circulars(options?)` | `rollup-plugin-circular-dependency` |
536
- | `externals` | `externals(options?)` | `rollup-plugin-node-externals` |
537
- | `typescript` | `typescript(options?)` | TypeScript compiler API + `tsc-alias` |
538
- | `clean` | `clean(options?)` | Custom post-build JS cleanup |
539
-
540
- Pass plugin keys as strings in the `plugins` array to reorder or subset
541
- them:
542
-
543
- ```typescript
544
- defineConfig.default({
545
- plugins: ['alias', 'tsPaths', 'externals', 'typescript'],
546
- });
547
- ```
548
-
549
- ---
550
-
551
- ## `buildTests`
552
-
553
- CLI tooling that packs your built library as a local tarball, installs it
554
- under the alias `this-gen-1`, runs your test suite against the real
555
- distributable, then tears down.
556
-
557
- Available as a sub-path export:
558
-
559
- ```typescript
560
- import {
561
- addTarball,
562
- cleanup,
563
- customImport,
564
- THIS1,
565
- } from '@bemedev/dev-utils/build-tests';
566
- ```
567
-
568
- ### CLI usage
569
-
570
- The binary is `build-tests`. It exposes three subcommands:
571
-
572
- ```bash
573
- # Install the tarball (pre-test hook)
574
- build-tests pre
575
-
576
- # Run tests with pre/post lifecycle
577
- build-tests test [--pretest] [--posttest]
578
-
579
- # Clean up tarball + uninstall (post-test hook)
580
- build-tests post
581
- ```
582
-
583
- `package.json` integration (auto-configured):
584
-
585
- ```json
586
- {
587
- "scripts": {
588
- "pretest": "build && build-tests pre",
589
- "posttest": "fmt && build-tests post"
590
- }
591
- }
592
- ```
593
-
594
- ---
595
-
596
- ### `addTarball()`
597
-
598
- Programmatic API for the `pre` step:
599
-
600
- 1. Builds the `package.json` for the `outDir` (strips `scripts`,
601
- `devDependencies`, `files`; fixes paths)
602
- 2. Runs `pnpm pack` into `.pack/`
603
- 3. Installs the resulting `.tgz` as `this-gen-1` in `devDependencies`
604
-
605
- ```typescript
606
- import { addTarball } from '@bemedev/dev-utils/build-tests';
607
-
608
- await addTarball();
609
- ```
610
-
611
- ---
612
-
613
- ### `cleanup()`
614
-
615
- Programmatic API for the `post` step:
616
-
617
- 1. Removes the `.pack/` folder
618
- 2. Runs `pnpm remove this-gen-1`
619
-
620
- ```typescript
621
- import { cleanup } from '@bemedev/dev-utils/build-tests';
622
-
623
- cleanup();
624
- ```
625
-
626
- ---
627
-
628
- ### `customImport(fn?)`
629
-
630
- Dynamically imports the installed package (`this-gen-1`) and optionally
631
- transforms its exports via a mapper function.
632
-
633
- ```typescript
634
- import { customImport } from '@bemedev/dev-utils/build-tests';
635
-
636
- // Import the default export as-is
637
- const out = await customImport();
638
-
639
- // Import and pick a specific export
640
- const myFn = await customImport(mod => mod.myFn);
641
- ```
642
-
643
- **Parameters**
644
-
645
- | Name | Type | Default | Description |
646
- | ---- | ------------------------- | ---------- | -------------------------------------------------------- |
647
- | `fn` | `(out: IndexImport) => T` | `identity` | Mapper applied to the imported module; defaults to no-op |
648
-
649
- **Returns** `Promise<T>` — the mapped module output.
650
-
651
- ---
652
-
653
- ### `THIS1`
654
-
655
- Constant string `'this-gen-1'` — the package alias used by `addTarball` and
656
- `cleanup` when installing/removing the local tarball.
657
-
658
- ```typescript
659
- import { THIS1 } from '@bemedev/dev-utils/build-tests';
660
-
661
- console.log(THIS1); // 'this-gen-1'
662
- ```
663
-
664
- ---
665
-
666
- ### Types
667
-
668
- | Name | Description |
669
- | ------------- | --------------------------------------------------------------------- |
670
- | `IndexImport` | Type of the module returned by a dynamic `import(THIS1)` call (`any`) |
671
-
672
- ---
673
-
674
- <br/>
675
-
676
- ## Licence
677
-
678
- MIT
679
-
680
- ## CHANGELOG
681
-
682
- Read [CHANGELOG.md](CHANGELOG.md) for details about all changes and
683
- versions.
684
-
685
- <br/>
686
-
687
- ## Author
688
-
689
- chlbri (bri_lvi@icloud.com)
690
-
691
- [My github](https://github.com/chlbri?tab=repositories)
692
-
693
- [<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>](https://github.com/chlbri?tab=repositories)
694
-
695
- <br/>
696
-
697
- ## Links
698
-
699
- - [GitHub Repository](https://github.com/chlbri/node-dev-utils)
700
- - [Website](https://bemedev.vercel.app)
@@ -1,4 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_vitest_alias_vitest = require("./vitest.cjs");
3
- exports.aliasTs = require_vitest_alias_vitest.aliasTs;
4
- exports.createAlias = require_vitest_alias_vitest.createAlias;
@@ -1 +0,0 @@
1
- export * from './vitest';
@@ -1,2 +0,0 @@
1
- import { aliasTs, createAlias } from "./vitest.js";
2
- export { aliasTs, createAlias };