poku 0.1.0 → 1.0.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 (54) hide show
  1. package/README.md +158 -11
  2. package/lib/@types/poku.d.ts +7 -2
  3. package/lib/bin/index.d.ts +2 -0
  4. package/lib/bin/index.js +12 -0
  5. package/lib/helpers/get-arg.d.ts +1 -0
  6. package/lib/helpers/get-arg.js +12 -0
  7. package/lib/index.d.ts +2 -0
  8. package/lib/modules/poku.js +6 -10
  9. package/lib/services/runTests.d.ts +1 -1
  10. package/lib/services/runTests.js +18 -22
  11. package/package.json +22 -4
  12. package/lib/src/@types/code.d.ts +0 -1
  13. package/lib/src/@types/poku.d.ts +0 -36
  14. package/lib/src/helpers/escape-reg-exp.d.ts +0 -1
  15. package/lib/src/helpers/filter.d.ts +0 -1
  16. package/lib/src/helpers/force-array.d.ts +0 -1
  17. package/lib/src/helpers/format.d.ts +0 -8
  18. package/lib/src/helpers/getFiles.d.ts +0 -2
  19. package/lib/src/helpers/hr.d.ts +0 -1
  20. package/lib/src/helpers/indentation.d.ts +0 -4
  21. package/lib/src/helpers/logs.d.ts +0 -4
  22. package/lib/src/helpers/pad.d.ts +0 -4
  23. package/lib/src/helpers/runner.d.ts +0 -1
  24. package/lib/src/index.d.ts +0 -2
  25. package/lib/src/modules/exit.d.ts +0 -2
  26. package/lib/src/modules/poku.d.ts +0 -6
  27. package/lib/src/services/runTestFile.d.ts +0 -2
  28. package/lib/src/services/runTests.d.ts +0 -3
  29. package/lib/test/ci.test.d.ts +0 -1
  30. package/lib/test/compatibility/node-06.test.d.ts +0 -1
  31. package/lib/test/compatibility/node-07.test.d.ts +0 -1
  32. package/lib/test/compatibility/node-08.test.d.ts +0 -1
  33. package/lib/test/compatibility/node-09.test.d.ts +0 -1
  34. package/lib/test/compatibility/node-10.test.d.ts +0 -1
  35. package/lib/test/compatibility/node-11.test.d.ts +0 -1
  36. package/lib/test/compatibility/node-12.test.d.ts +0 -1
  37. package/lib/test/compatibility/node-13.test.d.ts +0 -1
  38. package/lib/test/compatibility/node-14.test.d.ts +0 -1
  39. package/lib/test/compatibility/node-15.test.d.ts +0 -1
  40. package/lib/test/compatibility/node-16.test.d.ts +0 -1
  41. package/lib/test/compatibility/node-17.test.d.ts +0 -1
  42. package/lib/test/compatibility/node-18.test.d.ts +0 -1
  43. package/lib/test/compatibility/node-19.test.d.ts +0 -1
  44. package/lib/test/compatibility/node-20.test.d.ts +0 -1
  45. package/lib/test/compatibility/node-21.test.d.ts +0 -1
  46. package/lib/test/fixtures/fail/exit.test.d.ts +0 -0
  47. package/lib/test/fixtures/success/exit.test.d.ts +0 -0
  48. package/lib/test/helpers/check-node.test.d.ts +0 -1
  49. package/lib/test/integration/code.test.d.ts +0 -1
  50. package/lib/test/integration/import.test.d.ts +0 -1
  51. package/lib/test/run.test.d.ts +0 -1
  52. package/lib/test/unit/pad.test.d.ts +0 -1
  53. package/lib/test/unit/runTestFile.test.d.ts +0 -1
  54. package/lib/test/unit/runTests.test.d.ts +0 -1
package/README.md CHANGED
@@ -1,19 +1,41 @@
1
+ [npm-image]: https://img.shields.io/npm/v/poku.svg?color=f78fb3
2
+ [npm-url]: https://npmjs.org/package/poku
3
+ [ci-url]: https://github.com/wellwelwel/poku/actions/workflows/ci.yml?query=branch%3Amain
4
+ [ci-image]: https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci.yml?event=push&style=flat&label=ci&branch=main&color=badc58
5
+ [license-url]: https://github.com/wellwelwel/poku/blob/main/LICENSE
6
+ [license-image]: https://img.shields.io/npm/l/poku.svg?maxAge=2592000&color=3dc1d3
7
+ [node-version-image]: https://img.shields.io/node/v/poku.svg?color=ffb142
8
+ [node-version-url]: https://nodejs.org/en/download
9
+
1
10
  # Poku
