poku 1.1.0 → 1.2.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
@@ -1,13 +1,15 @@
1
- [node-version-url]: https://nodejs.org/en/download
1
+ [node-version-url]: https://github.com/nodejs/node
2
2
  [node-version-image]: https://img.shields.io/badge/Node.js->=6.0.0-badc58
3
- [bun-version-url]: https://nodejs.org/en/download
3
+ [bun-version-url]: https://github.com/oven-sh/bun
4
4
  [bun-version-image]: https://img.shields.io/badge/Bun->=0.5.3-f471b5
5
- [deno-version-url]: https://nodejs.org/en/download
5
+ [deno-version-url]: https://github.com/denoland/deno
6
6
  [deno-version-image]: https://img.shields.io/badge/Deno->=1.30.0-70ffaf
7
7
  [npm-image]: https://img.shields.io/npm/v/poku.svg?color=3dc1d3
8
8
  [npm-url]: https://npmjs.org/package/poku
9
9
  [ci-url]: https://github.com/wellwelwel/poku/actions/workflows/ci.yml?query=branch%3Amain
10
- [ci-image]: https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci.yml?event=push&style=flat&label=ci&branch=main
10
+ [ci-image]: https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci.yml?event=push&style=flat&label=CI&branch=main
11
+ [ql-url]: https://github.com/wellwelwel/poku/actions/workflows/codeql.yml?query=branch%3Amain
12
+ [ql-image]: https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/codeql.yml?event=push&style=flat&label=Code%20QL&branch=main
11
13
  [license-url]: https://github.com/wellwelwel/poku/blob/main/LICENSE
12
14
  [license-image]: https://img.shields.io/npm/l/poku.svg?maxAge=2592000&color=9c88ff
13
15
 
@@ -15,25 +17,24 @@
15
17
 
16
18
  <img align="right" width="128" height="128" alt="Logo" src=".github/assets/readme/poku.svg">
17
19
 
