poku 1.14.0 → 1.15.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.
Files changed (42) hide show
  1. package/README.md +39 -38
  2. package/lib/@types/describe.d.ts +10 -0
  3. package/lib/@types/describe.js +4 -0
  4. package/lib/@types/list-files.d.ts +2 -2
  5. package/lib/@types/poku.d.ts +4 -0
  6. package/lib/bin/index.js +48 -36
  7. package/lib/configs/files.d.ts +2 -0
  8. package/lib/configs/files.js +4 -3
  9. package/lib/configs/indentation.d.ts +3 -0
  10. package/lib/configs/indentation.js +3 -0
  11. package/lib/helpers/get-arg.d.ts +1 -13
  12. package/lib/helpers/get-arg.js +24 -53
  13. package/lib/helpers/hr.js +4 -3
  14. package/lib/helpers/logs.d.ts +6 -0
  15. package/lib/helpers/logs.js +27 -1
  16. package/lib/helpers/parse-assertion.js +25 -15
  17. package/lib/helpers/runner.js +3 -2
  18. package/lib/helpers/time.d.ts +2 -0
  19. package/lib/helpers/time.js +19 -0
  20. package/lib/index.d.ts +6 -4
  21. package/lib/index.js +11 -8
  22. package/lib/modules/create-service.js +6 -5
  23. package/lib/modules/describe.d.ts +7 -26
  24. package/lib/modules/describe.js +63 -25
  25. package/lib/modules/exit.js +13 -4
  26. package/lib/modules/it.d.ts +4 -0
  27. package/lib/modules/it.js +66 -0
  28. package/lib/modules/list-files-sync.d.ts +2 -0
  29. package/lib/modules/list-files-sync.js +48 -0
  30. package/lib/modules/list-files.d.ts +2 -4
  31. package/lib/modules/list-files.js +97 -36
  32. package/lib/modules/log.d.ts +7 -0
  33. package/lib/modules/log.js +14 -0
  34. package/lib/modules/poku.js +28 -36
  35. package/lib/modules/test.d.ts +2 -0
  36. package/lib/modules/test.js +32 -1
  37. package/lib/services/each.js +5 -4
  38. package/lib/services/run-test-file.js +22 -42
  39. package/lib/services/run-tests.js +23 -17
  40. package/package.json +15 -12
  41. package/lib/helpers/remove-repeats.d.ts +0 -1
  42. package/lib/helpers/remove-repeats.js +0 -31
package/README.md CHANGED
@@ -44,14 +44,18 @@ Enjoying **Poku**? Give him a star to show your support ⭐️
44
44
  <img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> No configurations<br />
45
45
  <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Auto detect **ESM** and **CJS**<br />
46
46
  <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Auto detect **Typescript** files<br />
47
- <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Don't export your **server** (_just run it_) 🚀<br />
48
- <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Run the same test suite for [**Node.js**][node-version-url], [**Bun**][bun-version-url] and [**Deno**][deno-version-url].<br />
47
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Run the same test suite for [**Node.js**][node-version-url], [**Bun**][bun-version-url] and [**Deno**][deno-version-url]<br />
48
+
49
+ <img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Easier and Less Verbose<br />
50
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> [**Node.js**][node-version-url] familiar **API**<br />
51
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Easily test your server just by running it 🚀<br />
52
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Run **CJS** (**CommonJS**) files directly with [**Deno**][deno-version-url]<br />
53
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Easily handle **services**, **servers**, **processes** and **ports**<br />
49
54
 
50
55
  <img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Safety and Reliability<br />
51
56
  <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> High **isolation** level per file<br />
57
+ <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Performant and lightweight<br />
52
58
  <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Compatible with **Coverage** tools<br />
53
- <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Run **CJS** (**CommonJS**) files directly with [**Deno**][deno-version-url]<br />
54
- <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Easily handle **services**, **servers**, **processes** and **ports**<br />
55
59
  <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> **Poku** doesn't use `eval` nor global state 🔐<br />
56
60
  <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> _In other words, you can run your tests directly, without relying on **Poku**_<br />
57
61
 
@@ -174,15 +178,15 @@ That's it 🎉
174
178
  - **Background Services**
