poku 1.15.1 → 1.16.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.
package/README.md CHANGED
@@ -184,6 +184,7 @@ That's it 🎉
184
184
  - [**test**](https://poku.io/docs/documentation/helpers/test)
185
185
  - [**describe**](https://poku.io/docs/documentation/helpers/describe) and [**it**](https://poku.io/docs/documentation/helpers/it)
186
186
  - [**beforeEach**](https://poku.io/docs/category/beforeeach-and-aftereach) and [**afterEach**](https://poku.io/docs/category/beforeeach-and-aftereach)
187
+ - [**watch**](https://poku.io/docs/documentation/poku/options/watch)
187
188
  - **Processes**
188
189
  - [**kill**](https://poku.io/docs/documentation/processes/kill) (_terminate Ports, Port Ranges and PIDs_)
189
190
  - [**getPIDs**](https://poku.io/docs/documentation/processes/get-pids) (_get all processes IDs using ports and port ranges_)
package/lib/bin/index.js CHANGED
@@ -13,12 +13,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const list_files_js_1 = require("../modules/list-files.js");
15
15
  const get_arg_js_1 = require("../helpers/get-arg.js");
16
- const poku_js_1 = require("../modules/poku.js");
17
- const processes_js_1 = require("../modules/processes.js");
16
+ const files_js_1 = require("../configs/files.js");
18
17
  const get_runtime_js_1 = require("../helpers/get-runtime.js");
19
18
  const format_js_1 = require("../helpers/format.js");
20
19
  const logs_js_1 = require("../helpers/logs.js");
21
20
  const hr_js_1 = require("../helpers/hr.js");
21
+ const watch_js_1 = require("../services/watch.js");
22
+ const poku_js_1 = require("../modules/poku.js");
23
+ const processes_js_1 = require("../modules/processes.js");
22
24
  (() => __awaiter(void 0, void 0, void 0, function* () {
23
25
  var _a;
24
26
  const dirs = (() => {
@@ -43,6 +45,7 @@ const hr_js_1 = require("../helpers/hr.js");
43
45
  const quiet = (0, get_arg_js_1.hasArg)('quiet');
44
46
  const debug = (0, get_arg_js_1.hasArg)('debug');
45
47
  const failFast = (0, get_arg_js_1.hasArg)('fail-fast');
48
+ const watchMode = (0, get_arg_js_1.hasArg)('watch');
46
49
  const concurrency = parallel
47
50
  ? Number((0, get_arg_js_1.getArg)('concurrency')) || undefined
48
51
  : undefined;
@@ -72,6 +75,7 @@ const hr_js_1 = require("../helpers/hr.js");
72
75
  debug,
73
76
  failFast,
74
77
  concurrency,
78
+ noExit: watchMode,
75
79
  deno: {
76
80
  allow: denoAllow,
77
81
  deny: denoDeny,
@@ -87,6 +91,30 @@ const hr_js_1 = require("../helpers/hr.js");
87
91
  (0, logs_js_1.write)(`${format_js_1.format.italic(format_js_1.format.info('…'))} ${format_js_1.format.bold('Options')}`);
88
92
  console.dir(options, { depth: null, colors: true });
89
93
  }
90
- (0, poku_js_1.poku)(dirs, options);
94
+ yield (0, poku_js_1.poku)(dirs, options);
95
+ if (watchMode) {
96
+ const executing = new Set();
97
+ const interval = Number((0, get_arg_js_1.getArg)('watch-interval')) || 1500;
98
+ files_js_1.fileResults.success.clear();
99
+ files_js_1.fileResults.fail.clear();
100
+ (0, hr_js_1.hr)();
101
+ (0, logs_js_1.write)(`Watching: ${dirs.join(', ')}`);
102
+ dirs.forEach((dir) => {
103
+ (0, watch_js_1.watch)(dir, (file, event) => {
104
+ if (event === 'change') {
105
+ if (executing.has(file))
106
+ return;
107
+ executing.add(file);
108
+ files_js_1.fileResults.success.clear();
109
+ files_js_1.fileResults.fail.clear();
110
+ (0, poku_js_1.poku)(file, options).then(() => {
111
+ setTimeout(() => {
112
+ executing.delete(file);
113
+ }, interval);
114
+ });
115
+ }
116
+ });
117
+ });
118
+ }
91
119
  }))();
92
120
  /* c8 ignore stop */
@@ -47,5 +47,5 @@ export declare const beforeEach: (callback: () => unknown, options?: EachOptions
47
47
  * after.reset();
48
48
  * ```
49
49
  */
50
- export declare const afterEach: (callback: () => unknown, options: Omit<EachOptions, 'immediate'>) => Control;
50
+ export declare const afterEach: (callback: () => unknown, options?: Omit<EachOptions, 'immediate'>) => Control;
51
51
  export {};
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { type Dirent, type Stats } from 'node:fs';
3
+ export declare const readdir: (path: string, options: {
4
+ withFileTypes: true;
5
+ }) => Promise<Dirent[]>;
6
+ export declare const stat: (path: string) => Promise<Stats>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /* c8 ignore start */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.stat = exports.readdir = void 0;
5
+ const node_fs_1 = require("fs");
6
+ const readdir = (path, options) => new Promise((resolve, reject) => {
7
+ (0, node_fs_1.readdir)(path, options, (err, entries) => {
8
+ if (err)
9
+ reject(err);
10
+ else
11
+ resolve(entries);
12
+ });
13
+ });
14
+ exports.readdir = readdir;
15
+ const stat = (path) => {
16
+ return new Promise((resolve, reject) => {
17
+ (0, node_fs_1.stat)(path, (err, stats) => {
18
+ if (err)
19
+ reject(err);
20
+ else
21
+ resolve(stats);
22
+ });
23
+ });
24
+ };
25
+ exports.stat = stat;
26
+ /* c8 ignore stop */
@@ -0,0 +1,18 @@
1
+ export type WatchCallback = (file: string, event: string) => void;
2
+ declare class Watcher {
3
+ private rootDir;
4
+ private files;
5
+ private fileWatchers;
6
+ private dirWatchers;
7
+ private callback;
8
+ constructor(rootDir: string, callback: WatchCallback);
9
+ private watchFile;
10
+ private unwatchFiles;
11
+ private watchFiles;
12
+ private watchDirectory;
13
+ start(): Promise<void>;
14
+ stop(): void;
15
+ private unwatchDirectories;
16
+ }
17
+ export declare const watch: (path: string, callback: WatchCallback) => Promise<Watcher>;
18
+ export {};
@@ -0,0 +1,122 @@
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.watch = void 0;
13
+ /* c8 ignore next */
14
+ const node_fs_1 = require("fs");
15
+ const node_path_1 = require("path");
16
+ const fs_js_1 = require("../polyfills/fs.js");
17
+ const list_files_js_1 = require("../modules/list-files.js");
18
+ class Watcher {
19
+ constructor(rootDir, callback) {
20
+ this.files = [];
21
+ this.fileWatchers = new Map();
22
+ this.dirWatchers = new Map();
23
+ this.rootDir = rootDir;
24
+ this.callback = callback;
25
+ }
26
+ watchFile(filePath) {
27
+ /* c8 ignore next */
28
+ if (this.fileWatchers.has(filePath))
29
+ return;
30
+ const watcher = (0, node_fs_1.watch)(filePath, (eventType) => {
31
+ this.callback(filePath, eventType);
32
+ });
33
+ /* c8 ignore start */
34
+ watcher.on('error', () => {
35
+ return;
36
+ });
37
+ /* c8 ignore stop */
38
+ this.fileWatchers.set(filePath, watcher);
39
+ }
40
+ unwatchFiles() {
41
+ for (const [filePath, watcher] of this.fileWatchers) {
42
+ watcher.close();
43
+ this.fileWatchers.delete(filePath);
44
+ }
45
+ }
46
+ watchFiles(filePaths) {
47
+ this.unwatchFiles();
48
+ for (const filePath of filePaths) {
49
+ this.watchFile(filePath);
50
+ }
51
+ }
52
+ watchDirectory(dir) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ if (this.dirWatchers.has(dir))
55
+ return;
56
+ const watcher = (0, node_fs_1.watch)(dir, (_, filename) => __awaiter(this, void 0, void 0, function* () {
57
+ if (filename) {
58
+ const fullPath = (0, node_path_1.join)(dir, filename);
59
+ this.files = yield (0, list_files_js_1.listFiles)(this.rootDir);
60
+ this.watchFiles(this.files);
61
+ try {
62
+ const stats = yield (0, fs_js_1.stat)(fullPath);
63
+ if (stats.isDirectory())
64
+ yield this.watchDirectory(fullPath);
65
+ /* c8 ignore start */
66
+ }
67
+ catch (_a) { }
68
+ /* c8 ignore stop */
69
+ }
70
+ }));
71
+ /* c8 ignore start */
72
+ watcher.on('error', () => {
73
+ return;
74
+ });
75
+ /* c8 ignore stop */
76
+ this.dirWatchers.set(dir, watcher);
77
+ const entries = yield (0, fs_js_1.readdir)(dir, { withFileTypes: true });
78
+ for (const entry of entries) {
79
+ if (entry.isDirectory()) {
80
+ const fullPath = (0, node_path_1.join)(dir, entry.name);
81
+ yield this.watchDirectory(fullPath);
82
+ }
83
+ }
84
+ });
85
+ }
86
+ start() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ try {
89
+ const stats = yield (0, fs_js_1.stat)(this.rootDir);
90
+ if (stats.isDirectory()) {
91
+ this.files = yield (0, list_files_js_1.listFiles)(this.rootDir);
92
+ this.watchFiles(this.files);
93
+ yield this.watchDirectory(this.rootDir);
94
+ }
95
+ else
96
+ this.watchFile(this.rootDir);
97
+ /* c8 ignore start */
98
+ }
99
+ catch (err) {
100
+ throw new Error(`Path does not exist or is not accessible: ${this.rootDir}`);
101
+ }
102
+ /* c8 ignore stop */
103
+ });
104
+ }
105
+ stop() {
106
+ this.unwatchFiles();
107
+ this.unwatchDirectories();
108
+ }
109
+ unwatchDirectories() {
110
+ for (const [dirPath, watcher] of this.dirWatchers) {
111
+ watcher.close();
112
+ this.dirWatchers.delete(dirPath);
113
+ }
114
+ }
115
+ }
116
+ /* c8 ignore next */
117
+ const watch = (path, callback) => __awaiter(void 0, void 0, void 0, function* () {
118
+ const watcher = new Watcher(path, callback);
119
+ yield watcher.start();
120
+ return watcher;
121
+ });
122
+ exports.watch = watch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poku",
3
- "version": "1.15.1",
3
+ "version": "1.16.0",
4
4
  "description": "🐷 Poku makes testing easy for Node.js, Bun, Deno and you at the same time.",
5
5
  "main": "./lib/index.js",
6
6
  "scripts": {
@@ -126,7 +126,7 @@
126
126
  "@types/node": "^20.14.2",
127
127
  "@typescript-eslint/eslint-plugin": "^7.13.0",
128
128
  "@typescript-eslint/parser": "^7.13.0",
129
- "c8": "^10.1.0",
129
+ "c8": "^10.1.2",
130
130
  "esbuild": "^0.21.5",
131
131
  "eslint": "^8.57.0",
132
132
  "eslint-config-prettier": "^9.1.0",
@@ -136,7 +136,7 @@
136
136
  "packages-update": "^2.0.0",
137
137
  "prettier": "^3.3.2",
138
138
  "shx": "^0.3.4",
139
- "tsx": "4.15.2",
139
+ "tsx": "4.15.4",
140
140
  "typescript": "^5.4.5"
141
141
  }
142
142
  }