2
11
 
3
12
  <img align="right" width="128" height="128" alt="Logo" src=".github/assets/readme/poku.svg">
4
13
 
5
- 🖇️ A flexible and user-friendly **Test Runner** which allows parallel runs and high isolation level.
14
+ 🖇️ A flexible and easy-to-use **Test Runner** for parallel or sequential runs and high isolation level.
6
15
 
7
- > - **Poku** is designed to be highly intuitive.<br />
8
- > - Compatible with **ESM** and **CJS**, **Node.js** and **TypeScript** (_no-build_).<br />
9
- > - From **Node.js 6** to the **Latest** release.<br />
10
- > - Totally dependency-free.
16
+ [![NPM Version][npm-image]][npm-url]
17
+ [![Node.js Version][node-version-image]][node-version-url]
18
+ [![GitHub Workflow Status (with event)][ci-image]][ci-url]
19
+ [![License][license-image]][license-url]
11
20
 
12
21
  ---
13
22
 
14
- ## In progress
23
+ ## Why Poku?
24
+
25
+ 🪄 Runs test files in an individual process, shows progress and exits.<br/>
26
+
27
+ - **Poku** is designed to be highly intuitive.<br />
28
+ - Supports **Node.js 6+** (_ESM_ and _CJS_), **TypeScript** (_no need to build_) and **Coverage** tools.<br />
29
+ - **Poku** dive to the deepest depths to find tests in the specified directories.
30
+ - No constraints or rules, code in your own signature style.
31
+ - Zero configurations, except you want.
32
+ - Allows both **in-code** and **CLI** usage.
33
+
34
+ ---
15
35
 
16
- 🧑🏻‍🔧 Soon releasing version `1.x`.
36
+ - Totally **dependency-free**.
37
+ - **Compatibility:** **Poku** is tested across all **Node 6+** versions.
38
+ - **Poku** uses itself to test its own tests using `process.exit` at several depths on the same process node.
17
39
 
18
40
  ---
19
41
 
@@ -25,22 +47,147 @@ npm install --save-dev poku
25
47
 
26
48
  ---
27
49
 
28
- ## Usage
50
+ ## Basic Usage
51
+
52
+ ## In-code
29
53
 
30
54
  ```ts
31
55
  import { poku } from 'poku';
32
56
 
33
- await poku(['./test/unit/']);
57
+ await poku(['./a', './b']);
58
+ ```
59
+
60
+ ### CLI
34
61
 
35
- // 🧑🏻‍🔧 Soon documenting all options and Poku's usage variations.
62
+ ```bash
63
+ npx poku --include='./a,./b'
36
64
  ```
37
65
 
38
66
  ---
39
67
 
40
- ## TypeScript
68
+ ### TypeScript
41
69
 
42
70
  To run your tests without compile, just install `tsx` and it's done:
43
71
 
44
72
  ```bash
45
73
  npm install --save-dev tsx
46
74
  ```
