poku 1.7.0 → 1.8.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/README.md CHANGED
@@ -167,6 +167,25 @@ deno run npm:poku
167
167
 
168
168
  ---
169
169
 
170
+ ## Available Methods
171
+
172
+ ### Essentials
173
+
174
+ - `poku` (_test runner_)
175
+ - `assert` and `assertPromise` (_test assertion_)
176
+
177
+ ### Helpers
178
+
179
+ - `beforeEach` and `afterEach`
180
+ - `test`
181
+ - `describe` and `log`
182
+ - `listFiles`
183
+ - `exit`
184
+
185
+ [**See the complete documentation**](https://poku.io/docs).
186
+
187
+ ---
188
+
170
189
  ## Overview
171
190
 
172
191
  ### `poku`
@@ -5,6 +5,8 @@ export type Control = {
5
5
  };
6
6
  export type EachConfigs = {
7
7
  status: boolean;
8
+ assert?: boolean;
9
+ test?: boolean;
8
10
  cb?: () => unknown | Promise<unknown>;
9
11
  };
10
12
  export declare const each: {
@@ -5,9 +5,13 @@ exports.each = {
5
5
  before: {
6
6
  status: true,
7
7
  cb: undefined,
8
+ assert: true,
9
+ test: true,
8
10
  },
9
11
  after: {
10
12
  status: true,
11
13
  cb: undefined,
14
+ assert: true,
15
+ test: true,
12
16
  },
13
17
  };
@@ -26,7 +26,7 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
26
26
  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;
27
27
  const FILE = node_process_1.default.env.FILE;
28
28
  try {
29
- if (typeof each_js_1.each.before.cb === 'function') {
29
+ if (typeof each_js_1.each.before.cb === 'function' && each_js_1.each.before.assert) {
30
30
  const beforeResult = each_js_1.each.before.cb();
31
31
  if (beforeResult instanceof Promise)
32
32
  yield beforeResult;
@@ -34,7 +34,7 @@ const parseAssertion = (cb, options) => __awaiter(void 0, void 0, void 0, functi
34
34
  const cbResult = cb();
35
35
  if (cbResult instanceof Promise)
36
36
  yield cbResult;
37
- if (typeof each_js_1.each.after.cb === 'function') {
37
+ if (typeof each_js_1.each.after.cb === 'function' && each_js_1.each.after.assert) {
38
38
  const afterResult = each_js_1.each.after.cb();
39
39
  if (afterResult instanceof Promise)
40
40
  yield afterResult;
package/lib/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { describe, log } from './modules/describe.js';
5
5
  export { assertPromise } from './modules/assert-promise.js';
6
6
  export { beforeEach, afterEach } from './modules/each.js';
7
7
  export { publicListFiles as listFiles } from './modules/list-files.js';
8
+ export { test } from './modules/test.js';
8
9
  export type { Code } from './@types/code.ts';
9
10
  export type { Configs } from './@types/poku.ts';
10
11
  export type { Configs as ListFilesConfigs } from './@types/list-files.ts';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listFiles = exports.afterEach = exports.beforeEach = exports.assertPromise = exports.log = exports.describe = exports.assert = exports.exit = exports.poku = void 0;
3
+ exports.test = exports.listFiles = exports.afterEach = exports.beforeEach = exports.assertPromise = exports.log = exports.describe = exports.assert = 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");
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "beforeEach", { enumerable: true, get: function (
17
17
  Object.defineProperty(exports, "afterEach", { enumerable: true, get: function () { return each_js_1.afterEach; } });
18
18
  var list_files_js_1 = require("./modules/list-files.js");
19
19
  Object.defineProperty(exports, "listFiles", { enumerable: true, get: function () { return list_files_js_1.publicListFiles; } });
20
+ var test_js_1 = require("./modules/test.js");
21
+ Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_js_1.test; } });
@@ -1,6 +1,8 @@
1
1
  import { Control } from '../configs/each.js';
2
2
  type EachOptions = {
3
3
  immediate?: boolean;
4
+ test?: boolean;
5
+ assert?: boolean;
4
6
  };
5
7
  /**
6
8
  * - ✅ Handling **global** and **external** services (_preparing a database, for example_)
@@ -45,5 +47,5 @@ export declare const beforeEach: (callback: () => unknown, options?: EachOptions
45
47
  * after.reset();
46
48
  * ```
47
49
  */
48
- export declare const afterEach: (callback: () => unknown) => Control;
50
+ export declare const afterEach: (callback: () => unknown, options: Omit<EachOptions, 'immediate'>) => Control;
49
51
  export {};
@@ -24,6 +24,9 @@ const each_js_1 = require("../configs/each.js");
24
24
  * ```
25
25
  */
26
26
  const beforeEach = (callback, options) => {
27
+ each_js_1.each.before.test = typeof (options === null || options === void 0 ? void 0 : options.test) === 'boolean' ? options.test : true;
28
+ each_js_1.each.before.assert =
29
+ typeof (options === null || options === void 0 ? void 0 : options.assert) === 'boolean' ? options.assert : true;
27
30
  (options === null || options === void 0 ? void 0 : options.immediate) && callback();
28
31
  each_js_1.each.before.cb = () => {
29
32
  if (each_js_1.each.before.status)
@@ -62,7 +65,10 @@ exports.beforeEach = beforeEach;
62
65
  * after.reset();
63
66
  * ```
64
67
  */
65
- const afterEach = (callback) => {
68
+ const afterEach = (callback, options) => {
69
+ each_js_1.each.after.test = typeof (options === null || options === void 0 ? void 0 : options.test) === 'boolean' ? options.test : true;
70
+ each_js_1.each.after.assert =
71
+ typeof (options === null || options === void 0 ? void 0 : options.assert) === 'boolean' ? options.assert : true;
66
72
  each_js_1.each.after.cb = () => {
67
73
  if (each_js_1.each.after.status)
68
74
  callback();
@@ -12,7 +12,7 @@ const sanitizePath = (input, ensureTarget) => {
12
12
  const sanitizedPath = input
13
13
  .replace(/[/\\]+/g, node_path_1.default.sep) // adapting slashes according to OS
14
14
  .replace(/(\.\.(\/|\\|$))+/g, '') // ensure the current path level
15
- .replace(/[<>:|^?*]+/g, ''); // removing unusual path characters
15
+ .replace(/[<>|^?*]+/g, ''); // removing unusual path characters
16
16
  // Preventing absolute path access
17
17
  return ensureTarget ? sanitizedPath.replace(/^[/\\]/, './') : sanitizedPath;
18
18
  };
@@ -0,0 +1,2 @@
1
+ export declare function test(cb: () => Promise<unknown>): Promise<void>;
2
+ export declare function test(cb: () => unknown): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.test = void 0;
13
+ const each_js_1 = require("../configs/each.js");
14
+ function test(cb) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ if (typeof each_js_1.each.before.cb === 'function' && each_js_1.each.before.test) {
17
+ const beforeResult = each_js_1.each.before.cb();
18
+ if (beforeResult instanceof Promise)
19
+ yield beforeResult;
20
+ }
21
+ const resultCb = cb();
22
+ if (resultCb instanceof Promise)
23
+ yield resultCb;
24
+ if (typeof each_js_1.each.after.cb === 'function' && each_js_1.each.after.test) {
25
+ const afterResult = each_js_1.each.after.cb();
26
+ if (afterResult instanceof Promise)
27
+ yield afterResult;
28
+ }
29
+ });
30
+ }
31
+ exports.test = test;
@@ -29,8 +29,13 @@ exports.fileResults = {
29
29
  };
30
30
  const runTestFile = (filePath, configs) => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
31
31
  const runtimeOptions = (0, runner_js_1.runner)(filePath, configs);
32
- const runtime = runtimeOptions.shift();
33
- const runtimeArguments = runtimeOptions.length > 1 ? [...runtimeOptions, filePath] : [filePath];
32
+ const originalRuntime = runtimeOptions.shift();
33
+ let runtime = originalRuntime;
34
+ let runtimeArguments = runtimeOptions.length > 1 ? [...runtimeOptions, filePath] : [filePath];
35
+ if (node_process_1.default.platform === 'win32' && originalRuntime === 'tsx') {
36
+ runtime = 'npx.cmd';
37
+ runtimeArguments = ['tsx', ...runtimeArguments];
38
+ }
34
39
  const fileRelative = node_path_1.default.relative(node_process_1.default.cwd(), filePath);
35
40
  const showLogs = !(0, logs_js_1.isQuiet)(configs);
36
41
  const showSuccess = (0, logs_js_1.isDebug)(configs);
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
2
  "name": "poku",
3
- "version": "1.7.0",
3
+ "version": "1.8.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": {
7
- "test": "npx tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
7
+ "test": "tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
8
8
  "pretest:c8": "npm run build",
9
9
  "test:c8": "docker compose -f test/docker/docker-compose.c8.yml up",
10
- "test:ci:c8": "npx c8 --include 'src/**' --exclude 'src/@types/**' --reporter=text --reporter=lcov npx tsx test/run.test.ts",
10
+ "test:ci:c8": "c8 --include 'src/**' --exclude 'src/@types/**' --reporter=text --reporter=lcov tsx test/run.test.ts",
11
11
  "test:ci": "tsx ./test/ci.test.ts",
12
12
  "test:node": "FILTER='node-' npm run test:ci",
13
13
  "test:deno": "FILTER='deno-' npm run test:ci",
14
14
  "test:bun": "FILTER='bun-' npm run test:ci",
15
- "prebuild": "rm -rf ./lib ./ci",
16
15
  "predocker:deno": "docker compose -f ./test/docker/playground/deno/docker-compose.yml down",
17
16
  "docker:deno": "docker compose -f ./test/docker/playground/deno/docker-compose.yml up --build",
18
- "build": "npx tsc; npx tsc -p tsconfig.test.json",
19
- "postbuild": "npx tsx ./tools/compatibility/node.ts; chmod +x lib/bin/index.js; npm audit",
20
- "eslint:checker": "npx eslint . --ext .js,.ts",
21
- "eslint:fix": "npx eslint . --fix --config ./.eslintrc.json",
22
- "lint:checker": "npm run eslint:checker; npm run prettier:checker",
23
- "lint:fix": "npm run eslint:fix; npm run prettier:fix",
24
- "prettier:checker": "npx prettier --check .",
25
- "prettier:fix": "npx prettier --write .github/workflows/*.yml .",
26
- "update": "npx npu; npm i; npm run lint:fix; npm audit"
17
+ "prebuild": "rm -rf ./lib ./ci",
18
+ "build": "tsc && tsc -p tsconfig.test.json",
19
+ "postbuild": "tsx ./tools/compatibility/node.ts && chmod +x lib/bin/index.js && npm audit",
20
+ "eslint:checker": "eslint . --ext .js,.ts",
21
+ "eslint:fix": "eslint . --fix --config ./.eslintrc.json",
22
+ "lint:checker": "npm run eslint:checker && npm run prettier:checker",
23
+ "lint:fix": "npm run eslint:fix && npm run prettier:fix",
24
+ "prettier:checker": "prettier --check .",
25
+ "prettier:fix": "prettier --write .github/workflows/*.yml .",
26
+ "update": "npu && npm i && npm run lint:fix && npm audit"
27
27
  },
28
28
  "license": "MIT",
29
29
  "repository": {