poku 2.7.1 → 3.0.0-rc.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 +17 -15
- package/lib/@types/background-process.d.ts +1 -7
- package/lib/@types/poku.d.ts +2 -8
- package/lib/bin/help.js +9 -19
- package/lib/bin/index.js +75 -98
- package/lib/bin/watch.js +11 -10
- package/lib/builders/assert.js +1 -8
- package/lib/configs/files.js +2 -2
- package/lib/configs/poku.d.ts +11 -0
- package/lib/configs/poku.js +13 -2
- package/lib/modules/essentials/poku.js +10 -35
- package/lib/modules/helpers/create-service.js +19 -20
- package/lib/modules/helpers/describe.js +17 -9
- package/lib/modules/helpers/each.js +1 -1
- package/lib/modules/helpers/env.js +2 -2
- package/lib/modules/helpers/exit.js +8 -8
- package/lib/modules/helpers/it/core.js +11 -8
- package/lib/modules/helpers/list-files.js +29 -20
- package/lib/modules/helpers/log.js +1 -1
- package/lib/modules/helpers/modifiers.js +12 -7
- package/lib/modules/helpers/skip.js +3 -3
- package/lib/modules/helpers/wait-for.js +6 -6
- package/lib/parsers/assert.js +2 -3
- package/lib/parsers/callback.d.ts +2 -0
- package/lib/parsers/callback.js +21 -0
- package/lib/parsers/find-file-from-stack.js +3 -4
- package/lib/parsers/get-arg.d.ts +0 -2
- package/lib/parsers/get-arg.js +10 -19
- package/lib/parsers/get-runner.d.ts +1 -2
- package/lib/parsers/get-runner.js +9 -16
- package/lib/parsers/get-runtime.d.ts +2 -4
- package/lib/parsers/get-runtime.js +5 -10
- package/lib/parsers/options.js +12 -8
- package/lib/parsers/output.d.ts +0 -4
- package/lib/parsers/output.js +5 -10
- package/lib/polyfills/deno.mjs +5 -7
- package/lib/polyfills/os.js +3 -6
- package/lib/services/assert.js +15 -18
- package/lib/services/container.js +5 -5
- package/lib/services/each.d.ts +2 -3
- package/lib/services/each.js +17 -17
- package/lib/services/enforce.d.ts +1 -0
- package/lib/services/enforce.js +131 -0
- package/lib/services/env.js +1 -2
- package/lib/services/format.js +3 -3
- package/lib/services/map-tests.js +5 -6
- package/lib/services/run-test-file.d.ts +1 -2
- package/lib/services/run-test-file.js +12 -20
- package/lib/services/run-tests.d.ts +1 -3
- package/lib/services/run-tests.js +52 -94
- package/lib/services/watch.js +5 -5
- package/lib/services/write.d.ts +2 -4
- package/lib/services/write.js +7 -7
- package/package.json +18 -23
- package/lib/bin/enforce.js +0 -53
- package/lib/parsers/to-dynamic-case.d.ts +0 -1
- package/lib/parsers/to-dynamic-case.js +0 -13
- package/lib/polyfills/fs.d.ts +0 -4
- package/lib/polyfills/fs.js +0 -8
- package/lib/polyfills/object.d.ts +0 -12
- package/lib/polyfills/object.js +0 -24
|
@@ -6,66 +6,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.onSigint = void 0;
|
|
7
7
|
exports.poku = poku;
|
|
8
8
|
const node_process_1 = __importDefault(require("process"));
|
|
9
|
-
const run_tests_js_1 = require("../../services/run-tests.js");
|
|
10
9
|
const write_js_1 = require("../../services/write.js");
|
|
11
10
|
const exit_js_1 = require("../helpers/exit.js");
|
|
12
11
|
const format_js_1 = require("../../services/format.js");
|
|
13
|
-
const output_js_1 = require("../../parsers/output.js");
|
|
14
12
|
const files_js_1 = require("../../configs/files.js");
|
|
13
|
+
const run_tests_js_1 = require("../../services/run-tests.js");
|
|
14
|
+
const poku_js_1 = require("../../configs/poku.js");
|
|
15
15
|
|
|
16
16
|
const onSigint = () => node_process_1.default.stdout.write('\u001B[?25h');
|
|
17
17
|
exports.onSigint = onSigint;
|
|
18
18
|
node_process_1.default.once('SIGINT', exports.onSigint);
|
|
19
19
|
async function poku(targetPaths, configs) {
|
|
20
20
|
let code = 0;
|
|
21
|
+
if (configs)
|
|
22
|
+
poku_js_1.GLOBAL.configs = { ...poku_js_1.GLOBAL.configs, ...configs };
|
|
21
23
|
files_js_1.finalResults.started = new Date();
|
|
22
24
|
const start = node_process_1.default.hrtime();
|
|
23
25
|
const dirs = Array.prototype.concat(targetPaths);
|
|
24
|
-
const showLogs = !
|
|
25
|
-
|
|
26
|
-
if (!(configs === null || configs === void 0 ? void 0 : configs.parallel)) {
|
|
27
|
-
for (const dir of dirs) {
|
|
28
|
-
const result = await (0, run_tests_js_1.runTests)(dir, configs);
|
|
29
|
-
if (!result) {
|
|
30
|
-
code = 1;
|
|
31
|
-
if (configs === null || configs === void 0 ? void 0 : configs.failFast)
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (configs === null || configs === void 0 ? void 0 : configs.noExit)
|
|
36
|
-
return code;
|
|
37
|
-
const end = node_process_1.default.hrtime(start);
|
|
38
|
-
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6);
|
|
39
|
-
files_js_1.finalResults.time = total;
|
|
40
|
-
showLogs && (0, format_js_1.showTestResults)();
|
|
41
|
-
(0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
26
|
+
const showLogs = !poku_js_1.GLOBAL.configs.quiet;
|
|
45
27
|
if (showLogs) {
|
|
46
|
-
write_js_1.
|
|
47
|
-
write_js_1.
|
|
28
|
+
(0, write_js_1.hr)();
|
|
29
|
+
(0, write_js_1.log)(`${(0, format_js_1.format)('Running Tests').bold()}\n`);
|
|
48
30
|
}
|
|
49
31
|
try {
|
|
50
|
-
const promises = dirs.map(async (dir) =>
|
|
51
|
-
const result = await (0, run_tests_js_1.runTestsParallel)(dir, configs);
|
|
52
|
-
if (!result && (configs === null || configs === void 0 ? void 0 : configs.failFast))
|
|
53
|
-
throw new Error('quiet');
|
|
54
|
-
return result;
|
|
55
|
-
});
|
|
32
|
+
const promises = dirs.map(async (dir) => await (0, run_tests_js_1.runTests)(dir));
|
|
56
33
|
const concurrency = await Promise.all(promises);
|
|
57
34
|
if (concurrency.some((result) => !result))
|
|
58
35
|
code = 1;
|
|
59
36
|
}
|
|
60
|
-
catch (_a) {
|
|
61
|
-
}
|
|
62
37
|
finally {
|
|
63
38
|
const end = node_process_1.default.hrtime(start);
|
|
64
39
|
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6);
|
|
65
40
|
files_js_1.finalResults.time = total;
|
|
66
41
|
}
|
|
67
42
|
showLogs && (0, format_js_1.showTestResults)();
|
|
68
|
-
if (configs
|
|
43
|
+
if (poku_js_1.GLOBAL.configs.noExit)
|
|
69
44
|
return code;
|
|
70
|
-
(0, exit_js_1.exit)(code, configs
|
|
45
|
+
(0, exit_js_1.exit)(code, poku_js_1.GLOBAL.configs.quiet);
|
|
71
46
|
}
|
|
@@ -18,8 +18,8 @@ const backgroundProcess = (runtime, args, file, options) => new Promise((resolve
|
|
|
18
18
|
const service = (0, node_child_process_1.spawn)(runtime, args, {
|
|
19
19
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
20
20
|
env: node_process_1.default.env,
|
|
21
|
-
timeout: options
|
|
22
|
-
cwd:
|
|
21
|
+
timeout: options?.timeout,
|
|
22
|
+
cwd: options?.cwd ? (0, list_files_js_1.sanitizePath)((0, node_path_1.normalize)(options.cwd)) : undefined,
|
|
23
23
|
shell: get_runner_js_1.isWindows,
|
|
24
24
|
detached: !get_runner_js_1.isWindows,
|
|
25
25
|
windowsHide: get_runner_js_1.isWindows,
|
|
@@ -36,7 +36,7 @@ const backgroundProcess = (runtime, args, file, options) => new Promise((resolve
|
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
if (['bun', 'deno'].includes(runtime) ||
|
|
39
|
-
['bun', 'deno'].includes(String(options
|
|
39
|
+
['bun', 'deno'].includes(String(options?.runner)))
|
|
40
40
|
node_process_1.default.kill(PID);
|
|
41
41
|
else
|
|
42
42
|
node_process_1.default.kill(-PID, 'SIGKILL');
|
|
@@ -52,37 +52,37 @@ const backgroundProcess = (runtime, args, file, options) => new Promise((resolve
|
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
catch
|
|
55
|
+
catch {
|
|
56
56
|
resolve(undefined);
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
runningProcesses.set(PID, { end, port: portBackup });
|
|
61
61
|
service.stdout.on('data', (data) => {
|
|
62
|
-
if (!isResolved && typeof
|
|
62
|
+
if (!isResolved && typeof options?.startAfter !== 'number') {
|
|
63
63
|
const stringData = JSON.stringify(String(data));
|
|
64
|
-
if (typeof
|
|
65
|
-
(typeof
|
|
66
|
-
stringData.includes(options
|
|
64
|
+
if (typeof options?.startAfter === 'undefined' ||
|
|
65
|
+
(typeof options?.startAfter === 'string' &&
|
|
66
|
+
stringData.includes(options?.startAfter))) {
|
|
67
67
|
resolve({ end });
|
|
68
68
|
clearTimeout(timeout);
|
|
69
69
|
isResolved = true;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
options?.verbose && (0, write_js_1.log)(data);
|
|
73
73
|
});
|
|
74
74
|
service.stderr.on('data', (data) => {
|
|
75
|
-
if (!isResolved && typeof
|
|
75
|
+
if (!isResolved && typeof options?.startAfter !== 'number') {
|
|
76
76
|
const stringData = JSON.stringify(String(data));
|
|
77
|
-
if (typeof
|
|
78
|
-
(typeof
|
|
79
|
-
stringData.includes(options
|
|
77
|
+
if (typeof options?.startAfter === 'undefined' ||
|
|
78
|
+
(typeof options?.startAfter === 'string' &&
|
|
79
|
+
stringData.includes(options?.startAfter))) {
|
|
80
80
|
resolve({ end });
|
|
81
81
|
clearTimeout(timeout);
|
|
82
82
|
isResolved = true;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
options?.verbose && (0, write_js_1.log)(data);
|
|
86
86
|
});
|
|
87
87
|
service.on('error', (err) => {
|
|
88
88
|
end(portBackup);
|
|
@@ -97,8 +97,8 @@ const backgroundProcess = (runtime, args, file, options) => new Promise((resolve
|
|
|
97
97
|
end(portBackup);
|
|
98
98
|
reject(`createService: Timeout\nFile: ${file}`);
|
|
99
99
|
}
|
|
100
|
-
},
|
|
101
|
-
if (typeof
|
|
100
|
+
}, options?.timeout || 60000);
|
|
101
|
+
if (typeof options?.startAfter === 'number')
|
|
102
102
|
setTimeout(() => {
|
|
103
103
|
if (!isResolved) {
|
|
104
104
|
resolve({ end });
|
|
@@ -107,11 +107,11 @@ const backgroundProcess = (runtime, args, file, options) => new Promise((resolve
|
|
|
107
107
|
}
|
|
108
108
|
}, options.startAfter);
|
|
109
109
|
}
|
|
110
|
-
catch
|
|
110
|
+
catch { }
|
|
111
111
|
});
|
|
112
112
|
/** Starts a file in a background process (useful for servers, APIs, etc.) */
|
|
113
113
|
const startService = async (file, options) => {
|
|
114
|
-
const runtimeOptions = (0, get_runner_js_1.runner)(file
|
|
114
|
+
const runtimeOptions = (0, get_runner_js_1.runner)(file);
|
|
115
115
|
const runtime = runtimeOptions.shift();
|
|
116
116
|
const runtimeArgs = [...runtimeOptions, file];
|
|
117
117
|
return await backgroundProcess(runtime, runtimeArgs, (0, node_path_1.normalize)((0, list_files_js_1.sanitizePath)(file)), options);
|
|
@@ -126,8 +126,7 @@ exports.startService = startService;
|
|
|
126
126
|
* By default it uses **npm**, but you can costumize it using the `runner` option.
|
|
127
127
|
*/
|
|
128
128
|
const startScript = async (script, options) => {
|
|
129
|
-
|
|
130
|
-
const runner = (_a = options === null || options === void 0 ? void 0 : options.runner) !== null && _a !== void 0 ? _a : 'npm';
|
|
129
|
+
const runner = options?.runner ?? 'npm';
|
|
131
130
|
const runtimeOptions = (0, get_runner_js_1.scriptRunner)(runner);
|
|
132
131
|
const runtime = runtimeOptions.shift();
|
|
133
132
|
const runtimeArgs = [...runtimeOptions, script];
|
|
@@ -8,12 +8,12 @@ const write_js_1 = require("../../services/write.js");
|
|
|
8
8
|
const indentation_js_1 = require("../../configs/indentation.js");
|
|
9
9
|
const modifiers_js_1 = require("./modifiers.js");
|
|
10
10
|
const get_arg_js_1 = require("../../parsers/get-arg.js");
|
|
11
|
+
const callback_js_1 = require("../../parsers/callback.js");
|
|
12
|
+
const poku_js_1 = require("../../configs/poku.js");
|
|
11
13
|
async function describeBase(arg1, arg2) {
|
|
12
14
|
let title;
|
|
13
15
|
let cb;
|
|
14
16
|
let options;
|
|
15
|
-
const isPoku = typeof (node_process_1.env === null || node_process_1.env === void 0 ? void 0 : node_process_1.env.FILE) === 'string' && (node_process_1.env === null || node_process_1.env === void 0 ? void 0 : node_process_1.env.FILE.length) > 0;
|
|
16
|
-
const FILE = node_process_1.env.FILE;
|
|
17
17
|
if (typeof arg1 === 'string') {
|
|
18
18
|
title = arg1;
|
|
19
19
|
if (typeof arg2 === 'function')
|
|
@@ -27,13 +27,13 @@ async function describeBase(arg1, arg2) {
|
|
|
27
27
|
}
|
|
28
28
|
if (title) {
|
|
29
29
|
indentation_js_1.indentation.hasDescribe = true;
|
|
30
|
-
const { background, icon } = options
|
|
31
|
-
const message = `${cb ? (0, format_js_1.format)('◌').dim() : (icon
|
|
30
|
+
const { background, icon } = options ?? Object.create(null);
|
|
31
|
+
const message = `${cb ? (0, format_js_1.format)('◌').dim() : (icon ?? '☰')} ${cb ? (0, format_js_1.format)(title).dim() : (0, format_js_1.format)(title).bold()}`;
|
|
32
32
|
const noBackground = !background;
|
|
33
33
|
if (noBackground)
|
|
34
|
-
write_js_1.
|
|
34
|
+
(0, write_js_1.log)((0, format_js_1.format)(message).bold());
|
|
35
35
|
else
|
|
36
|
-
write_js_1.
|
|
36
|
+
(0, write_js_1.log)((0, format_js_1.format)(` ${message} `).bg(typeof background === 'string' ? background : 'grey'));
|
|
37
37
|
}
|
|
38
38
|
if (typeof cb !== 'function')
|
|
39
39
|
return;
|
|
@@ -45,14 +45,22 @@ async function describeBase(arg1, arg2) {
|
|
|
45
45
|
if (!title)
|
|
46
46
|
return;
|
|
47
47
|
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6);
|
|
48
|
+
poku_js_1.GLOBAL.runAsOnly = false;
|
|
48
49
|
indentation_js_1.indentation.hasDescribe = false;
|
|
49
|
-
write_js_1.
|
|
50
|
+
(0, write_js_1.log)(`${(0, format_js_1.format)(`● ${title}`).success().bold()} ${(0, format_js_1.format)(`› ${total}ms`).success().dim()}`);
|
|
50
51
|
}
|
|
51
52
|
async function describeCore(messageOrCb, cbOrOptions) {
|
|
52
53
|
if (typeof messageOrCb === 'string' && typeof cbOrOptions !== 'function')
|
|
53
54
|
return describeBase(messageOrCb, cbOrOptions);
|
|
54
|
-
if (get_arg_js_1.hasOnly
|
|
55
|
-
|
|
55
|
+
if (get_arg_js_1.hasOnly) {
|
|
56
|
+
const hasItOnly = (0, callback_js_1.checkOnly)(typeof messageOrCb === 'function' ? messageOrCb : cbOrOptions);
|
|
57
|
+
if (!hasItOnly)
|
|
58
|
+
return;
|
|
59
|
+
if (typeof messageOrCb === 'string' && typeof cbOrOptions === 'function')
|
|
60
|
+
return describeBase(messageOrCb, cbOrOptions);
|
|
61
|
+
if (typeof messageOrCb === 'function')
|
|
62
|
+
return describeBase(messageOrCb);
|
|
63
|
+
}
|
|
56
64
|
if (typeof messageOrCb === 'string' && typeof cbOrOptions === 'function')
|
|
57
65
|
return describeBase(messageOrCb, cbOrOptions);
|
|
58
66
|
if (typeof messageOrCb === 'function')
|
|
@@ -20,7 +20,7 @@ const each_js_1 = require("../../configs/each.js");
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
const beforeEach = (callback, options) => {
|
|
23
|
-
|
|
23
|
+
options?.immediate && callback();
|
|
24
24
|
each_js_1.each.before.cb = () => {
|
|
25
25
|
if (each_js_1.each.before.status)
|
|
26
26
|
return callback();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.envFile = void 0;
|
|
4
4
|
const node_process_1 = require("process");
|
|
5
|
-
const
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
6
|
const list_files_js_1 = require("./list-files.js");
|
|
7
7
|
const env_js_1 = require("../../services/env.js");
|
|
8
8
|
const regex = {
|
|
@@ -11,7 +11,7 @@ const regex = {
|
|
|
11
11
|
/** Reads an environment file and sets the environment variables. */
|
|
12
12
|
const envFile = async (filePath = '.env') => {
|
|
13
13
|
const mapEnv = new Map();
|
|
14
|
-
const env = await (0,
|
|
14
|
+
const env = await (0, promises_1.readFile)((0, list_files_js_1.sanitizePath)(filePath), 'utf8');
|
|
15
15
|
const lines = env
|
|
16
16
|
.split('\n')
|
|
17
17
|
.map((line) => (0, env_js_1.removeComments)(line.trim()))
|
|
@@ -38,15 +38,15 @@ const exit = (code, quiet) => {
|
|
|
38
38
|
!quiet &&
|
|
39
39
|
node_process_1.default.on('exit', (code) => {
|
|
40
40
|
if (isPoku) {
|
|
41
|
-
write_js_1.
|
|
42
|
-
write_js_1.
|
|
43
|
-
write_js_1.
|
|
44
|
-
write_js_1.
|
|
45
|
-
write_js_1.
|
|
46
|
-
write_js_1.
|
|
47
|
-
write_js_1.
|
|
41
|
+
(0, write_js_1.hr)();
|
|
42
|
+
(0, write_js_1.log)(` ${(0, format_js_1.format)(`Start at › ${(0, format_js_1.format)(`${(0, time_js_1.parseTime)(files_js_1.finalResults.started)}`).bold()}`).dim()}`);
|
|
43
|
+
(0, write_js_1.log)(` ${(0, format_js_1.format)('Duration ›').dim()} ${(0, format_js_1.format)(`${files_js_1.finalResults.time}ms`).bold().dim()} ${(0, format_js_1.format)(`(±${(0, time_js_1.parseTimeToSecs)(files_js_1.finalResults.time)} seconds)`).dim()}`);
|
|
44
|
+
(0, write_js_1.log)(` ${(0, format_js_1.format)(`Test Files › ${(0, format_js_1.format)(String(files_js_1.fileResults.success.size + files_js_1.fileResults.fail.size)).bold()}`).dim()}`);
|
|
45
|
+
(0, write_js_1.hr)();
|
|
46
|
+
(0, write_js_1.log)(message);
|
|
47
|
+
(0, write_js_1.hr)();
|
|
48
48
|
}
|
|
49
|
-
write_js_1.
|
|
49
|
+
(0, write_js_1.log)(`${(0, format_js_1.format)('Exited with code').dim()} ${(0, format_js_1.format)(String(code)).bold()[code === 0 ? 'success' : 'fail']()}\n`);
|
|
50
50
|
});
|
|
51
51
|
node_process_1.default.exitCode = code === 0 ? 0 : 1;
|
|
52
52
|
};
|
|
@@ -9,12 +9,11 @@ const format_js_1 = require("../../../services/format.js");
|
|
|
9
9
|
const write_js_1 = require("../../../services/write.js");
|
|
10
10
|
const modifiers_js_1 = require("../modifiers.js");
|
|
11
11
|
const get_arg_js_1 = require("../../../parsers/get-arg.js");
|
|
12
|
+
const poku_js_1 = require("../../../configs/poku.js");
|
|
12
13
|
async function itBase(...args) {
|
|
13
14
|
try {
|
|
14
15
|
let message;
|
|
15
16
|
let cb;
|
|
16
|
-
const isPoku = typeof (node_process_1.env === null || node_process_1.env === void 0 ? void 0 : node_process_1.env.FILE) === 'string' && (node_process_1.env === null || node_process_1.env === void 0 ? void 0 : node_process_1.env.FILE.length) > 0;
|
|
17
|
-
const FILE = node_process_1.env.FILE;
|
|
18
17
|
if (typeof args[0] === 'string') {
|
|
19
18
|
message = args[0];
|
|
20
19
|
cb = args[1];
|
|
@@ -23,9 +22,7 @@ async function itBase(...args) {
|
|
|
23
22
|
cb = args[0];
|
|
24
23
|
if (message) {
|
|
25
24
|
indentation_js_1.indentation.hasItOrTest = true;
|
|
26
|
-
write_js_1.
|
|
27
|
-
? `${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`◌ ${message} › ${(0, format_js_1.format)(`${FILE}`).italic().gray()}`).dim()}`
|
|
28
|
-
: `${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`◌ ${message}`).dim()}`);
|
|
25
|
+
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`◌ ${message}`).dim()}`);
|
|
29
26
|
}
|
|
30
27
|
if (typeof each_js_1.each.before.cb === 'function') {
|
|
31
28
|
const beforeResult = each_js_1.each.before.cb();
|
|
@@ -46,7 +43,7 @@ async function itBase(...args) {
|
|
|
46
43
|
return;
|
|
47
44
|
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6);
|
|
48
45
|
indentation_js_1.indentation.hasItOrTest = false;
|
|
49
|
-
write_js_1.
|
|
46
|
+
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`● ${message}`).success().bold()} ${(0, format_js_1.format)(`› ${total}ms`).success().dim()}`);
|
|
50
47
|
}
|
|
51
48
|
catch (error) {
|
|
52
49
|
indentation_js_1.indentation.hasItOrTest = false;
|
|
@@ -59,8 +56,14 @@ async function itBase(...args) {
|
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
async function itCore(messageOrCb, cb) {
|
|
62
|
-
if (get_arg_js_1.hasOnly
|
|
63
|
-
|
|
59
|
+
if (get_arg_js_1.hasOnly) {
|
|
60
|
+
if (!poku_js_1.GLOBAL.runAsOnly)
|
|
61
|
+
return;
|
|
62
|
+
if (typeof messageOrCb === 'string' && typeof cb === 'function')
|
|
63
|
+
return itBase(messageOrCb, cb);
|
|
64
|
+
if (typeof messageOrCb === 'function')
|
|
65
|
+
return itBase(messageOrCb);
|
|
66
|
+
}
|
|
64
67
|
if (typeof messageOrCb === 'string' && cb)
|
|
65
68
|
return itBase(messageOrCb, cb);
|
|
66
69
|
if (typeof messageOrCb === 'function')
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.listFiles = exports.getAllFiles = exports.escapeRegExp = exports.isFile = exports.sanitizePath = void 0;
|
|
5
4
|
const node_process_1 = require("process");
|
|
6
5
|
const node_path_1 = require("path");
|
|
7
|
-
const
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
8
7
|
const files_js_1 = require("../../configs/files.js");
|
|
9
8
|
const regex = {
|
|
10
9
|
sep: /[/\\]+/g,
|
|
@@ -24,39 +23,49 @@ const sanitizePath = (input, ensureTarget) => {
|
|
|
24
23
|
: sanitizedPath;
|
|
25
24
|
};
|
|
26
25
|
exports.sanitizePath = sanitizePath;
|
|
27
|
-
const isFile = async (fullPath) => (await (0,
|
|
26
|
+
const isFile = async (fullPath) => (await (0, promises_1.stat)(fullPath)).isFile();
|
|
28
27
|
exports.isFile = isFile;
|
|
29
28
|
const escapeRegExp = (string) => string.replace(regex.safeRegExp, '\\$&');
|
|
30
29
|
exports.escapeRegExp = escapeRegExp;
|
|
31
|
-
const envFilter =
|
|
30
|
+
const envFilter = node_process_1.env.FILTER?.trim()
|
|
32
31
|
? new RegExp((0, exports.escapeRegExp)(node_process_1.env.FILTER), 'i')
|
|
33
32
|
: undefined;
|
|
34
33
|
const getAllFiles = async (dirPath, files = new Set(), configs) => {
|
|
35
34
|
let isFullPath = false;
|
|
36
35
|
const currentFiles = await (async () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
try {
|
|
37
|
+
if (await (0, exports.isFile)(dirPath)) {
|
|
38
|
+
isFullPath = true;
|
|
39
|
+
return [(0, exports.sanitizePath)(dirPath)];
|
|
40
|
+
}
|
|
41
|
+
return await (0, promises_1.readdir)((0, exports.sanitizePath)(dirPath));
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error(error);
|
|
45
|
+
process.exit(1);
|
|
40
46
|
}
|
|
41
|
-
return await (0, fs_js_1.readdir)((0, exports.sanitizePath)(dirPath));
|
|
42
47
|
})();
|
|
43
|
-
const filter =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const filter = (() => {
|
|
49
|
+
if (envFilter)
|
|
50
|
+
return envFilter;
|
|
51
|
+
if (configs?.filter instanceof RegExp)
|
|
52
|
+
return configs.filter;
|
|
53
|
+
return regex.defaultFilter;
|
|
54
|
+
})();
|
|
55
|
+
const exclude = (() => {
|
|
56
|
+
if (!configs?.exclude)
|
|
57
|
+
return undefined;
|
|
58
|
+
if (Array.isArray(configs.exclude))
|
|
59
|
+
return configs.exclude;
|
|
60
|
+
return [configs.exclude];
|
|
61
|
+
})();
|
|
53
62
|
await Promise.all(currentFiles.map(async (file) => {
|
|
54
63
|
const fullPath = isFullPath ? dirPath : (0, node_path_1.join)(dirPath, file);
|
|
55
|
-
const stat = await (0,
|
|
64
|
+
const stat = await (0, promises_1.stat)(fullPath);
|
|
56
65
|
if (fullPath.indexOf('node_modules') !== -1 ||
|
|
57
66
|
fullPath.indexOf('.git/') !== -1)
|
|
58
67
|
return;
|
|
59
|
-
if (isFullPath &&
|
|
68
|
+
if (isFullPath && files_js_1.states?.isSinglePath)
|
|
60
69
|
return files.add(fullPath);
|
|
61
70
|
if (exclude)
|
|
62
71
|
for (const pattern of exclude) {
|
|
@@ -4,33 +4,38 @@ exports.todo = todo;
|
|
|
4
4
|
exports.skip = skip;
|
|
5
5
|
exports.onlyDescribe = onlyDescribe;
|
|
6
6
|
exports.onlyIt = onlyIt;
|
|
7
|
+
const node_process_1 = require("process");
|
|
7
8
|
const write_js_1 = require("../../services/write.js");
|
|
8
9
|
const indentation_js_1 = require("../../configs/indentation.js");
|
|
9
10
|
const format_js_1 = require("../../services/format.js");
|
|
10
11
|
const core_js_1 = require("./it/core.js");
|
|
11
12
|
const describe_js_1 = require("./describe.js");
|
|
12
13
|
const get_arg_js_1 = require("../../parsers/get-arg.js");
|
|
13
|
-
const
|
|
14
|
+
const callback_js_1 = require("../../parsers/callback.js");
|
|
15
|
+
const poku_js_1 = require("../../configs/poku.js");
|
|
14
16
|
async function todo(message, _cb) {
|
|
15
|
-
write_js_1.
|
|
17
|
+
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`● ${message}`).cyan().bold()}`);
|
|
16
18
|
}
|
|
17
19
|
async function skip(messageOrCb, _cb) {
|
|
18
20
|
const message = typeof messageOrCb === 'string' ? messageOrCb : 'Skipping';
|
|
19
|
-
write_js_1.
|
|
21
|
+
(0, write_js_1.log)(`${indentation_js_1.indentation.hasDescribe ? ' ' : ''}${(0, format_js_1.format)(`◯ ${message}`).info().bold()}`);
|
|
20
22
|
}
|
|
21
23
|
async function onlyDescribe(messageOrCb, cb) {
|
|
22
|
-
if (!
|
|
23
|
-
write_js_1.
|
|
24
|
+
if (!get_arg_js_1.hasOnly) {
|
|
25
|
+
(0, write_js_1.log)((0, format_js_1.format)("Can't run `describe.only` tests without `--only` flag").fail());
|
|
24
26
|
(0, node_process_1.exit)(1);
|
|
25
27
|
}
|
|
28
|
+
const noItOnly = (0, callback_js_1.CheckNoOnly)(typeof messageOrCb === 'function' ? messageOrCb : cb);
|
|
29
|
+
if (noItOnly)
|
|
30
|
+
poku_js_1.GLOBAL.runAsOnly = true;
|
|
26
31
|
if (typeof messageOrCb === 'string' && cb)
|
|
27
32
|
return (0, describe_js_1.describeBase)(messageOrCb, cb);
|
|
28
33
|
if (typeof messageOrCb === 'function')
|
|
29
34
|
return (0, describe_js_1.describeBase)(messageOrCb);
|
|
30
35
|
}
|
|
31
36
|
async function onlyIt(messageOrCb, cb) {
|
|
32
|
-
if (!
|
|
33
|
-
write_js_1.
|
|
37
|
+
if (!get_arg_js_1.hasOnly) {
|
|
38
|
+
(0, write_js_1.log)((0, format_js_1.format)("Can't run `it.only` and `test.only` tests without `--only` flag").fail());
|
|
34
39
|
(0, node_process_1.exit)(1);
|
|
35
40
|
}
|
|
36
41
|
if (typeof messageOrCb === 'string' && cb)
|
|
@@ -4,11 +4,11 @@ exports.skip = void 0;
|
|
|
4
4
|
const node_process_1 = require("process");
|
|
5
5
|
const write_js_1 = require("../../services/write.js");
|
|
6
6
|
const format_js_1 = require("../../services/format.js");
|
|
7
|
+
const poku_js_1 = require("../../configs/poku.js");
|
|
7
8
|
const skip = (message = 'Skipping') => {
|
|
8
|
-
const isPoku
|
|
9
|
-
const FILE = node_process_1.env.FILE;
|
|
9
|
+
const { isPoku, FILE } = poku_js_1.GLOBAL;
|
|
10
10
|
if (message)
|
|
11
|
-
write_js_1.
|
|
11
|
+
(0, write_js_1.log)((0, format_js_1.format)(isPoku
|
|
12
12
|
? `◯ ${message} ${(0, format_js_1.format)('›').dim()} ${(0, format_js_1.format)(`${FILE}`).italic().gray().dim()}`
|
|
13
13
|
: `◯ ${message}`)
|
|
14
14
|
.info()
|
|
@@ -20,9 +20,9 @@ const sleep = (milliseconds) => {
|
|
|
20
20
|
exports.sleep = sleep;
|
|
21
21
|
/** Wait until a result is equal the expected value. */
|
|
22
22
|
const waitForExpectedResult = async (callback, expectedResult, options) => {
|
|
23
|
-
const delay =
|
|
24
|
-
const interval =
|
|
25
|
-
const timeout =
|
|
23
|
+
const delay = options?.delay || 0;
|
|
24
|
+
const interval = options?.interval || 100;
|
|
25
|
+
const timeout = options?.timeout || 60000;
|
|
26
26
|
if (typeof callback !== 'function')
|
|
27
27
|
throw new Error('Callback must be a function.');
|
|
28
28
|
if (!Number.isInteger(interval))
|
|
@@ -46,12 +46,12 @@ const waitForExpectedResult = async (callback, expectedResult, options) => {
|
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
try {
|
|
49
|
-
|
|
49
|
+
options?.strict
|
|
50
50
|
? (0, node_assert_1.deepStrictEqual)(result, expectedResult)
|
|
51
51
|
: (0, node_assert_1.deepEqual)(result, expectedResult);
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
|
-
catch
|
|
54
|
+
catch { }
|
|
55
55
|
}
|
|
56
56
|
if (Date.now() - startTime >= timeout)
|
|
57
57
|
throw new Error('Timeout');
|
|
@@ -62,7 +62,7 @@ const waitForExpectedResult = async (callback, expectedResult, options) => {
|
|
|
62
62
|
exports.waitForExpectedResult = waitForExpectedResult;
|
|
63
63
|
/** Wait until the defined port is active. */
|
|
64
64
|
const waitForPort = async (port, options) => {
|
|
65
|
-
const host =
|
|
65
|
+
const host = options?.host || 'localhost';
|
|
66
66
|
if (!Number.isInteger(port))
|
|
67
67
|
throw new Error('Port must be an integer.');
|
|
68
68
|
await (0, exports.waitForExpectedResult)(async () => await checkPort(port, host), true, options);
|
package/lib/parsers/assert.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseResultType = void 0;
|
|
4
|
-
const object_js_1 = require("../polyfills/object.js");
|
|
5
4
|
const recurse = (value) => {
|
|
6
5
|
if (typeof value === 'undefined' ||
|
|
7
6
|
typeof value === 'function' ||
|
|
@@ -14,9 +13,9 @@ const recurse = (value) => {
|
|
|
14
13
|
if (value instanceof Set)
|
|
15
14
|
return Array.from(value).map(recurse);
|
|
16
15
|
if (value instanceof Map)
|
|
17
|
-
return recurse(
|
|
16
|
+
return recurse(Object.fromEntries(value));
|
|
18
17
|
if (value !== null && typeof value === 'object')
|
|
19
|
-
return
|
|
18
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, recurse(val)]));
|
|
20
19
|
return value;
|
|
21
20
|
};
|
|
22
21
|
const parseResultType = (type) => {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckNoOnly = exports.checkOnly = void 0;
|
|
4
|
+
const checkOnly = (cb) => {
|
|
5
|
+
if (typeof cb !== 'function')
|
|
6
|
+
return false;
|
|
7
|
+
const body = cb.toString();
|
|
8
|
+
return (body.includes('it.only') ||
|
|
9
|
+
body.includes('test.only') ||
|
|
10
|
+
body.includes('describe.only'));
|
|
11
|
+
};
|
|
12
|
+
exports.checkOnly = checkOnly;
|
|
13
|
+
const CheckNoOnly = (cb) => {
|
|
14
|
+
if (typeof cb !== 'function')
|
|
15
|
+
return false;
|
|
16
|
+
const body = cb.toString();
|
|
17
|
+
return !(body.includes('it.only') ||
|
|
18
|
+
body.includes('test.only') ||
|
|
19
|
+
body.includes('describe.only'));
|
|
20
|
+
};
|
|
21
|
+
exports.CheckNoOnly = CheckNoOnly;
|
|
@@ -3,19 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findFile = void 0;
|
|
4
4
|
const regex = /at\s(\/.+|file:.+)|^(\s+)at\smodule\scode\s\((\/.+|file:.+)\)/i;
|
|
5
5
|
const findFile = (error) => {
|
|
6
|
-
|
|
7
|
-
const stackLines = (_b = (_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')) !== null && _b !== void 0 ? _b : [];
|
|
6
|
+
const stackLines = error.stack?.split('\n') ?? [];
|
|
8
7
|
let file = '';
|
|
9
8
|
const basePath = 'poku/lib/';
|
|
10
9
|
for (const line of stackLines) {
|
|
11
10
|
if (line.indexOf(basePath) !== -1)
|
|
12
11
|
continue;
|
|
13
12
|
const match = line.match(regex);
|
|
14
|
-
if (match
|
|
13
|
+
if (match?.[1]) {
|
|
15
14
|
file = match[1];
|
|
16
15
|
break;
|
|
17
16
|
}
|
|
18
|
-
if (match
|
|
17
|
+
if (match?.[3]) {
|
|
19
18
|
file = match[3];
|
|
20
19
|
break;
|
|
21
20
|
}
|
package/lib/parsers/get-arg.d.ts
CHANGED
|
@@ -3,5 +3,3 @@ export declare const hasArg: (arg: string, prefix?: string, baseArgs?: string[])
|
|
|
3
3
|
export declare const getPaths: (prefix?: string, baseArgs?: string[]) => string[] | undefined;
|
|
4
4
|
export declare const argToArray: (arg: string, prefix?: string, baseArgs?: string[]) => string[] | undefined;
|
|
5
5
|
export declare const hasOnly: boolean;
|
|
6
|
-
export declare const hasDescribeOnly: boolean;
|
|
7
|
-
export declare const hasItOnly: boolean | "" | undefined;
|