18
- 🖇️ A flexible and easy-to-use **Test Runner** for [**Node**](https://github.com/nodejs/node), [**Bun**](https://github.com/oven-sh/bun) and [**Deno**](https://github.com/denoland/deno), which allows parallel or sequential runs and high isolation level.
19
-
20
- > **Poku** starts from the premise where tests come to help, not overcomplicate.
20
+ A flexible and easy-to-use **Test Runner** for [Node.js][node-version-url], [Bun][bun-version-url] and [Deno][deno-version-url] that allows you to run **parallel** and **sequential** tests, plus **high isolation level per test file**.
21
21
 
22
22
  [![Node.js Version][node-version-image]][node-version-url]
23
23
  [![Bun Version][bun-version-image]][bun-version-url]
24
24
  [![Deno Version][deno-version-image]][deno-version-url]
25
25
  [![NPM Version][npm-image]][npm-url]
26
- [![GitHub Workflow Status (with event)][ci-image]][ci-url]
27
26
  [![License][license-image]][license-url]
27
+ [![GitHub Workflow Status (with event)][ci-image]][ci-url]
28
+ [![GitHub Workflow Status (with event)][ql-image]][ql-url]
28
29
 
29
30
  ---
30
31
 
31
32
  ## Why Poku?
32
33
 
33
- Runs test files in an individual process, shows progress and exits 🪄
34
+ > **Poku** starts from the premise where tests come to help, not overcomplicate: runs test files in an individual process per file, shows progress and exits 🧙🏻
34
35
 
35
- - **Poku** is designed to be highly intuitive
36
36
  - Supports **ESM** and **CJS**
37
+ - Designed to be highly intuitive
37
38
  - No need to compile **TypeScript**
38
39
  - Compatible with **Coverage** tools
39
40
  - Allows both **in-code** and **CLI** usage
@@ -42,10 +43,18 @@ Runs test files in an individual process, shows progress and exits 🪄
42
43
 
43
44
  ---
44
45
 
45
- - Totally **dependency-free**.
46
+ - Totally **dependency-free**
46
47
  - **Poku** dive to the deepest depths to find tests in the specified directories
47
- - **Compatibility:** **Poku** is tested across all **Node 6+**, **Bun 0.5.3+** and **Deno 1.30+** versions.
48
- - **Poku** uses itself to test its own tests using `process.exit` at several depths on the same process node.
48
+ - **Compatibility:** **Poku** is tested across all **Node 6+**, **Bun 0.5.3+** and **Deno 1.30+** versions
49
+ - **Poku** uses itself to test its own tests using `process.exit` at several depths on the same process node
50
+
51
+ ---
52
+
53
+ ```bash
54
+ npx poku --include='test/unit,test/integration'
55
+ ```
56
+
57
+ <img src="./.github/assets/readme/screen-recording-2024-02-17-at-23.38.06.gif" width="360">
49
58
 
50
59
  ---
51
60
 
@@ -139,11 +148,11 @@ deno run npm:poku --include='./a,./b'
139
148
 
140
149
  ## Documentation
141
150
 
142
- > Documentation in Progress 🧑🏻‍🔧
151
+ > Website in Progress 🧑🏻‍🔧
143
152
  >
144
153
  > Initially, the documentation is based on **Node.js** usage, but you can use all the options normally for both **Bun** and **Deno**.
145
154
 
146
- ### `poku(string | string[])`
155
+ ### `poku(targetDirs: string | string[])`
147
156
 
148
157
  #### Include directories
149
158
 
@@ -165,9 +174,112 @@ npx poku --include='./targetDirA,./targetDirB'
165
174
 
166
175
  ---
167
176
 
168
- ### `poku(string | string[], configs: Configs)`
177
+ ### `poku(targetDirs: string | string[], configs?: Configs)`
178
+
179
+ #### `parallel: boolean`
180
+
181
+ Determines the mode of test execution across **sequential** or **parallel** modes.
182
+
183
+ - **in-code**
184
+
185
+ ```ts
186
+ /**
187
+ * @default
188
+ *
189
+ * Sequential mode
190
+ */
191
+
192
+ poku(['...'], {
193
+ parallel: false,
194
+ });
195
+ ```
196
+
197
+ ```ts
198
+ /**
199
+ * Parallel mode
200
+ */
201
+
202
+ poku(['...'], {
203
+ parallel: true,
204
+ });
205
+ ```
206
+
207
+ - **CLI**
169
208
 
170
- #### `filter`
209
+ > _Since **1.2.0**_
210
+
211
+ ```bash
212
+ # Parallel mode
213
+
214
+ npx poku --include='...' --parallel
215
+ ```
216
+
217
+ ---
218
+
219
+ #### `platform: "node" | "bun" | "deno"`
220
+
221
+ > _Since **1.2.0**_
222
+
223
+ By default, **Poku** tries to identify the platform automatically, but you can set it manually:
224
+
225
+ - **in-code**
226
+
227
+ ```ts
228
+ /**
229
+ * Force Node.js (or tsx for TypeScript)
230
+ *
231
+ * @default 'node'
232
+ */
233
+
234
+ poku('...', {
235
+ platform: 'node',
236
+ });
237
+ ```
238
+
239
+ ```ts
240
+ /**
241
+ * Force Bun
242
+ */
243
+
244
+ poku('...', {
245
+ platform: 'bun',
246
+ });
247
+ ```
248
+
249
+ ```ts
250
+ /**
251
+ * Force Deno
252
+ */
253
+
254
+ poku('...', {
255
+ platform: 'deno',
256
+ });
257
+ ```
258
+
259
+ - **CLI**
260
+
261
+ ```bash
262
+ # Normal
263
+
264
+ npx poku --include='...' --platform=node
265
+ bun poku --include='...' --platform=bun
266
+ deno poku --include='...' --platform=deno
267
+ ```
268
+
269
+ ```bash
270
+ # Custom
271
+
272
+ npx poku --include='...' --platform=bun
273
+ bun poku --include='...' --platform=deno
274
+ deno run poku --include='...' --platform=node
275
+ # ...
276
+ ```
277
+
278
+ ---
279
+
280
+ #### `filter: RexExp`
281
+
282
+ By default, **Poku** searches for _`.test.`_ files, but you can customize it using the `filter` option.
171
283
 
172
284
  > Filter by path using **Regex** to match only the files that should be performed.
173
285
 
@@ -204,6 +316,12 @@ poku(['...'], {
204
316
  npx poku --include='...' --filter='some-file'
205
317
  ```
206
318
 
319
+ ```bash
320
+ # Testing only a specific file
321
+
322
+ npx poku --include='...' --filter='some-file|other-file'
323
+ ```
324
+
207
325
  ```bash
208
326
  # Testing only paths that contains "unit"
209
327
 
@@ -220,6 +338,12 @@ npx poku --include='...' --filter='unit'
220
338
  FILTER='some-file' npx poku --include='...'
221
339
  ```
222
340
 
341
+ ```bash
342
+ # Testing only a specific file
343
+
344
+ FILTER='some-file|other-file' npx poku --include='...'
345
+ ```
346
+
223
347
  ```bash
224
348
  # Testing only paths that contains "unit"
225
349
 
@@ -228,34 +352,110 @@ FILTER='unit' npx poku --include='...'
228
352
 
229
353
  ---
230
354
 
231
- #### `parallel`
355
+ #### `exclude: RexExp | RexExp[]`
232
356
 
233
- Determines the mode of test execution across **parallelism** or **sequential** modes.
357
+ > Exclude by path using Regex to match only the files that should be performed.
358
+ >
359
+ > _Since **1.2.0**_
360
+
361
+ - **in-code**:
234
362
 
235
363
  ```ts
236
364
  /**
237
- * @default
238
- *
239
- * Sequential mode
365
+ * Excluding directories from tests
240
366
  */
241
367
 
242
368
  poku(['...'], {
243
- parallel: false,
369
+ exclude: /\/(helpers|tools)\//,
244
370
  });
245
371
  ```
246
372
 
247
373
  ```ts
248
374
  /**
249
- * Parallel mode
375
+ * Excluding directories from tests
250
376
  */
251
377
 
252
378
  poku(['...'], {
253
- parallel: true,
379
+ exclude: [/\/helpers\//, /\/tools\//],
380
+ });
381
+ ```
382
+
383
+ ```ts
384
+ /**
385
+ * Excluding specific files from tests
386
+ */
387
+
388
+ poku(['...'], {
389
+ exclude: /(index|common).test.ts/,
390
+ });
391
+ ```
392
+
393
+ ```ts
394
+ /**
395
+ * Excluding specific files from tests
396
+ */
397
+
398
+ poku(['...'], {
399
+ exclude: [/index.test.ts/, /common.test.ts/],
254
400
  });
255
401
  ```
256
402
 
403
+ ```ts
404
+ /**
405
+ * Excluding directories and files from tests
406
+ */
407
+
408
+ poku(['...'], {
409
+ exclude: /\/(helpers|tools)\/|(index|common).test.ts/,
410
+ });
411
+ ```
412
+
413
+ ```ts
414
+ /**
415
+ * Excluding directories and files from tests
416
+ */
417
+
418
+ poku(['...'], {
419
+ exclude: [/\/helpers\//, /\/tools\//, /index.test.ts/, /common.test.ts/],
420
+ });
421
+ ```
422
+
423
+ - **CLI**
424
+
425
+ ```bash
426
+ # Excluding directories and files from tests
427
+
428
+ npx poku --include='...' --exclude='some-file-or-dir'
429
+ ```
430
+
431
+ ```bash
432
+ # Excluding directories and files from tests
433
+
434
+ npx poku --include='...' --exclude='some-file-or-dir|other-file-or-dir'
435
+ ```
436
+
437
+ ---
438
+
439
+ ### `listFiles(targetDir: string, configs?: ListFilesConfigs)`
440
+
441
+ > _Since **1.2.0**_
442
+
443
+ Returns all files in a directory, independent of their depth.
444
+
445
+ ```ts
446
+ listFiles('some-dir');
447
+ ```
448
+
449
+ - You can use the `filter` and `exclude` options, as well as they are for **`poku`** method.
450
+
451
+ ---
452
+
453
+ ## Community
454
+
455
+ I'm continuously working to improve **Poku**. If you've got something interesting to share, feel free to submit a [**Pull Request**](https://github.com/wellwelwel/poku/compare). If you notice something wrong, I'd appreciate if you'd open an [**Issue**](https://github.com/wellwelwel/poku/issues/new).
456
+
257
457
  ---
258
458
 
259
- ## Documentation in Progress...
459
+ ## Acknowledgements
260
460
 
261
- > 🧑🏻‍🎓 Soon documenting all options and **Poku**'s usage variations.
461
+ - [**Contributors**](https://github.com/wellwelwel/poku/graphs/contributors)
@@ -0,0 +1,14 @@
1
+ export type Configs = {
2
+ /**
3
+ * Filter by path to match only the files that should be performed.
4
+ *
5
+ * @default /\.test\./i
6
+ */
7
+ filter?: RegExp;
8
+ /**
9
+ * Exclude by path to match only the files that should be performed.
10
+ *
11
+ * @default undefined
12
+ */
13
+ exclude?: RegExp | RegExp[];
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ import type { Configs as ListFilesConfigs } from './list-files.js';
1
2
  export type Configs = {
2
3
  /**
3
4
  * By setting `true`, **Poku** won't exit the process and will return the exit code (`0` or `1`).
@@ -26,16 +27,16 @@ export type Configs = {
26
27
  * @default false
27
28
  */
28
29
  quiet?: boolean;
29
- /**
30
- * Filter by path to match only the files that should be performed.
31
- *
32
- * @default /\.test\./i
33
- */
34
- filter?: RegExp;
35
30
  /**
36
31
  * Determines the mode of test execution.
37
32
  *
38
33
  * @default false
39
34
  */
40
35
  parallel?: boolean;
41
- };
36
+ /**
37
+ * Determines the platform for test execution.
38
+ *
39
+ * @default 'node'
40
+ */
41
+ platform?: 'node' | 'bun' | 'deno';
42
+ } & ListFilesConfigs;
package/lib/bin/index.js CHANGED
@@ -1,12 +1,19 @@
1
1
  #! /usr/bin/env node
2
2
  "use strict";
3
+ var _a;
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const get_files_js_1 = require("../helpers/get-files.js");
5
+ const list_files_js_1 = require("../modules/list-files.js");
5
6
  const get_arg_js_1 = require("../helpers/get-arg.js");
6
7
  const index_js_1 = require("../index.js");
7
- const rawDirs = (0, get_arg_js_1.getArg)('include');
8
- const rawFilter = (0, get_arg_js_1.getArg)('filter');
9
- const dirs = (rawDirs === null || rawDirs === void 0 ? void 0 : rawDirs.split(',')) || [];
8
+ const get_runtime_js_1 = require("../helpers/get-runtime.js");
9
+ const dirs = ((_a = (0, get_arg_js_1.getArg)('include')) === null || _a === void 0 ? void 0 : _a.split(',')) || [];
10
+ const platform = (0, get_arg_js_1.getArg)('platform');
11
+ const filter = (0, get_arg_js_1.getArg)('filter');
12
+ const parallel = (0, get_arg_js_1.hasArg)('parallel');
13
+ const exclude = (0, get_arg_js_1.getArg)('exclude');
10
14
  (0, index_js_1.poku)(dirs, {
11
- filter: rawFilter ? new RegExp((0, get_files_js_1.escapeRegExp)(rawFilter)) : undefined,
15
+ platform: (0, get_runtime_js_1.platformIsValid)(platform) ? platform : undefined,
16
+ filter: filter ? new RegExp((0, list_files_js_1.escapeRegExp)(filter)) : undefined,
17
+ exclude: exclude ? new RegExp((0, list_files_js_1.escapeRegExp)(exclude)) : undefined,
18
+ parallel,
12
19
  });
@@ -1 +1,2 @@
1
1
  export declare const getArg: (arg: string) => string | undefined;
2
+ export declare const hasArg: (arg: string) => boolean;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getArg = void 0;
6
+ exports.hasArg = exports.getArg = void 0;
7
7
  const node_process_1 = __importDefault(require("process"));
8
8
  const [, , ...args] = node_process_1.default.argv;
9
9
  const getArg = (arg) => {
@@ -14,3 +14,5 @@ const getArg = (arg) => {
14
14
  return undefined;
15
15
  };
16
16
  exports.getArg = getArg;
17
+ const hasArg = (arg) => args.some((a) => a.startsWith(`--${arg}`));
18
+ exports.hasArg = hasArg;
@@ -1 +1,4 @@
1
- export declare const getRuntime: () => "deno" | "bun" | "node";
1
+ import type { Configs } from '../@types/poku.ts';
2
+ export declare const supportedPlatforms: ReadonlyArray<Configs['platform']>;
3
+ export declare const platformIsValid: (platform: unknown) => platform is "node" | "bun" | "deno" | undefined;
4
+ export declare const getRuntime: (configs?: Configs) => (typeof supportedPlatforms)[number];
@@ -1,7 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRuntime = void 0;
4
- const getRuntime = () => {
3
+ exports.getRuntime = exports.platformIsValid = exports.supportedPlatforms = void 0;
4
+ exports.supportedPlatforms = [
5
+ 'node',
6
+ 'bun',
7
+ 'deno',
8
+ ];
9
+ const platformIsValid = (platform) => {
10
+ if (typeof platform === 'string' &&
11
+ exports.supportedPlatforms.some((supportedPlatform) => supportedPlatform === platform))
12
+ return true;
13
+ return false;
14
+ };
15
+ exports.platformIsValid = platformIsValid;
16
+ const getRuntime = (configs) => {
17
+ if ((configs === null || configs === void 0 ? void 0 : configs.platform) && (0, exports.platformIsValid)(configs.platform))
18
+ return configs.platform;
5
19
  if (typeof Deno !== 'undefined')
6
20
  return 'deno';
7
21
  if (typeof Bun !== 'undefined')
@@ -1 +1,2 @@
1
- export declare const runner: (filename: string) => string[];
1
+ import { Configs } from '../@types/poku.js';
2
+ export declare const runner: (filename: string, configs?: Configs) => string[];
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runner = void 0;
7
7
  const node_path_1 = __importDefault(require("path"));
8
8
  const get_runtime_js_1 = require("./get-runtime.js");
9
- const runtime = (0, get_runtime_js_1.getRuntime)();
10
- const runner = (filename) => {
9
+ const runner = (filename, configs) => {
10
+ const runtime = (0, get_runtime_js_1.getRuntime)(configs);
11
11
  if (runtime === 'bun')
12
12
  return ['bun'];
13
13
  if (runtime === 'deno')
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { poku } from './modules/poku.js';
2
2
  export { exit } from './modules/exit.js';
3
- export type { Code } from './@types/code.js';
4
- export type { Configs } from './@types/poku.js';
3
+ export { publicListFiles as listFiles } from './modules/list-files.js';
4
+ export type { Code } from './@types/code.ts';
5
+ export type { Configs } from './@types/poku.ts';
6
+ export type { Configs as ListFilesConfigs } from './@types/list-files.ts';
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exit = exports.poku = void 0;
3
+ exports.listFiles = exports.exit = exports.poku = void 0;
4
4
  var poku_js_1 = require("./modules/poku.js");
5
5
  Object.defineProperty(exports, "poku", { enumerable: true, get: function () { return poku_js_1.poku; } });
6
6
  var exit_js_1 = require("./modules/exit.js");
7
7
  Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_js_1.exit; } });
8
+ var list_files_js_1 = require("./modules/list-files.js");
9
+ Object.defineProperty(exports, "listFiles", { enumerable: true, get: function () { return list_files_js_1.publicListFiles; } });
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.exit = void 0;
7
7
  const node_process_1 = __importDefault(require("process"));
8
+ const node_os_1 = require("os");
8
9
  const hr_js_1 = require("../helpers/hr.js");
9
10
  const exit = (code, quiet) => {
10
11
  !quiet &&
11
12
  node_process_1.default.on('exit', (code) => {
12
- console.log(`About to exit with code`, code);
13
+ console.log(`Exited with code`, code, node_os_1.EOL);
13
14
  });
14
15
  !quiet && (0, hr_js_1.hr)();
15
16
  if (code !== 0) {
@@ -0,0 +1,4 @@
1
+ import type { Configs } from '../@types/list-files.js';
2
+ export declare const escapeRegExp: (string: string) => string;
3
+ export declare const listFiles: (dirPath: string, files?: string[], configs?: Configs) => string[];
4
+ export declare const publicListFiles: (targetDir: string, configs?: Configs) => string[];
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.publicListFiles = exports.listFiles = exports.escapeRegExp = void 0;
8
+ const node_process_1 = __importDefault(require("process"));
9
+ const node_fs_1 = __importDefault(require("fs"));
10
+ const node_path_1 = __importDefault(require("path"));
11
+ const escapeRegExp = (string) => string.replace(/[.*+?^${}()[\]\\]/g, '\\$&');
12
+ exports.escapeRegExp = escapeRegExp;
13
+ const envFilter = ((_a = node_process_1.default.env.FILTER) === null || _a === void 0 ? void 0 : _a.trim())
14
+ ? new RegExp((0, exports.escapeRegExp)(node_process_1.default.env.FILTER), 'i')
15
+ : null;
16
+ const listFiles = (dirPath, files = [], configs) => {
17
+ const currentFiles = node_fs_1.default.readdirSync(dirPath);
18
+ const defaultRegExp = /\.test\./i;
19
+ const filter = (envFilter
20
+ ? envFilter
21
+ : (configs === null || configs === void 0 ? void 0 : configs.filter) instanceof RegExp
22
+ ? configs.filter
23
+ : defaultRegExp) || defaultRegExp;
24
+ const exclude = (configs === null || configs === void 0 ? void 0 : configs.exclude)
25
+ ? Array.isArray(configs.exclude)
26
+ ? configs.exclude
27
+ : [configs.exclude]
28
+ : undefined;
29
+ for (const file of currentFiles) {
30
+ const fullPath = node_path_1.default.join(dirPath, file);
31
+ if (exclude && exclude.some((regex) => regex.test(fullPath)))
32
+ continue;
33
+ if (node_fs_1.default.statSync(fullPath).isDirectory())
34
+ (0, exports.listFiles)(fullPath, files, configs);
35
+ else if (filter.test(fullPath))
36
+ files.push(fullPath);
37
+ }
38
+ return files;
39
+ };
40
+ exports.listFiles = listFiles;
41
+ const publicListFiles = (targetDir, configs) => (0, exports.listFiles)(targetDir, [], configs);
42
+ exports.publicListFiles = publicListFiles;
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.poku = void 0;
13
13
  const force_array_js_1 = require("../helpers/force-array.js");
14
- const runTests_js_1 = require("../services/runTests.js");
14
+ const run_tests_js_1 = require("../services/run-tests.js");
15
15
  const exit_js_1 = require("./exit.js");
16
16
  function poku(targetDirs, configs) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  let code = 0;
19
19
  const dirs = (0, force_array_js_1.forceArray)(targetDirs);
20
20
  if (configs === null || configs === void 0 ? void 0 : configs.parallel) {
21
- const results = yield Promise.all(dirs.map((dir) => (0, runTests_js_1.runTestsParallel)(dir, configs)));
21
+ const results = yield Promise.all(dirs.map((dir) => (0, run_tests_js_1.runTestsParallel)(dir, configs)));
22
22
  if (results.some((result) => !result)) {
23
23
  code = 1;
24
24
  }
@@ -28,7 +28,7 @@ function poku(targetDirs, configs) {
28
28
  return;
29
29
  }
30
30
  for (const dir of dirs) {
31
- const result = yield (0, runTests_js_1.runTests)(dir, configs);
31
+ const result = yield (0, run_tests_js_1.runTests)(dir, configs);
32
32
  if (!result)
33
33
  code = 1;
34
34
  }
@@ -20,7 +20,7 @@ const runTestFile = (filePath, configs) => new Promise((resolve) => {
20
20
  const fileRelative = node_path_1.default.relative(node_process_1.default.cwd(), filePath);
21
21
  showLogs &&
22
22
  console.log(`${indentation_js_1.indentation.test}${format_js_1.format.info('→')} ${fileRelative}`);
23
- const runtimeOptions = (0, runner_js_1.runner)(filePath);
23
+ const runtimeOptions = (0, runner_js_1.runner)(filePath, configs);
24
24
  const runtime = runtimeOptions.shift();
25
25
  const runtimeArguments = runtimeOptions.length > 1 ? [...runtimeOptions, filePath] : [filePath];
26
26
  const child = (0, node_child_process_1.spawn)(runtime, runtimeArguments, {
@@ -18,16 +18,16 @@ const node_os_1 = require("os");
18
18
  const node_path_1 = __importDefault(require("path"));
19
19
  const runner_js_1 = require("../helpers/runner.js");
20
20
  const indentation_js_1 = require("../helpers/indentation.js");
21
- const get_files_js_1 = require("../helpers/get-files.js");
21
+ const list_files_js_1 = require("../modules/list-files.js");
22
22
  const hr_js_1 = require("../helpers/hr.js");
23
23
  const format_js_1 = require("../helpers/format.js");
24
- const runTestFile_js_1 = require("./runTestFile.js");
24
+ const run_test_file_js_1 = require("./run-test-file.js");
25
25
  const logs_js_1 = require("../helpers/logs.js");
26
26
  const runTests = (dir, configs) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  const cwd = node_process_1.default.cwd();
28
28
  const testDir = node_path_1.default.join(cwd, dir);
29
29
  const currentDir = node_path_1.default.relative(cwd, testDir);
30
- const files = (0, get_files_js_1.getFiles)(testDir, undefined, configs);
30
+ const files = (0, list_files_js_1.listFiles)(testDir, undefined, configs);
31
31
  const totalTests = files.length;
32
32
  const showLogs = !(0, logs_js_1.isQuiet)(configs);
33
33
  let passed = true;
@@ -38,10 +38,10 @@ const runTests = (dir, configs) => __awaiter(void 0, void 0, void 0, function* (
38
38
  for (let i = 0; i < files.length; i++) {
39
39
  const filePath = files[i];
40
40
  const fileRelative = node_path_1.default.relative(cwd, filePath);
41
- const testPassed = yield (0, runTestFile_js_1.runTestFile)(filePath, configs);
41
+ const testPassed = yield (0, run_test_file_js_1.runTestFile)(filePath, configs);
42
42
  const testNumber = i + 1;
43
43
  const counter = format_js_1.format.counter(testNumber, totalTests);
44
- const command = `${(0, runner_js_1.runner)(fileRelative).join(' ')} ${fileRelative}`;
44
+ const command = `${(0, runner_js_1.runner)(fileRelative, configs).join(' ')} ${fileRelative}`;
45
45
  const nextLine = i + 1 !== files.length ? node_os_1.EOL : '';
46
46
  const log = `${counter}/${totalTests} ${command}${nextLine}`;
47
47
  if (testPassed) {
@@ -59,11 +59,11 @@ exports.runTests = runTests;
59
59
  const runTestsParallel = (dir, configs) => __awaiter(void 0, void 0, void 0, function* () {
60
60
  const cwd = node_process_1.default.cwd();
61
61
  const testDir = node_path_1.default.join(cwd, dir);
62
- const files = (0, get_files_js_1.getFiles)(testDir, undefined, configs);
62
+ const files = (0, list_files_js_1.listFiles)(testDir, undefined, configs);
63
63
  const showLogs = !(0, logs_js_1.isQuiet)(configs);
64
64
  const promises = files.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
65
65
  const fileRelative = node_path_1.default.relative(cwd, filePath);
66
- const testPassed = yield (0, runTestFile_js_1.runTestFile)(filePath, configs);
66
+ const testPassed = yield (0, run_test_file_js_1.runTestFile)(filePath, configs);
67
67
  const command = `${(0, runner_js_1.runner)(fileRelative).join(' ')} ${fileRelative}`;
68
68
  if (testPassed) {
69
69
  showLogs &&
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poku",
3
- "version": "1.1.0",
4
- "description": "🐷 A flexible and easy-to-use Test Runner for Node, Bun and Deno, which allows parallel or sequential runs and high isolation level",
3
+ "version": "1.2.0",
4
+ "description": "🐷 Poku is a flexible and easy-to-use Test Runner for Node.js, Bun and Deno that allows you to run parallel and sequential tests, plus high isolation level per test file",
5
5
  "main": "./lib/index.js",
6
6
  "scripts": {
7
7
  "test": "npx tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
@@ -9,7 +9,7 @@
9
9
  "test:node": "FILTER='node-' npm run test:ci",
10
10
  "test:deno": "FILTER='deno-' npm run test:ci",
11
11
  "test:bun": "FILTER='bun-' npm run test:ci",
12
- "update": "npx npu; npm run init",
12
+ "update": "npx npu;",
13
13
  "prebuild": "rm -rf ./lib ./ci",
14
14
  "build": "npx tsc; npx tsc -p tsconfig.test.json",
15
15
  "postbuild": "npx tsx ./tools/compatibility/node.ts; npm audit",
@@ -43,7 +43,11 @@
43
43
  "typescript",
44
44
  "filter",
45
45
  "queue",
46
- "queuing"
46
+ "queuing",
47
+ "nodejs",
48
+ "node",
49
+ "bun",
50
+ "deno"
47
51
  ],
48
52
  "author": "https://github.com/wellwelwel",
49
53
  "bugs": {
@@ -51,6 +55,7 @@
51
55
  },
52
56
  "engines": {
53
57
  "node": ">=6.0.0",
58
+ "bun": ">=0.5.3",
54
59
  "deno": ">=1.17.0"
55
60
  },
56
61
  "files": [
@@ -58,7 +63,7 @@
58
63
  ],
59
64
  "type": "commonjs",
60
65
  "devDependencies": {
61
- "@types/node": "^20.11.17",
66
+ "@types/node": "^20.11.19",
62
67
  "@typescript-eslint/eslint-plugin": "^7.0.1",
63
68
  "@typescript-eslint/parser": "^7.0.1",
64
69
  "eslint": "^8.56.0",
@@ -1,4 +0,0 @@
1
- import type { Configs } from '../@types/poku.ts';
2
- export declare const escapeRegExp: (string: string) => string;
3
- export declare const envFilter: RegExp | null;
4
- export declare const getFiles: (dirPath: string, files?: string[], configs?: Configs) => string[];
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- var _a;
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.getFiles = exports.envFilter = exports.escapeRegExp = void 0;
8
- const node_process_1 = __importDefault(require("process"));
9
- const node_fs_1 = __importDefault(require("fs"));
10
- const node_path_1 = __importDefault(require("path"));
11
- const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
12
- exports.escapeRegExp = escapeRegExp;
13
- exports.envFilter = ((_a = node_process_1.default.env.FILTER) === null || _a === void 0 ? void 0 : _a.trim())
14
- ? new RegExp((0, exports.escapeRegExp)(node_process_1.default.env.FILTER), 'i')
15
- : null;
16
- const getFiles = (dirPath, files = [], configs) => {
17
- const currentFiles = node_fs_1.default.readdirSync(dirPath);
18
- const filter = (exports.envFilter ? exports.envFilter : configs === null || configs === void 0 ? void 0 : configs.filter) || /\.test\./i;
19
- for (const file of currentFiles) {
20
- const fullPath = node_path_1.default.join(dirPath, file);
21
- if (node_fs_1.default.statSync(fullPath).isDirectory()) {
22
- (0, exports.getFiles)(fullPath, files, configs);
23
- }
24
- else if (filter.test(fullPath)) {
25
- files.push(fullPath);
26
- }
27
- }
28
- return files;
29
- };
30
- exports.getFiles = getFiles;
File without changes