175
179
  - [**startScript**](https://poku.io/docs/documentation/startScript) (_run `package.json` scripts in a background process_)
176
180
  - [**startService**](https://poku.io/docs/documentation/startService) (_run files in a background process_)
177
- - **Processes**
178
- - [**kill**](https://poku.io/docs/documentation/processes/kill) (_terminate Ports, Port Ranges and PIDs_)
179
- - [**getPIDs**](https://poku.io/docs/documentation/processes/get-pids) (_get all processes IDs using ports and port ranges_)
180
181
 
181
182
  ### Helpers
182
183
 
183
- - [**beforeEach**](https://poku.io/docs/category/beforeeach-and-aftereach) and [**afterEach**](https://poku.io/docs/category/beforeeach-and-aftereach)
184
184
  - [**test**](https://poku.io/docs/documentation/helpers/test)
185
- - [**describe**](https://poku.io/docs/documentation/helpers/describe)
185
+ - [**describe**](https://poku.io/docs/documentation/helpers/describe) and [**it**](https://poku.io/docs/documentation/helpers/it)
186
+ - [**beforeEach**](https://poku.io/docs/category/beforeeach-and-aftereach) and [**afterEach**](https://poku.io/docs/category/beforeeach-and-aftereach)
187
+ - **Processes**
188
+ - [**kill**](https://poku.io/docs/documentation/processes/kill) (_terminate Ports, Port Ranges and PIDs_)
189
+ - [**getPIDs**](https://poku.io/docs/documentation/processes/get-pids) (_get all processes IDs using ports and port ranges_)
186
190
  - _and much more_ ✨
187
191
 
188
192
  ---
@@ -193,14 +197,10 @@ To see the detailed documentation, please visit the [**Documentation**](https://
193
197
 
194
198
  ---
195
199
 
196
- ## Community
197
-
198
- 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).
199
-
200
- ---
201
-
202
200
  ## Contributing
203
201
 
202
+ > 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).
203
+
204
204
  Please check the [**CONTRIBUTING.md**](./CONTRIBUTING.md) for instructions 🚀
205
205
 
206
206
  ---
@@ -211,32 +211,42 @@ Please check the [**Philosophy**](https://poku.io/docs/philosophy) section from
211
211
 
212
212
  ---
213
213
 
214
- ## License
214
+ ## Security Policy
215
215
 
216
- Poku is under the [**MIT License**](./LICENSE).
216
+ [![GitHub Workflow Status (with event)][ql-image]][ql-url]
217
+
218
+ Please check the [**SECURITY.md**](./SECURITY.md) and the section [**Is Poku Safe?**](https://poku.io/docs/security) from Documentation.
217
219
 
218
220
  ---
219
221
 
220
- ## Security Policy
222
+ ## Quick Comparisons
221
223
 
222
- [![GitHub Workflow Status (with event)][ql-image]][ql-url]
224
+ ### Performance
223
225
 
224
- Please check the [**SECURITY.md**](./SECURITY.md) and the section [**Is Poku Safe?**](https://poku.io/docs/security) from Documentation.
226
+ **Poku** is continuously tested ([**CI**](https://github.com/wellwelwel/poku/blob/main/.github/workflows/ci_benchmark.yml)) to ensure the following expectations:
227
+
228
+ - [x] **~4x** faster than [**Jest**](https://github.com/jestjs/jest) (v29.7.0)
229
+ - [x] **~3x** faster than [**Vitest**](https://github.com/vitest-dev/vitest) (v1.6.0)
230
+ - [x] **~1x** faster than [**Mocha**](https://github.com/mochajs/mocha) (v10.4.0) + [**Chai**](https://github.com/chaijs/chai) (v5.1.1)
231
+
232
+ > You can see how the tests are run and compared in the [benchmark](https://github.com/wellwelwel/poku/tree/main/benchmark) directory.
225
233
 
226
234
  ---
227
235
 
228
- ## Limitations
236
+ ### Installation Size
229
237
 
230
- - **Poku** community is gradually building up 🤝
231
- - Although it has no external dependencies, **Poku** is not _all-in-one_, so it doesn't have features such as _mocks_ and _spies_, where you can use your favorite packages or native solutions.
238
+ <a href="https://pkg-size.dev/poku"><img src="https://pkg-size.dev/badge/install/125875" title="Install size for poku"></a>
239
+
240
+ - [x] [~**175x** lighter than **Jest**](https://pkg-size.dev/jest)
241
+ - [x] [~**302x** lighter than **Vitest**](https://pkg-size.dev/vitest)
242
+ - [x] [~**44x** lighter than **Mocha** + **Chai**](https://pkg-size.dev/mocha%20chai)
232
243
 
233
244
  ---
234
245
 
235
- ## Overview
246
+ ### Limitations
236
247
 
237
- | Sequential | Concurrent |
238
- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
239
- | <img src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/sequential.png" /> | <img src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/parallel.png" /> |
248
+ - **Poku** community is gradually building up 🤝
249
+ - Although it has no external dependencies, **Poku** is not _all-in-one_, so it doesn't have features such as _mocks_ and _spies_, where you can use your favorite packages or native solutions.
240
250
 
241
251
  ---
242
252
 
@@ -248,15 +258,6 @@ Please check the [**SECURITY.md**](./SECURITY.md) and the section [**Is Poku Saf
248
258
 
249
259
  ---
250
260
 
251
- ## Author
261
+ ## License
252
262
 
253
- <a href="https://github.com/wellwelwel">
254
- <table>
255
- <tr>
256
- <td align="center">
257
- <img src="https://avatars.githubusercontent.com/u/46850407" alt="wellwelwel" width=96><br>
258
- <em>@wellwelwel</em>
259
- </td>
260
- </tr>
261
- </table>
262
- </a>
263
+ Poku is under the [**MIT License**](./LICENSE).
@@ -0,0 +1,10 @@
1
+ import { type backgroundColor } from '../helpers/format.js';
2
+ export type DescribeOptions = {
3
+ background?: keyof typeof backgroundColor | boolean;
4
+ /**
5
+ * @default "☰"
6
+ */
7
+ icon?: string;
8
+ /** @deprecated */
9
+ pad?: boolean;
10
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /* c8 ignore start */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /* c8 ignore stop */
@@ -13,6 +13,6 @@ export type Configs = {
13
13
  exclude?: RegExp | RegExp[];
14
14
  };
15
15
  export type FileResults = {
16
- success: string[];
17
- fail: string[];
16
+ success: Map<string, string>;
17
+ fail: Map<string, string>;
18
18
  };
@@ -97,3 +97,7 @@ export type Configs = {
97
97
  afterEach?: () => unknown | Promise<unknown>;
98
98
  deno?: DenoOptions;
99
99
  } & ListFilesConfigs;
100
+ export type FinalResults = {
101
+ time: string;
102
+ started: Date;
103
+ };
package/lib/bin/index.js CHANGED
@@ -10,56 +10,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  step((generator = generator.apply(thisArg, _arguments || [])).next());
11
11
  });
12
12
  };
13
- var _a, _b, _c;
14
13
  Object.defineProperty(exports, "__esModule", { value: true });
15
14
  const list_files_js_1 = require("../modules/list-files.js");
16
15
  const get_arg_js_1 = require("../helpers/get-arg.js");
17
- const index_js_1 = require("../index.js");
16
+ const poku_js_1 = require("../modules/poku.js");
17
+ const processes_js_1 = require("../modules/processes.js");
18
18
  const get_runtime_js_1 = require("../helpers/get-runtime.js");
19
19
  const format_js_1 = require("../helpers/format.js");
20
- // Argument with values
21
- const dirs = ((0, get_arg_js_1.hasArg)('include')
22
- ? (_a = (0, get_arg_js_1.getArg)('include')) === null || _a === void 0 ? void 0 : _a.split(',')
23
- : (_b = (0, get_arg_js_1.getLastParam)()) === null || _b === void 0 ? void 0 : _b.split(',')) || [];
24
- const platform = (0, get_arg_js_1.getArg)('platform');
25
- const filter = (0, get_arg_js_1.getArg)('filter');
26
- const exclude = (0, get_arg_js_1.getArg)('exclude');
27
- const killPort = (0, get_arg_js_1.getArg)('kill-port');
28
- const killRange = (0, get_arg_js_1.getArg)('kill-range');
29
- const killPID = (0, get_arg_js_1.getArg)('kill-pid');
30
- const concurrency = Number((0, get_arg_js_1.getArg)('concurrency')) || undefined;
31
- const denoAllow = (0, get_arg_js_1.getSubArg)('deno-allow');
32
- const denoDeny = (0, get_arg_js_1.getSubArg)('deno-deny');
33
- const denoCJS = ((_c = (0, get_arg_js_1.getArg)('deno-cjs')) === null || _c === void 0 ? void 0 : _c.split(',')) || (0, get_arg_js_1.hasArg)('deno-cjs');
34
- // Multiple arguments with values or not
35
- // TODO (Custom Args)
36
- // const args = getAllArgs('arg');
37
- // Argument exists
38
- const parallel = (0, get_arg_js_1.hasArg)('parallel');
39
- const quiet = (0, get_arg_js_1.hasArg)('quiet');
40
- const debug = (0, get_arg_js_1.hasArg)('debug');
41
- const failFast = (0, get_arg_js_1.hasArg)('fail-fast');
42
- if ((0, get_arg_js_1.hasArg)('log-success'))
43
- console.log(`The flag ${format_js_1.format.bold('--log-success')} is deprecated. Use ${format_js_1.format.bold('--debug')} instead.`);
20
+ const logs_js_1 = require("../helpers/logs.js");
21
+ const hr_js_1 = require("../helpers/hr.js");
44
22
  (() => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a;
24
+ const dirs = (() => {
25
+ const includeArg = (0, get_arg_js_1.getArg)('include');
26
+ if (includeArg !== undefined)
27
+ return includeArg.split(',');
28
+ const lastParam = (0, get_arg_js_1.getLastParam)();
29
+ if (lastParam !== undefined)
30
+ return lastParam.split(',');
31
+ return ['.'];
32
+ })();
33
+ const platform = (0, get_arg_js_1.getArg)('platform');
34
+ const filter = (0, get_arg_js_1.getArg)('filter');
35
+ const exclude = (0, get_arg_js_1.getArg)('exclude');
36
+ const killPort = (0, get_arg_js_1.getArg)('kill-port');
37
+ const killRange = (0, get_arg_js_1.getArg)('kill-range');
38
+ const killPID = (0, get_arg_js_1.getArg)('kill-pid');
39
+ const denoAllow = (0, get_arg_js_1.argToArray)('deno-allow');
40
+ const denoDeny = (0, get_arg_js_1.argToArray)('deno-deny');
41
+ const denoCJS = ((_a = (0, get_arg_js_1.getArg)('deno-cjs')) === null || _a === void 0 ? void 0 : _a.split(',').map((a) => a.trim()).filter((a) => a)) || (0, get_arg_js_1.hasArg)('deno-cjs');
42
+ const parallel = (0, get_arg_js_1.hasArg)('parallel');
43
+ const quiet = (0, get_arg_js_1.hasArg)('quiet');
44
+ const debug = (0, get_arg_js_1.hasArg)('debug');
45
+ const failFast = (0, get_arg_js_1.hasArg)('fail-fast');
46
+ const concurrency = parallel
47
+ ? Number((0, get_arg_js_1.getArg)('concurrency')) || undefined
48
+ : undefined;
45
49
  if (killPort) {
46
- const ports = killPort.split(',').map((port) => Number(port));
47
- yield index_js_1.kill.port(ports);
50
+ const ports = killPort.split(',').map(Number);
51
+ yield processes_js_1.kill.port(ports);
48
52
  }
49
53
  if (killRange) {
50
54
  const ranges = killRange.split(',');
51
55
  for (const range of ranges) {
52
- const ports = range.split('-').map((port) => Number(port));
56
+ const ports = range.split('-').map(Number);
53
57
  const startsAt = ports[0];
54
58
  const endsAt = ports[1];
55
- yield index_js_1.kill.range(startsAt, endsAt);
59
+ yield processes_js_1.kill.range(startsAt, endsAt);
56
60
  }
57
61
  }
58
62
  if (killPID) {
59
- const PIDs = killPID.split(',').map((port) => Number(port));
60
- yield index_js_1.kill.pid(PIDs);
63
+ const PIDs = killPID.split(',').map(Number);
64
+ yield processes_js_1.kill.pid(PIDs);
61
65
  }
62
- yield (0, index_js_1.poku)(dirs, {
66
+ const options = {
63
67
  platform: (0, get_runtime_js_1.platformIsValid)(platform) ? platform : undefined,
64
68
  filter: filter ? new RegExp((0, list_files_js_1.escapeRegExp)(filter)) : undefined,
65
69
  exclude: exclude ? new RegExp((0, list_files_js_1.escapeRegExp)(exclude)) : undefined,
@@ -68,13 +72,21 @@ if ((0, get_arg_js_1.hasArg)('log-success'))
68
72
  debug,
69
73
  failFast,
70
74
  concurrency,
71
- // TODO (Custom Args)
72
- // arguments: args.length > 0 ? args : undefined,
73
75
  deno: {
74
76
  allow: denoAllow,
75
77
  deny: denoDeny,
76
78
  cjs: denoCJS,
77
79
  },
78
- });
80
+ };
81
+ if (debug) {
82
+ (0, hr_js_1.hr)();
83
+ (0, logs_js_1.write)(`${format_js_1.format.bg(104, 'Debug Enabled')}\n`);
84
+ (0, logs_js_1.write)(`${format_js_1.format.italic(format_js_1.format.info('…'))} ${format_js_1.format.bold('Paths')}`);
85
+ console.table(dirs);
86
+ (0, logs_js_1.write)('\n');
87
+ (0, logs_js_1.write)(`${format_js_1.format.italic(format_js_1.format.info('…'))} ${format_js_1.format.bold('Options')}`);
88
+ console.dir(options, { depth: null, colors: true });
89
+ }
90
+ (0, poku_js_1.poku)(dirs, options);
79
91
  }))();
80
92
  /* c8 ignore stop */
@@ -1,2 +1,4 @@
1
1
  import type { FileResults } from '../@types/list-files.js';
2
+ import type { FinalResults } from '../@types/poku.js';
2
3
  export declare const fileResults: FileResults;
4
+ export declare const finalResults: FinalResults;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  /* c8 ignore start */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.fileResults = void 0;
4
+ exports.finalResults = exports.fileResults = void 0;
5
5
  exports.fileResults = {
6
- success: [],
7
- fail: [],
6
+ success: new Map(),
7
+ fail: new Map(),
8
8
  };
9
+ exports.finalResults = {};
9
10
  /* c8 ignore stop */
@@ -1,4 +1,7 @@
1
1
  export declare const indentation: {
2
2
  test: string;
3
3
  stdio: string;
4
+ hasDescribe: boolean;
5
+ hasTest: boolean;
6
+ hasIt: boolean;
4
7
  };
@@ -5,5 +5,8 @@ exports.indentation = void 0;
5
5
  exports.indentation = {
6
6
  test: ' ',
7
7
  stdio: ' ',
8
+ hasDescribe: false,
9
+ hasTest: false,
10
+ hasIt: false,
8
11
  };
9
12
  /* c8 ignore stop */
@@ -12,19 +12,6 @@
12
12
  * ```
13
13
  */
14
14
  export declare const getArg: (arg: string, prefix?: string) => string | undefined;
15
- /**
16
- * Parses all arguments of an argument value.
17
- *
18
- * ---
19
- *
20
- * CLI arguments examples:
21
- *
22
- * ```sh
23
- * command --arg='--sub=some' # ['--sub=some']
24
- * command --arg='--sub=some, --sub2' # ['--sub=some', '--sub2']
25
- * ```
26
- */
27
- export declare const getSubArg: (arg: string, prefix?: string) => string[] | undefined;
28
15
  /**
29
16
  * Checks if an argument exists.
30
17
  *
@@ -51,3 +38,4 @@ export declare const hasArg: (arg: string, prefix?: string) => boolean;
51
38
  * ```
52
39
  */
53
40
  export declare const getLastParam: (prefix?: string) => string | undefined;
41
+ export declare const argToArray: (arg: string, prefix?: string) => string[] | undefined;
@@ -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.getLastParam = exports.hasArg = exports.getSubArg = exports.getArg = void 0;
6
+ exports.argToArray = exports.getLastParam = exports.hasArg = exports.getArg = void 0;
7
7
  /* c8 ignore start */
8
8
  const node_process_1 = __importDefault(require("process"));
9
9
  const [, , ...processArgs] = node_process_1.default.argv;
@@ -21,33 +21,13 @@ const [, , ...processArgs] = node_process_1.default.argv;
21
21
  * ```
22
22
  */
23
23
  const getArg = (arg, prefix = '--') => {
24
- var _a;
25
- const mountArg = processArgs.find((a) => a.startsWith(`${prefix}${arg}=`));
26
- if (!mountArg)
24
+ const argPattern = `${prefix}${arg}=`;
25
+ const argValue = processArgs.find((a) => a.startsWith(argPattern));
26
+ if (!argValue)
27
27
  return undefined;
28
- return (_a = mountArg.split('=')) === null || _a === void 0 ? void 0 : _a[1].replace(/''|""/, '');
28
+ return argValue.slice(argPattern.length).replace(/''|""/, '');
29
29
  };
30
30
  exports.getArg = getArg;
31
- /**
32
- * Parses all arguments of an argument value.
33
- *
34
- * ---
35
- *
36
- * CLI arguments examples:
37
- *
38
- * ```sh
39
- * command --arg='--sub=some' # ['--sub=some']
40
- * command --arg='--sub=some, --sub2' # ['--sub=some', '--sub2']
41
- * ```
42
- */
43
- const getSubArg = (arg, prefix = '--') => {
44
- var _a, _b;
45
- if ((0, exports.hasArg)(arg) && !((_a = (0, exports.getArg)(arg)) === null || _a === void 0 ? void 0 : _a[1]))
46
- return [];
47
- return (_b = processArgs
48
- .find((a) => a.startsWith(`${prefix}${arg}=`))) === null || _b === void 0 ? void 0 : _b.split(`--${arg}=`)[1].split(',').map((a) => a.trim()).filter((a) => a && !/''|""/.test(a));
49
- };
50
- exports.getSubArg = getSubArg;
51
31
  /**
52
32
  * Checks if an argument exists.
53
33
  *
@@ -60,7 +40,10 @@ exports.getSubArg = getSubArg;
60
40
  * command # false
61
41
  * ```
62
42
  */
63
- const hasArg = (arg, prefix = '--') => processArgs.some((a) => a.startsWith(`${prefix}${arg}`));
43
+ const hasArg = (arg, prefix = '--') => {
44
+ const argPattern = `${prefix}${arg}`;
45
+ return processArgs.some((a) => a.startsWith(argPattern));
46
+ };
64
47
  exports.hasArg = hasArg;
65
48
  /**
66
49
  * Gets the last param/value.
@@ -81,31 +64,19 @@ const getLastParam = (prefix = '--') => {
81
64
  return lastArg;
82
65
  };
83
66
  exports.getLastParam = getLastParam;
84
- // TODO (Custom Args)
85
- // export const getAllArgs = (arg: string, prefix = '--'): string[] => {
86
- // return processArgs
87
- // .filter((a) => a.startsWith(`${prefix}${arg}=`) || a === `${prefix}${arg}`)
88
- // .map((a) => {
89
- // const [key, ...value] = a.split('=');
90
- // return value.length > 0 ? value.join('=') : key;
91
- // });
92
- // };
93
- // TODO (Custom Args)
94
- // export const setArgs = (
95
- // args: (string | Record<string, string>)[],
96
- // options?: { prefix: string }
97
- // ): string[] => {
98
- // const customArgs: string[] = [];
99
- // const prefix = options?.prefix || '';
100
- // args.forEach((arg) => {
101
- // if (!Array.isArray(arg) && typeof arg === 'object') {
102
- // for (const key in arg) {
103
- // customArgs.push(`${prefix}${key}=${arg[key]}`);
104
- // }
105
- // return;
106
- // }
107
- // customArgs.push(`${prefix}${arg}`);
108
- // });
109
- // return customArgs;
110
- // };
67
+ const argToArray = (arg, prefix = '--') => {
68
+ const hasArgument = (0, exports.hasArg)(arg);
69
+ if (!hasArgument)
70
+ return undefined;
71
+ const argValue = (0, exports.getArg)(arg, prefix);
72
+ if (hasArgument && !argValue)
73
+ return [];
74
+ if (!argValue)
75
+ return undefined;
76
+ return argValue
77
+ .split(',')
78
+ .map((a) => a.trim())
79
+ .filter((a) => a);
80
+ };
81
+ exports.argToArray = argToArray;
111
82
  /* c8 ignore stop */
package/lib/helpers/hr.js CHANGED
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.hr = void 0;
8
- const node_os_1 = require("os");
9
8
  const node_process_1 = __importDefault(require("process"));
9
+ const node_os_1 = require("os");
10
+ const logs_js_1 = require("./logs.js");
10
11
  const hr = () => {
11
- const line = '⎯'.repeat(node_process_1.default.stdout.columns - 10);
12
- console.log(`${node_os_1.EOL}\x1b[2m\x1b[90m${line}\x1b[0m${node_os_1.EOL}`);
12
+ const line = '⎯'.repeat(node_process_1.default.stdout.columns - 10 || 40);
13
+ (0, logs_js_1.write)(`${node_os_1.EOL}\x1b[2m\x1b[90m${line}\x1b[0m${node_os_1.EOL}`);
13
14
  };
14
15
  exports.hr = hr;
15
16
  /* c8 ignore stop */
@@ -1,3 +1,9 @@
1
1
  import type { Configs } from '../@types/poku.js';
2
2
  export declare const isQuiet: (configs?: Configs) => boolean;
3
3
  export declare const isDebug: (configs?: Configs) => boolean;
4
+ export declare const write: (data: string | Uint8Array) => boolean;
5
+ export declare const printOutput: (options: {
6
+ output: string;
7
+ result: boolean;
8
+ configs?: Configs;
9
+ }) => void;
@@ -1,8 +1,34 @@
1
1
  "use strict";
2
+ /* c8 ignore start */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDebug = exports.isQuiet = void 0;
7
+ exports.printOutput = exports.write = exports.isDebug = exports.isQuiet = void 0;
8
+ const node_process_1 = __importDefault(require("process"));
9
+ const node_os_1 = require("os");
4
10
  const isQuiet = (configs) => typeof (configs === null || configs === void 0 ? void 0 : configs.quiet) === 'boolean' && Boolean(configs === null || configs === void 0 ? void 0 : configs.quiet);
5
11
  exports.isQuiet = isQuiet;
6
12
  const isDebug = (configs) => Boolean(configs === null || configs === void 0 ? void 0 : configs.debug);
7
13
  exports.isDebug = isDebug;
14
+ const write = (data) => node_process_1.default.stdout.write(`${String(data)}\n`);
15
+ exports.write = write;
16
+ const printOutput = (options) => {
17
+ const { output, result, configs } = options;
18
+ const debug = (0, exports.isDebug)(configs);
19
+ const pad = (configs === null || configs === void 0 ? void 0 : configs.parallel) ? ' ' : ' ';
20
+ const splittedOutput = output.split(/\n/);
21
+ const outputs = (debug || !result
22
+ ? splittedOutput
23
+ : splittedOutput.filter((current) => {
24
+ if (current.includes('Exited with code'))
25
+ return false;
26
+ return (/u001b\[0m|\n/i.test(JSON.stringify(current)) || current === '');
27
+ })).filter((line) => (line === null || line === void 0 ? void 0 : line.trim().length) > 0);
28
+ if (outputs.length === 0)
29
+ return;
30
+ const mappedOutputs = outputs.map((current) => `${pad}${current}`);
31
+ (0, exports.write)(mappedOutputs.join(node_os_1.EOL));
32
+ };
33
+ exports.printOutput = printOutput;
8
34
  /* c8 ignore stop */
@@ -20,9 +20,14 @@ const node_os_1 = require("os");
20
20
  const format_js_1 = require("./format.js");
21
21
  const hr_js_1 = require("./hr.js");
22
22
  const find_file_js_1 = require("./find-file.js");
23
+ /* c8 ignore next */
23
24
  const each_js_1 = require("../configs/each.js");
25
+ /* c8 ignore next */
26
+ const indentation_js_1 = require("../configs/indentation.js");
24
27
  const object_js_1 = require("../polyfills/object.js");
25
28
  const get_runtime_js_1 = require("./get-runtime.js");
29
+ const logs_js_1 = require("./logs.js");
30
+ const cwd = node_process_1.default.cwd();
26
31
  const parseResultType = (type) => {
27
32
  const recurse = (value) => {
28
33
  if (typeof value === 'undefined')
@@ -50,6 +55,11 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
50
55
  var _a, _b;
51
56
  const isPoku = typeof ((_a = node_process_1.default.env) === null || _a === void 0 ? void 0 : _a.FILE) === 'string' && ((_b = node_process_1.default.env) === null || _b === void 0 ? void 0 : _b.FILE.length) > 0;
52
57
  const FILE = node_process_1.default.env.FILE;
58
+ let preIdentation = '';
59
+ if (indentation_js_1.indentation.hasDescribe || indentation_js_1.indentation.hasTest)
60
+ preIdentation += ' ';
61
+ if (indentation_js_1.indentation.hasIt)
62
+ preIdentation += ' ';
53
63
  try {
54
64
  if (typeof each_js_1.each.before.cb === 'function' && each_js_1.each.before.assert) {
55
65
  const beforeResult = each_js_1.each.before.cb();
@@ -66,16 +76,16 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
66
76
  }
67
77
  if (typeof options.message === 'string') {
68
78
  const message = isPoku
69
- ? `${format_js_1.format.bold(format_js_1.format.success(`✔ ${options.message}`))} ${format_js_1.format.dim(format_js_1.format.success(`› ${FILE}`))}`
70
- : format_js_1.format.bold(format_js_1.format.success(`✔ ${options.message}`));
71
- console.log(message);
79
+ ? `${preIdentation}${format_js_1.format.bold(format_js_1.format.success(`✔ ${options.message}`))} ${format_js_1.format.dim(format_js_1.format.success(`› ${FILE}`))}`
80
+ : `${preIdentation}${format_js_1.format.bold(format_js_1.format.success(`✔ ${options.message}`))}`;
81
+ (0, logs_js_1.write)(message);
72
82
  }
73
83
  }
74
84
  catch (error) {
75
85
  if (error instanceof node_assert_1.default.AssertionError) {
76
86
  const { code, actual, expected, operator } = error;
77
87
  const absoultePath = (0, find_file_js_1.findFile)(error).replace(/file:(\/\/)?/, '');
78
- const file = node_path_1.default.relative(node_path_1.default.resolve(node_process_1.default.cwd()), absoultePath);
88
+ const file = node_path_1.default.relative(node_path_1.default.resolve(cwd), absoultePath);
79
89
  let message = '';
80
90
  if (typeof options.message === 'string')
81
91
  message = options.message;
@@ -87,22 +97,22 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
87
97
  const finalMessage = (message === null || message === void 0 ? void 0 : message.trim().length) > 0
88
98
  ? format_js_1.format.bold(format_js_1.format.fail(`✘ ${message}`))
89
99
  : format_js_1.format.bold(format_js_1.format.fail('✘ No Message'));
90
- console.log(isPoku
91
- ? `${finalMessage} ${format_js_1.format.dim(format_js_1.format.fail(`› ${FILE}`))}`
92
- : finalMessage);
93
- file && console.log(`${format_js_1.format.dim(' File')} ${file}`);
94
- console.log(`${format_js_1.format.dim(' Code')} ${code}`);
95
- console.log(`${format_js_1.format.dim(' Operator')} ${operator}${node_os_1.EOL}`);
100
+ (0, logs_js_1.write)(isPoku
101
+ ? `${preIdentation}${finalMessage} ${format_js_1.format.dim(format_js_1.format.fail(`› ${FILE}`))}`
102
+ : `${preIdentation}${finalMessage}`);
103
+ file && (0, logs_js_1.write)(`${format_js_1.format.dim(`${preIdentation} File`)} ${file}`);
104
+ (0, logs_js_1.write)(`${format_js_1.format.dim(`${preIdentation} Code`)} ${code}`);
105
+ (0, logs_js_1.write)(`${format_js_1.format.dim(`${preIdentation} Operator`)} ${operator}${node_os_1.EOL}`);
96
106
  if (!(options === null || options === void 0 ? void 0 : options.hideDiff)) {
97
107
  const splitActual = (0, exports.parseResultType)(actual).split('\n');
98
108
  const splitExpected = (0, exports.parseResultType)(expected).split('\n');
99
- console.log(format_js_1.format.dim(` ${(options === null || options === void 0 ? void 0 : options.actual) || 'Actual'}:`));
100
- splitActual.forEach((line) => console.log(` ${format_js_1.format.bold(format_js_1.format.fail(line))}`));
101
- console.log(`${node_os_1.EOL} ${format_js_1.format.dim(`${(options === null || options === void 0 ? void 0 : options.expected) || 'Expected'}:`)}`);
102
- splitExpected.forEach((line) => console.log(` ${format_js_1.format.bold(format_js_1.format.success(line))}`));
109
+ (0, logs_js_1.write)(format_js_1.format.dim(`${preIdentation} ${(options === null || options === void 0 ? void 0 : options.actual) || 'Actual'}:`));
110
+ splitActual.forEach((line) => (0, logs_js_1.write)(`${preIdentation} ${format_js_1.format.bold(format_js_1.format.fail(line))}`));
111
+ (0, logs_js_1.write)(`${node_os_1.EOL}${preIdentation} ${format_js_1.format.dim(`${(options === null || options === void 0 ? void 0 : options.expected) || 'Expected'}:`)}`);
112
+ splitExpected.forEach((line) => (0, logs_js_1.write)(`${preIdentation} ${format_js_1.format.bold(format_js_1.format.success(line))}`));
103
113
  }
104
114
  if (options.throw) {
105
- console.log(error);
115
+ console.error(error);
106
116
  (0, hr_js_1.hr)();
107
117
  }
108
118
  node_process_1.default.exit(1);