poku 1.14.0 → 1.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/helpers/hr.js CHANGED
@@ -8,7 +8,7 @@ exports.hr = void 0;
8
8
  const node_os_1 = require("os");
9
9
  const node_process_1 = __importDefault(require("process"));
10
10
  const hr = () => {
11
- const line = '⎯'.repeat(node_process_1.default.stdout.columns - 10);
11
+ const line = '⎯'.repeat(node_process_1.default.stdout.columns - 10 || 40);
12
12
  console.log(`${node_os_1.EOL}\x1b[2m\x1b[90m${line}\x1b[0m${node_os_1.EOL}`);
13
13
  };
14
14
  exports.hr = hr;
@@ -1,3 +1,8 @@
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 printOutput: (options: {
5
+ output: string;
6
+ result: boolean;
7
+ configs?: Configs;
8
+ }) => void;
@@ -1,8 +1,28 @@
1
1
  "use strict";
2
+ /* c8 ignore start */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDebug = exports.isQuiet = void 0;
4
+ exports.printOutput = exports.isDebug = exports.isQuiet = void 0;
5
+ const node_os_1 = require("os");
4
6
  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
7
  exports.isQuiet = isQuiet;
6
8
  const isDebug = (configs) => Boolean(configs === null || configs === void 0 ? void 0 : configs.debug);
7
9
  exports.isDebug = isDebug;
10
+ const printOutput = (options) => {
11
+ const { output, result, configs } = options;
12
+ const debug = (0, exports.isDebug)(configs);
13
+ const pad = (configs === null || configs === void 0 ? void 0 : configs.parallel) ? ' ' : ' ';
14
+ const splittedOutput = output.split(/\n/);
15
+ const outputs = (debug || !result
16
+ ? splittedOutput
17
+ : splittedOutput.filter((current) => {
18
+ if (current.includes('Exited with code'))
19
+ return false;
20
+ return (/u001b\[0m|\n/i.test(JSON.stringify(current)) || current === '');
21
+ })).filter((line) => (line === null || line === void 0 ? void 0 : line.trim().length) > 0);
22
+ if (outputs.length === 0)
23
+ return;
24
+ const mappedOutputs = outputs.map((current) => `${pad}${current}`);
25
+ console.log(mappedOutputs.join(node_os_1.EOL));
26
+ };
27
+ exports.printOutput = printOutput;
8
28
  /* c8 ignore stop */
@@ -21,6 +21,7 @@ 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
23
  const each_js_1 = require("../configs/each.js");
24
+ const describe_js_1 = require("../modules/describe.js");
24
25
  const object_js_1 = require("../polyfills/object.js");
25
26
  const get_runtime_js_1 = require("./get-runtime.js");
26
27
  const parseResultType = (type) => {
@@ -50,6 +51,7 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
50
51
  var _a, _b;
51
52
  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
53
  const FILE = node_process_1.default.env.FILE;
54
+ const preIdentation = describe_js_1.describeCounter > 0 ? ' ' : '';
53
55
  try {
54
56
  if (typeof each_js_1.each.before.cb === 'function' && each_js_1.each.before.assert) {
55
57
  const beforeResult = each_js_1.each.before.cb();
@@ -66,8 +68,8 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
66
68
  }
67
69
  if (typeof options.message === 'string') {
68
70
  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
+ ? `${preIdentation}${format_js_1.format.bold(format_js_1.format.success(`✔ ${options.message}`))} ${format_js_1.format.dim(format_js_1.format.success(`› ${FILE}`))}`
72
+ : `${preIdentation}${format_js_1.format.bold(format_js_1.format.success(`✔ ${options.message}`))}`;
71
73
  console.log(message);
72
74
  }
73
75
  }
@@ -88,18 +90,19 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
88
90
  ? format_js_1.format.bold(format_js_1.format.fail(`✘ ${message}`))
89
91
  : format_js_1.format.bold(format_js_1.format.fail('✘ No Message'));
90
92
  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}`);
93
+ ? `${preIdentation}${finalMessage} ${format_js_1.format.dim(format_js_1.format.fail(`› ${FILE}`))}`
94
+ : `${preIdentation}${finalMessage}`);
95
+ file &&
96
+ console.log(`${format_js_1.format.dim(`${preIdentation} File`)} ${file}`);
97
+ console.log(`${format_js_1.format.dim(`${preIdentation} Code`)} ${code}`);
98
+ console.log(`${format_js_1.format.dim(`${preIdentation} Operator`)} ${operator}${node_os_1.EOL}`);
96
99
  if (!(options === null || options === void 0 ? void 0 : options.hideDiff)) {
97
100
  const splitActual = (0, exports.parseResultType)(actual).split('\n');
98
101
  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))}`));
