poku 1.9.4 → 1.10.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.
@@ -50,6 +50,12 @@ export type Configs = {
50
50
  * @default 'node'
51
51
  */
52
52
  platform?: 'node' | 'bun' | 'deno';
53
+ /**
54
+ * Stops the tests at the first failure.
55
+ *
56
+ * @default false
57
+ */
58
+ failFast?: boolean;
53
59
  /**
54
60
  * You can use this option to run a **callback** or a **file** before each test file on your suite.
55
61
  *
package/lib/bin/index.js CHANGED
@@ -17,6 +17,7 @@ const exclude = (0, get_arg_js_1.getArg)('exclude');
17
17
  const parallel = (0, get_arg_js_1.hasArg)('parallel');
18
18
  const quiet = (0, get_arg_js_1.hasArg)('quiet');
19
19
  const debug = (0, get_arg_js_1.hasArg)('debug');
20
+ const failFast = (0, get_arg_js_1.hasArg)('fail-fast');
20
21
  if ((0, get_arg_js_1.hasArg)('log-success'))
21
22
  console.log(`The flag ${format_js_1.format.bold('--log-success')} is deprecated. Use ${format_js_1.format.bold('--debug')} instead.`);
22
23
  (0, index_js_1.poku)(dirs, {
@@ -26,5 +27,6 @@ if ((0, get_arg_js_1.hasArg)('log-success'))
26
27
  parallel,
27
28
  quiet,
28
29
  debug,
30
+ failFast,
29
31
  });
30
32
  /* c8 ignore stop */
@@ -13,15 +13,14 @@ const exit = (code, quiet) => {
13
13
  const isPoku = run_tests_js_1.results.success > 0 || run_tests_js_1.results.fail > 0;
14
14
  !quiet &&
15
15
  node_process_1.default.on('exit', (code) => {
16
- isPoku &&
16
+ if (isPoku) {
17
+ (0, hr_js_1.hr)();
17
18
  console.log(format_js_1.format.bg(42, `PASS › ${run_tests_js_1.results.success}`), format_js_1.format.bg(run_tests_js_1.results.fail === 0 ? 100 : 41, `FAIL › ${run_tests_js_1.results.fail}`));
18
- isPoku && (0, hr_js_1.hr)();
19
+ (0, hr_js_1.hr)();
20
+ }
19
21
  console.log(`${format_js_1.format.dim('Exited with code')} ${format_js_1.format.bold(format_js_1.format === null || format_js_1.format === void 0 ? void 0 : format_js_1.format[code === 0 ? 'success' : 'fail'](String(code)))}`);
20
22
  });
21
- isPoku && !quiet && (0, hr_js_1.hr)();
22
- if (code !== 0)
23
- node_process_1.default.exit(1);
24
- node_process_1.default.exit(0);
23
+ node_process_1.default.exit(code === 0 ? 0 : 1);
25
24
  };
26
25
  exports.exit = exit;
27
26
  node_process_1.default.on('unhandledRejection', (reason) => {
@@ -29,33 +29,47 @@ function poku(targetPaths, configs) {
29
29
  const prepareDirs = (0, force_array_js_1.forceArray)(targetPaths);
30
30
  const dirs = prepareDirs.length > 0 ? prepareDirs : ['./'];
31
31
  const showLogs = !(0, logs_js_1.isQuiet)(configs);
32
- if (configs === null || configs === void 0 ? void 0 : configs.parallel) {
33
- if (showLogs) {
34
- (0, hr_js_1.hr)();
35
- console.log(`${format_js_1.format.bold('Running the Test Suite in Parallel')}${node_os_1.EOL}`);
32
+ // Sequential
33
+ if (!(configs === null || configs === void 0 ? void 0 : configs.parallel)) {
34
+ for (const dir of dirs) {
35
+ const result = yield (0, run_tests_js_1.runTests)(dir, configs);
36
+ if (!result) {
37
+ code = 1;
38
+ if (configs === null || configs === void 0 ? void 0 : configs.failFast)
39
+ break;
40
+ }
36
41
  }
37
- const concurrency = yield Promise.all(dirs.map((dir) => (0, run_tests_js_1.runTestsParallel)(dir, configs)));
38
- if (concurrency.some((result) => !result))
39
- code = 1;
40
- showLogs && (0, hr_js_1.hr)();
41
- if (showLogs && run_test_file_js_1.fileResults.success.length > 0)
42
- console.log(run_test_file_js_1.fileResults.success
43
- .map((current) => `${indentation_js_1.indentation.test}${format_js_1.format.success('✔')} ${format_js_1.format.dim(current)}`)
44
- .join(node_os_1.EOL));
45
- if (showLogs && run_test_file_js_1.fileResults.fail.length > 0)
46
- console.log(run_test_file_js_1.fileResults.fail
47
- .map((current) => `${indentation_js_1.indentation.test}${format_js_1.format.fail('✘')} ${current}`)
48
- .join(node_os_1.EOL));
49
42
  if (configs === null || configs === void 0 ? void 0 : configs.noExit)
50
43
  return code;
51
44
  (0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
52
45
  return;
53
46
  }
54
- for (const dir of dirs) {
55
- const result = yield (0, run_tests_js_1.runTests)(dir, configs);
56
- if (!result)
47
+ // Parallel
48
+ if (showLogs) {
49
+ (0, hr_js_1.hr)();
50
+ console.log(`${format_js_1.format.bold('Running the Test Suite in Parallel')}${node_os_1.EOL}`);
51
+ }
52
+ try {
53
+ const promises = dirs.map((dir) => __awaiter(this, void 0, void 0, function* () {
54
+ const result = yield (0, run_tests_js_1.runTestsParallel)(dir, configs);
55
+ if (!result && (configs === null || configs === void 0 ? void 0 : configs.failFast))
56
+ throw '';
57
+ return result;
58
+ }));
59
+ const concurrency = yield Promise.all(promises);
60
+ if (concurrency.some((result) => !result))
57
61
  code = 1;
58
62
  }
63
+ catch (_a) { }
64
+ showLogs && (0, hr_js_1.hr)();
65
+ if (showLogs && run_test_file_js_1.fileResults.success.length > 0)
66
+ console.log(run_test_file_js_1.fileResults.success
67
+ .map((current) => `${indentation_js_1.indentation.test}${format_js_1.format.success('✔')} ${format_js_1.format.dim(current)}`)
68
+ .join(node_os_1.EOL));
69
+ if (showLogs && run_test_file_js_1.fileResults.fail.length > 0)
70
+ console.log(run_test_file_js_1.fileResults.fail
71
+ .map((current) => `${indentation_js_1.indentation.test}${format_js_1.format.fail('✘')} ${current}`)
72
+ .join(node_os_1.EOL));
59
73
  if (configs === null || configs === void 0 ? void 0 : configs.noExit)
60
74
  return code;
61
75
  (0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
@@ -59,6 +59,11 @@ const runTests = (dir, configs) => __awaiter(void 0, void 0, void 0, function* (
59
59
  showLogs &&
60
60
  console.log(`${indentation_js_1.indentation.test}${format_js_1.format.fail('✘')} ${log}`, nextLine);
61
61
  passed = false;
62
+ if (configs === null || configs === void 0 ? void 0 : configs.failFast) {
63
+ (0, hr_js_1.hr)();
64
+ console.log(` ${format_js_1.format.fail('ℹ')} ${format_js_1.format.bold('fail-fast')} is enabled`);
65
+ break;
66
+ }
62
67
  }
63
68
  }
64
69
  return passed;
@@ -68,16 +73,27 @@ const runTestsParallel = (dir, configs) => __awaiter(void 0, void 0, void 0, fun
68
73
  const cwd = node_process_1.default.cwd();
69
74
  const testDir = node_path_1.default.join(cwd, dir);
70
75
  const files = (0, list_files_js_1.isFile)(dir) ? [dir] : (0, list_files_js_1.listFiles)(testDir, undefined, configs);
71
- const promises = files.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
72
- const testPassed = yield (0, run_test_file_js_1.runTestFile)(filePath, configs);
73
- if (!testPassed) {
74
- ++exports.results.fail;
75
- return false;
76
- }
77
- ++exports.results.success;
78
- return true;
79
- }));
80
- const concurrency = yield Promise.all(promises);
81
- return concurrency.every((result) => result);
76
+ try {
77
+ const promises = files.map((filePath) => __awaiter(void 0, void 0, void 0, function* () {
78
+ if ((configs === null || configs === void 0 ? void 0 : configs.failFast) && exports.results.fail > 0)
79
+ return;
80
+ const testPassed = yield (0, run_test_file_js_1.runTestFile)(filePath, configs);
81
+ if (!testPassed) {
82
+ ++exports.results.fail;
83
+ if (configs === null || configs === void 0 ? void 0 : configs.failFast)
84
+ throw ` ${format_js_1.format.fail('ℹ')} ${format_js_1.format.bold('fail-fast')} is enabled`;
85
+ return false;
86
+ }
87
+ ++exports.results.success;
88
+ return true;
89
+ }));
90
+ const concurrency = yield Promise.all(promises);
91
+ return concurrency.every((result) => result);
92
+ }
93
+ catch (error) {
94
+ (0, hr_js_1.hr)();
95
+ console.log(error);
96
+ return false;
97
+ }
82
98
  });
83
99
  exports.runTestsParallel = runTestsParallel;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "poku",
3
- "version": "1.9.4",
3
+ "version": "1.10.0",
4
4
  "description": "🐷 Poku makes testing easy for Node.js, Bun & Deno at the same time.",
5
5
  "main": "./lib/index.js",
6
6
  "scripts": {
7
- "test": "tsx src/bin/index.ts --parallel --debug test/unit,test/integration,test/e2e",
7
+ "test": "tsx src/bin/index.ts --parallel --debug --include=\"test/unit,test/integration,test/e2e\"",
8
8
  "test:c8": "c8 npm run test",
9
9
  "test:ci": "tsx ./test/ci.test.ts",
10
10
  "test:node": "FILTER='node-' npm run test:ci",
@@ -22,7 +22,7 @@
22
22
  "lint:fix": "npm run eslint:fix && npm run prettier:fix",
23
23
  "prettier:checker": "prettier --check .",
24
24
  "prettier:fix": "prettier --write .github/workflows/*.yml .",
25
- "update": "npu && npm i && npm run lint:fix && npm audit"
25
+ "update": "npu --minor && npm i && npm run lint:fix && npm audit"
26
26
  },
27
27
  "license": "MIT",
28
28
  "repository": {
@@ -102,9 +102,9 @@
102
102
  ],
103
103
  "type": "commonjs",
104
104
  "devDependencies": {
105
- "@types/node": "^20.12.7",
106
- "@typescript-eslint/eslint-plugin": "^7.7.1",
107
- "@typescript-eslint/parser": "^7.7.1",
105
+ "@types/node": "^20.12.11",
106
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
107
+ "@typescript-eslint/parser": "^7.8.0",
108
108
  "c8": "^9.1.0",
109
109
  "eslint": "^8.57.0",
110
110
  "eslint-config-prettier": "^9.1.0",