75
+
76
+ ---
77
+
78
+ ## Documentation
79
+
80
+ ### `poku`
81
+
82
+ #### Include directories
83
+
84
+ ```ts
85
+ poku('./targetDir');
86
+ ```
87
+
88
+ ```ts
89
+ poku(['./targetDirA', './targetDirB']);
90
+ ```
91
+
92
+ ```bash
93
+ npx poku --include='./targetDir'
94
+ ```
95
+
96
+ ```bash
97
+ npx poku --include='./targetDirA,./targetDirB'
98
+ ```
99
+
100
+ ---
101
+
102
+ #### `filter`
103
+
104
+ > Filter by path using **Regex** to match only the files that should be performed.
105
+
106
+ - **in-code**
107
+
108
+ ```ts
109
+ /**
110
+ * @default
111
+ *
112
+ * Testing all `*.test.*` files.
113
+ */
114
+
115
+ poku(['...'], {
116
+ filter: /\.test\./,
117
+ });
118
+ ```
119
+
120
+ ```ts
121
+ /**
122
+ * Testing all `ts`, `js`, `mts` and `mjs` files
123
+ */
124
+
125
+ poku(['...'], {
126
+ filter: /\.(m)?(j|t)?s$/,
127
+ // filter: /\.(js|ts|mjs|mts)$/,
128
+ });
129
+ ```
130
+
131
+ - **CLI**
132
+
133
+ ```bash
134
+ # Testing only a specific file
135
+
136
+ npx poku --include='...' --filter='some-file'
137
+ ```
138
+
139
+ ```bash
140
+ # Testing only paths that contains "unit"
141
+
142
+ npx poku --include='...' --filter='unit'
143
+ ```
144
+
145
+ - **Environment Variable**
146
+
147
+ > By using `FILTER` from **Environment Variable**, it will overwrite the `filter` option.
148
+
149
+ ```bash
150
+ # Testing only a specific file
151
+
152
+ FILTER='some-file' npx poku --include='...'
153
+ ```
154
+
155
+ ```bash
156
+ # Testing only paths that contains "unit"
157
+
158
+ FILTER='unit' npx poku --include='...'
159
+ ```
160
+
161
+ ---
162
+
163
+ #### `parallel`
164
+
165
+ Determines the mode of test execution across **parallelism** or **sequential** modes.
166
+
167
+ ```ts
168
+ /**
169
+ * @default
170
+ *
171
+ * Sequential mode
172
+ */
173
+
174
+ poku(['...'], {
175
+ parallel: false,
176
+ });
177
+ ```
178
+
179
+ ```ts
180
+ /**
181
+ * Parallel mode
182
+ */
183
+
184
+ poku(['...'], {
185
+ parallel: true,
186
+ });
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Documentation in Progress
192
+
193
+ > 🧑🏻‍🎓 Soon documenting all options and **Poku**'s usage variations.
@@ -21,16 +21,21 @@ export type Configs = {
21
21
  fail?: boolean;
22
22
  };
23
23
  /**
24
- * This option overwrites all `log` settings
24
+ * This option overwrites all `log` settings.
25
25
  *
26
26
  * @default false
27
27
  */
28
28
  quiet?: boolean;
29
29
  /**
30
- * Filter by path to match only the files that should be performed
30
+ * Filter by path to match only the files that should be performed.
31
31
  *
32
32
  * @default /\.test\./i
33
33
  */
34
34
  filter?: RegExp;
35
+ /**
36
+ * Determines the mode of test execution.
37
+ *
38
+ * @default false
39
+ */
35
40
  parallel?: boolean;
36
41
  };
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const escape_reg_exp_js_1 = require("../helpers/escape-reg-exp.js");
5
+ const get_arg_js_1 = require("../helpers/get-arg.js");
6
+ 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(',')) || [];
10
+ (0, index_js_1.poku)(dirs, {
11
+ filter: rawFilter ? new RegExp((0, escape_reg_exp_js_1.escapeRegExp)(rawFilter)) : undefined,
12
+ });
@@ -0,0 +1 @@
1
+ export declare const getArg: (arg: string) => string | undefined;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getArg = void 0;
4
+ const [, , ...args] = process.argv;
5
+ const getArg = (arg) => {
6
+ var _a;
7
+ const getArg = args.find((a) => a.startsWith(`--${arg}=`));
8
+ if (getArg)
9
+ return ((_a = getArg.split('=')) === null || _a === void 0 ? void 0 : _a[1]) || undefined;
10
+ return undefined;
11
+ };
12
+ exports.getArg = getArg;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,4 @@
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';
@@ -18,17 +18,13 @@ function poku(targetDirs, configs) {
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
- for (const dir of dirs) {
22
- (0, runTests_js_1.runTestsParallel)(dir, configs).then((result) => {
23
- if (!result)
24
- code = 1;
25
- });
21
+ const results = yield Promise.all(dirs.map((dir) => (0, runTests_js_1.runTestsParallel)(dir, configs)));
22
+ if (results.some((result) => !result)) {
23
+ code = 1;
26
24
  }
27
- process.on('beforeExit', () => {
28
- if (configs === null || configs === void 0 ? void 0 : configs.noExit)
29
- return code;
30
- (0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
31
- });
25
+ if (configs === null || configs === void 0 ? void 0 : configs.noExit)
26
+ return code;
27
+ (0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
32
28
  return;
33
29
  }
34
30
  for (const dir of dirs) {
@@ -1,3 +1,3 @@
1
1
  import { Configs } from '../@types/poku.js';
2
2
  export declare const runTests: (dir: string, configs?: Configs) => Promise<boolean>;
3
- export declare const runTestsParallel: (dir: string, configs?: Configs) => Promise<unknown>;
3
+ export declare const runTestsParallel: (dir: string, configs?: Configs) => Promise<boolean>;
@@ -55,31 +55,27 @@ const runTests = (dir, configs) => __awaiter(void 0, void 0, void 0, function* (
55
55
  return passed;
56
56
  });
57
57
  exports.runTests = runTests;
58
- const runTestsParallel = (dir, configs) => {
58
+ const runTestsParallel = (dir, configs) => __awaiter(void 0, void 0, void 0, function* () {
59
59
  const cwd = process.cwd();
60
60
  const testDir = path_1.default.join(cwd, dir);
61
61
  const files = (0, getFiles_js_1.getFiles)(testDir, undefined, configs);
62
62
  const showLogs = !(0, logs_js_1.isQuiet)(configs);
63
- let passed = true;
64
- return new Promise((resolve) => {
65
- for (let i = 0; i < files.length; i++) {
66
- const filePath = files[i];
67
- const fileRelative = path_1.default.relative(cwd, filePath);
68
- (0, runTestFile_js_1.runTestFile)(filePath, configs).then((testPassed) => {
69
- const command = `${(0, runner_js_1.runner)(fileRelative)} ${fileRelative}`;
70
- const log = command;
71
- if (testPassed) {
72
- showLogs &&
73
- console.log(`${indentation_js_1.indentation.test}${format_js_1.format.success('✔')} ${log}`);
74
- }
75
- else {
76
- showLogs &&
77
- console.log(`${indentation_js_1.indentation.test}${format_js_1.format.fail('✖')} ${log}`);
78
- passed = false;
79
- }
80
- });
81
- resolve(passed);
63
+ const promises = files.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const fileRelative = path_1.default.relative(cwd, filePath);
65
+ const testPassed = yield (0, runTestFile_js_1.runTestFile)(filePath, configs);
66
+ const command = `${(0, runner_js_1.runner)(fileRelative)} ${fileRelative}`;
67
+ if (testPassed) {
68
+ showLogs &&
69
+ console.log(`${indentation_js_1.indentation.test}${format_js_1.format.success('✔')} ${command}`);
82
70
  }
83
- });
84
- };
71
+ else {
72
+ showLogs &&
73
+ console.log(`${indentation_js_1.indentation.test}${format_js_1.format.fail('✖')} ${command}`);
74
+ return false;
75
+ }
76
+ return true;
77
+ }));
78
+ const results = yield Promise.all(promises);
79
+ return results.every((result) => result);
80
+ });
85
81
  exports.runTestsParallel = runTestsParallel;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poku",
3
- "version": "0.1.0",
4
- "description": "🐷 This is Poku",
3
+ "version": "1.0.0",
4
+ "description": "🐷 A flexible and easy-to-use Test Runner for parallel or sequential runs and high isolation level",
5
5
  "main": "./lib/index.js",
6
6
  "scripts": {
7
7
  "test": "npx tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
@@ -12,6 +12,7 @@
12
12
  "update": "npx npu; npm run init",
13
13
  "prebuild": "rm -rf ./lib",
14
14
  "build": "npx tsc",
15
+ "postbuild": "npm audit",
15
16
  "eslint:checker": "npx eslint . --ext .js,.ts",
16
17
  "eslint:fix": "npx eslint . --fix --config ./.eslintrc.json",
17
18
  "prettier:checker": "npx prettier --check .",
@@ -22,17 +23,34 @@
22
23
  "type": "git",
23
24
  "url": "git+https://github.com/wellwelwel/poku.git"
24
25
  },
26
+ "bin": {
27
+ "poku": "./lib/bin/index.js"
28
+ },
25
29
  "keywords": [
26
30
  "test",
31
+ "testing",
27
32
  "runner",
28
- "isolate"
33
+ "run",
34
+ "isolate",
35
+ "isolation",
36
+ "concurrent",
37
+ "concurrency",
38
+ "parallelism",
39
+ "parallel",
40
+ "sequential",
41
+ "unit",
42
+ "integration",
43
+ "typescript",
44
+ "filter",
45
+ "queue",
46
+ "queuing"
29
47
  ],
30
48
  "author": "https://github.com/wellwelwel",
31
49
  "bugs": {
32
50
  "url": "https://github.com/wellwelwel/poku/issues"
33
51
  },
34
52
  "engines": {
35
- "node": ">=6.x"
53
+ "node": ">=6.0.0"
36
54
  },
37
55
  "files": [
38
56
  "lib"
@@ -1 +0,0 @@
1
- export type Code = 0 | 1;
@@ -1,36 +0,0 @@
1
- export type Configs = {
2
- /**
3
- * By setting `true`, **Poku** won't exit the process and will return the exit code (`0` or `1`).
4
- *
5
- * You can combine this option with **Poku**'s `exit` method or just use the result, for example, in `process.exit(code)`.
6
- *
7
- * @default false
8
- */
9
- noExit?: boolean;
10
- /**
11
- * Customize `stdout` options.
12
- */
13
- log?: {
14
- /**
15
- * @default false
16
- */
17
- success?: boolean;
18
- /**
19
- * @default true
20
- */
21
- fail?: boolean;
22
- };
23
- /**
24
- * This option overwrites all `log` settings
25
- *
26
- * @default false
27
- */
28
- 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
- parallel?: boolean;
36
- };
@@ -1 +0,0 @@
1
- export declare const escapeRegExp: (string: string) => string;
@@ -1 +0,0 @@
1
- export declare const filter: RegExp | null;
@@ -1 +0,0 @@
1
- export declare const forceArray: <T>(input: T | T[]) => T[];
@@ -1,8 +0,0 @@
1
- export declare const format: {
2
- counter: (current: number, total: number, pad?: string) => string;
3
- bold: (value: string) => string;
4
- underline: (value: string) => string;
5
- info: (value: string) => string;
6
- success: (value: string) => string;
7
- fail: (value: string) => string;
8
- };
@@ -1,2 +0,0 @@
1
- import { Configs } from '../@types/poku.js';
2
- export declare const getFiles: (dirPath: string, files?: string[], configs?: Configs) => string[];
@@ -1 +0,0 @@
1
- export declare const hr: () => void;
@@ -1,4 +0,0 @@
1
- export declare const indentation: {
2
- test: string;
3
- stdio: string;
4
- };
@@ -1,4 +0,0 @@
1
- import { Configs } from '../@types/poku.js';
2
- export declare const isQuiet: (configs?: Configs) => boolean;
3
- export declare const showSuccesses: (configs?: Configs) => boolean;
4
- export declare const showFailures: (configs?: Configs) => boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * Custom implementations of `padStart` for compatibility with Node.js version 6.
3
- */
4
- export declare const padStart: (str: string, targetLength: number, padString: string) => string;
@@ -1 +0,0 @@
1
- export declare const runner: (filename: string) => "tsx" | "node";
@@ -1,2 +0,0 @@
1
- export { poku } from './modules/poku.js';
2
- export { exit } from './modules/exit.js';
@@ -1,2 +0,0 @@
1
- import { Code } from '../@types/code.js';
2
- export declare const exit: (code: Code, quiet?: boolean) => never;
@@ -1,6 +0,0 @@
1
- import { Code } from '../@types/code.js';
2
- import { Configs } from '../@types/poku.js';
3
- export declare function poku(targetDirs: string | string[], configs?: Configs): Promise<void>;
4
- export declare function poku(targetDirs: string | string[], configs: Configs & {
5
- noExit: true;
6
- }): Promise<Code>;
@@ -1,2 +0,0 @@
1
- import { Configs } from '../@types/poku.js';
2
- export declare const runTestFile: (filePath: string, configs?: Configs) => Promise<boolean>;
@@ -1,3 +0,0 @@
1
- import { Configs } from '../@types/poku.js';
2
- export declare const runTests: (dir: string, configs?: Configs) => Promise<boolean>;
3
- export declare const runTestsParallel: (dir: string, configs?: Configs) => Promise<unknown>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
File without changes
File without changes
@@ -1 +0,0 @@
1
- export declare const checkNode: (version: number) => Promise<number>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};