102
+ console.log(format_js_1.format.dim(`${preIdentation} ${(options === null || options === void 0 ? void 0 : options.actual) || 'Actual'}:`));
103
+ splitActual.forEach((line) => console.log(`${preIdentation} ${format_js_1.format.bold(format_js_1.format.fail(line))}`));
104
+ console.log(`${node_os_1.EOL}${preIdentation} ${format_js_1.format.dim(`${(options === null || options === void 0 ? void 0 : options.expected) || 'Expected'}:`)}`);
105
+ splitExpected.forEach((line) => console.log(`${preIdentation} ${format_js_1.format.bold(format_js_1.format.success(line))}`));
103
106
  }
104
107
  if (options.throw) {
105
108
  console.log(error);
@@ -1,10 +1,7 @@
1
1
  import { backgroundColor } from '../helpers/format.js';
2
+ export declare let describeCounter: number;
2
3
  export type DescribeOptions = {
3
- /**
4
- * Skips a line before to console it.
5
- *
6
- * @default false
7
- */
4
+ /** @deprecated */
8
5
  pad?: boolean;
9
6
  /**
10
7
  * @default "grey"
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.describe = exports.log = void 0;
4
2
  /* c8 ignore start */
5
- const node_os_1 = require("os");
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.describe = exports.log = exports.describeCounter = void 0;
6
5
  const format_js_1 = require("../helpers/format.js");
6
+ exports.describeCounter = 0;
7
7
  /**
8
8
  * By default **Poku** only shows outputs generated from itself.
9
9
  * This helper allows you to use an alternative to `console.log` with **Poku**.
@@ -16,14 +16,15 @@ exports.log = log;
16
16
  * On **Poku**, `describe` is just a pretty `console.log` to title your test suites in the terminal.
17
17
  */
18
18
  const describe = (title, options) => {
19
- const { pad, background, icon } = options || {};
19
+ const { background, icon } = options || {};
20
20
  const message = `${icon || '☰'} ${title}`;
21
- const noBackground = typeof background === 'boolean' && !background;
21
+ const noBackground = !background;
22
+ exports.describeCounter++;
22
23
  if (noBackground) {
23
- console.log(`${pad ? node_os_1.EOL : ''}${format_js_1.format.bold(message)}`);
24
+ console.log(`${format_js_1.format.bold(message)}`);
24
25
  return;
25
26
  }
26
- console.log(`${pad ? node_os_1.EOL : ''}${format_js_1.format.bg(format_js_1.backgroundColor[typeof background === 'string' ? background : 'grey'], message)}`);
27
+ console.log(`${format_js_1.format.bg(format_js_1.backgroundColor[typeof background === 'string' ? background : 'grey'], message)}`);
27
28
  };
28
29
  exports.describe = describe;
29
30
  /* c8 ignore stop */
@@ -15,14 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.runTestFile = void 0;
16
16
  const node_process_1 = __importDefault(require("process"));
17
17
  const node_path_1 = __importDefault(require("path"));
18
- const node_os_1 = require("os");
19
18
  const node_child_process_1 = require("child_process");
20
19
  const indentation_js_1 = require("../configs/indentation.js");
21
20
  const files_js_1 = require("../configs/files.js");
22
21
  const runner_js_1 = require("../helpers/runner.js");
23
22
  const format_js_1 = require("../helpers/format.js");
24
23
  const logs_js_1 = require("../helpers/logs.js");
25
- const remove_repeats_js_1 = require("../helpers/remove-repeats.js");
26
24
  const each_js_1 = require("./each.js");
27
25
  const runTestFile = (filePath, configs) => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
28
26
  var _a, _b, _c;
@@ -40,38 +38,7 @@ const runTestFile = (filePath, configs) => new Promise((resolve) => __awaiter(vo
40
38
  /* c8 ignore stop */
41
39
  const fileRelative = node_path_1.default.relative(node_process_1.default.cwd(), filePath);
42
40
  const showLogs = !(0, logs_js_1.isQuiet)(configs);
43
- const showSuccess = (0, logs_js_1.isDebug)(configs);
44
- const pad = (configs === null || configs === void 0 ? void 0 : configs.parallel) ? ' ' : ' ';
45
41
  let output = '';
46
- /* c8 ignore start */
47
- const log = () => {
48
- const outputs = (0, remove_repeats_js_1.removeConsecutiveRepeats)(showSuccess
49
- ? [output]
50
- : output.split(/(\r\n|\r|\n)/).filter((current) => {
51
- if (current.includes('Exited with code'))
52
- return false;
53
- return (/u001b\[0m|(\r\n|\r|\n)/i.test(JSON.stringify(current)) ||
54
- current === '');
55
- }), /(\r\n|\r|\n)|^$/);
56
- // Remove last EOL
57
- outputs.length > 1 && outputs.pop();
58
- if (!showSuccess &&
59
- /error:/i.test(output) &&
60
- !/error:/i.test(outputs.join()))
61
- Object.assign(outputs, [
62
- ...outputs,
63
- format_js_1.format.bold(format_js_1.format.fail(`✘ External Error ${format_js_1.format.dim(`› ${fileRelative}`)}`)),
64
- format_js_1.format.dim(' For detailed diagnostics:'),
65
- `${format_js_1.format.dim(` CLI ›`)} rerun with the ${format_js_1.format.bold('--debug')} flag enabled.`,
66
- `${format_js_1.format.dim(` API ›`)} set the config option ${format_js_1.format.bold('debug')} to true.`,
67
- `${format_js_1.format.dim(' RUN ›')} ${format_js_1.format.bold(`${runtime === 'tsx' ? 'npx tsx' : runtime}${runtimeArguments.slice(0, -1).join(' ')} ${fileRelative}`)}`,
68
- ]);
69
- /* c8 ignore start */
70
- const mappedOutputs = outputs.map((current) => `${pad}${current}`);
71
- if (outputs.length === 1 && outputs[0] === '')
72
- return;
73
- console.log(showSuccess ? mappedOutputs.join('') : mappedOutputs.join(node_os_1.EOL));
74
- };
75
42
  const stdOut = (data) => {
76
43
  output += String(data);
77
44
  };
@@ -91,21 +58,27 @@ const runTestFile = (filePath, configs) => new Promise((resolve) => __awaiter(vo
91
58
  child.stdout.on('data', stdOut);
92
59
  child.stderr.on('data', stdOut);
93
60
  child.on('close', (code) => __awaiter(void 0, void 0, void 0, function* () {
61
+ const result = code === 0;
94
62
  if (showLogs)
95
- log();
63
+ (0, logs_js_1.printOutput)({
64
+ output,
65
+ result,
66
+ configs,
67
+ });
96
68
  if (!(yield (0, each_js_1.afterEach)(fileRelative, configs)))
97
69
  return false;
98
- const result = code === 0;
99
70
  if (result)
100
71
  files_js_1.fileResults.success.push(fileRelative);
101
72
  else
102
73
  files_js_1.fileResults.fail.push(fileRelative);
103
74
  resolve(result);
104
75
  }));
76
+ /* c8 ignore start */
105
77
  child.on('error', (err) => {
106
78
  console.log(`Failed to start test: ${filePath}`, err);
107
79
  files_js_1.fileResults.fail.push(fileRelative);
108
80
  resolve(false);
109
81
  });
82
+ /* c8 ignore stop */
110
83
  }));
111
84
  exports.runTestFile = runTestFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poku",
3
- "version": "1.14.0",
3
+ "version": "1.14.1",
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": {
@@ -26,7 +26,7 @@
26
26
  "prebuild": "npm run clear",
27
27
  "build": "tsc && tsc -p tsconfig.test.json",
28
28
  "postbuild": "tsx ./tools/compatibility/node.ts && shx cp fixtures/server/package.json ci/fixtures/server/package.json && npm run build:deno && shx chmod +x lib/bin/index.js",
29
- "build:deno": "esbuild src/polyfills/deno.mts --outfile=lib/polyfills/deno.mjs --format=esm && esbuild src/polyfills/deno.mts --outfile=node_modules/poku/lib/polyfills/deno.mjs --format=esm",
29
+ "build:deno": "esbuild src/polyfills/deno.mts --outfile=lib/polyfills/deno.mjs --format=esm",
30
30
  "eslint:checker": "eslint . --ext .js,.ts",
31
31
  "eslint:fix": "eslint . --fix --config ./.eslintrc.json",
32
32
  "lint:checker": "npm run eslint:checker && npm run prettier:checker",
@@ -75,6 +75,7 @@
75
75
  "chai",
76
76
  "jest",
77
77
  "ava",
78
+ "uvu",
78
79
  "tap",
79
80
  "tape",
80
81
  "karma",
@@ -119,9 +120,9 @@
119
120
  ],
120
121
  "type": "commonjs",
121
122
  "devDependencies": {
122
- "@types/node": "^20.12.12",
123
- "@typescript-eslint/eslint-plugin": "^7.11.0",
124
- "@typescript-eslint/parser": "^7.11.0",
123
+ "@types/node": "^20.14.2",
124
+ "@typescript-eslint/eslint-plugin": "^7.12.0",
125
+ "@typescript-eslint/parser": "^7.12.0",
125
126
  "c8": "^9.1.0",
126
127
  "esbuild": "^0.21.4",
127
128
  "eslint": "^8.57.0",
@@ -130,9 +131,9 @@
130
131
  "eslint-plugin-import": "^2.29.1",
131
132
  "eslint-plugin-prettier": "^5.1.3",
132
133
  "packages-update": "^2.0.0",
133
- "prettier": "^3.2.5",
134
+ "prettier": "^3.3.1",
134
135
  "shx": "^0.3.4",
135
- "tsx": "4.11.0",
136
+ "tsx": "4.11.2",
136
137
  "typescript": "^5.4.5"
137
138
  }
138
139
  }
@@ -1 +0,0 @@
1
- export declare const removeConsecutiveRepeats: (arr: string[], specificItem: RegExp) => string[];
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeConsecutiveRepeats = void 0;
4
- /* c8 ignore start */
5
- const removeConsecutiveRepeats = (arr, specificItem) => {
6
- const result = [];
7
- let consecutiveCount = 0;
8
- for (let i = 0; i < arr.length; i++) {
9
- if (specificItem.test(arr[i])) {
10
- consecutiveCount++;
11
- if (consecutiveCount <= 2) {
12
- result.push(arr[i]);
13
- }
14
- }
15
- else {
16
- consecutiveCount = 0;
17
- result.push(arr[i]);
18
- }
19
- // Check if the next item is different or we're at the end of the array
20
- if (i + 1 === arr.length || !specificItem.test(arr[i + 1])) {
21
- // If more than two consecutive, remove them from the result
22
- if (consecutiveCount > 2) {
23
- result.splice(-consecutiveCount);
24
- }
25
- consecutiveCount = 0; // Reset the counter for the next group
26
- }
27
- }
28
- return result;
29
- };
30
- exports.removeConsecutiveRepeats = removeConsecutiveRepeats;
31
- /* c8 ignore stop */