@vbarbarosh/node-helpers 3.74.1 → 3.76.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 +29 -3
- package/dist/browser.js +1 -2504
- package/package.json +31 -11
- package/src/HeartbeatServer.js +24 -3
- package/src/HeartbeatServer.md +33 -0
- package/src/array_chunk.js +1 -1
- package/src/array_chunk.md +8 -0
- package/src/array_chunk_balanced.md +14 -0
- package/src/array_fps.md +12 -0
- package/src/array_gcd.js +4 -2
- package/src/array_gcd.md +2 -1
- package/src/array_group.js +3 -3
- package/src/array_group.md +14 -0
- package/src/array_group_map.js +3 -3
- package/src/array_group_map.md +13 -0
- package/src/array_index.js +2 -2
- package/src/array_index.md +9 -0
- package/src/array_lcm.js +4 -2
- package/src/array_lcm.md +2 -1
- package/src/array_max.js +11 -4
- package/src/array_max.md +1 -1
- package/src/array_min.js +11 -4
- package/src/array_min.md +1 -1
- package/src/array_permutations.js +4 -0
- package/src/array_permutations.md +13 -0
- package/src/array_sort.js +7 -2
- package/src/array_sort.md +13 -0
- package/src/array_sort_other.js +8 -5
- package/src/array_sort_other.md +11 -0
- package/src/array_sum.js +2 -2
- package/src/array_sum.md +8 -0
- package/src/array_unique.js +2 -2
- package/src/array_unique_last.js +2 -2
- package/src/assert_valid_expires_at.md +10 -0
- package/src/clamp.md +9 -0
- package/src/cli-apps/watchdog.js +5 -0
- package/src/cli.js +3 -1
- package/src/cli.md +15 -0
- package/src/const_stream.md +7 -0
- package/src/const_type.md +5 -0
- package/src/countdown.js +22 -5
- package/src/countdown.md +21 -0
- package/src/crypto_decrypt_aes256.md +13 -0
- package/src/crypto_encrypt_aes256.md +13 -0
- package/src/crypto_hash_md5.md +10 -0
- package/src/crypto_hash_sha256.md +10 -0
- package/src/crypto_hmac_sha256.md +11 -0
- package/src/date_add_hours.md +8 -0
- package/src/date_add_milliseconds.md +4 -0
- package/src/date_add_minutes.md +4 -0
- package/src/date_add_months.md +13 -0
- package/src/date_add_seconds.md +4 -0
- package/src/date_diff_seconds.md +4 -0
- package/src/date_is_leap_year.md +9 -0
- package/src/escape_content_disposition.js +6 -3
- package/src/escape_content_disposition.md +13 -0
- package/src/escape_regexp.md +7 -0
- package/src/eta.js +7 -1
- package/src/eta.md +18 -0
- package/src/factorize_ms.js +3 -0
- package/src/factorize_ms.md +10 -0
- package/src/fastdl.js +14 -3
- package/src/fcmp_dates.md +12 -0
- package/src/fcmp_default.js +7 -0
- package/src/fcmp_default.md +29 -0
- package/src/fcmp_default_desc.js +4 -7
- package/src/fcmp_default_desc.md +10 -0
- package/src/fcmp_from_spec.md +13 -0
- package/src/fcmp_numbers.md +11 -0
- package/src/fcmp_tuples.md +17 -0
- package/src/fcmp_utf8_bin.md +14 -0
- package/src/fcmp_utf8_ci.md +14 -0
- package/src/fcmp_utf8_cs.md +15 -0
- package/src/fcmp_utf8_natural_bin.js +38 -0
- package/src/fcmp_utf8_natural_bin.md +8 -0
- package/src/fcmp_utf8_natural_ci.md +13 -0
- package/src/fcmp_utf8_natural_cs.md +13 -0
- package/src/fcmpx.md +26 -9
- package/src/filter1_from_spec.js +3 -3
- package/src/format_bytes.md +15 -0
- package/src/format_date.md +7 -0
- package/src/format_date_fs.md +7 -0
- package/src/format_date_human.md +6 -0
- package/src/format_date_ymd.md +6 -0
- package/src/format_error_report.js +3 -3
- package/src/format_error_report.md +12 -0
- package/src/format_kilo.md +13 -0
- package/src/format_ms.js +3 -2
- package/src/format_ms.md +12 -0
- package/src/format_ms2.js +6 -3
- package/src/format_ms2.md +12 -0
- package/src/format_ms3.js +3 -2
- package/src/format_ms3.md +12 -0
- package/src/format_percents.md +10 -0
- package/src/format_progress_bytes.md +13 -0
- package/src/format_progress_kilo.md +10 -0
- package/src/format_seconds.md +11 -0
- package/src/format_thousands.md +9 -0
- package/src/fs_append.md +7 -0
- package/src/fs_append_json.md +8 -0
- package/src/fs_append_utf8.md +6 -0
- package/src/fs_assert_file_exists.md +3 -0
- package/src/fs_assert_file_readable.js +1 -1
- package/src/fs_assert_file_readable.md +3 -0
- package/src/fs_assert_file_socket.md +2 -0
- package/src/fs_copy.md +7 -0
- package/src/fs_copy_excl.md +2 -0
- package/src/fs_exists.md +6 -0
- package/src/fs_fclose.md +5 -0
- package/src/fs_fi.js +13 -1
- package/src/fs_fi.md +11 -0
- package/src/fs_file_md5.md +8 -0
- package/src/fs_find.md +7 -0
- package/src/fs_fopen.md +6 -0
- package/src/fs_fread.js +2 -2
- package/src/fs_fread.md +11 -0
- package/src/fs_fsize.md +2 -0
- package/src/fs_fstat.md +2 -0
- package/src/fs_fwrite.js +2 -2
- package/src/fs_fwrite.md +9 -0
- package/src/fs_list.md +5 -0
- package/src/fs_list_deep.md +5 -0
- package/src/fs_ls.md +2 -0
- package/src/fs_lsr.md +4 -0
- package/src/fs_lstat.md +3 -0
- package/src/fs_mkdir.md +3 -0
- package/src/fs_mkdirp.js +3 -30
- package/src/fs_mkdirp.md +7 -0
- package/src/fs_path_basename.md +2 -0
- package/src/fs_path_dirname.md +2 -0
- package/src/fs_path_extname.md +9 -0
- package/src/fs_path_join.md +2 -0
- package/src/fs_path_relative.md +2 -0
- package/src/fs_path_resolve.md +2 -0
- package/src/fs_path_tempdir.md +2 -0
- package/src/fs_path_untildify.md +8 -0
- package/src/fs_read.md +3 -0
- package/src/fs_read_buffer.md +5 -0
- package/src/fs_read_json.md +6 -0
- package/src/fs_read_lines.md +7 -0
- package/src/fs_read_stream.md +2 -0
- package/src/fs_read_utf8.md +5 -0
- package/src/fs_readdir.md +3 -0
- package/src/fs_readlink.md +6 -0
- package/src/fs_rename.md +6 -0
- package/src/fs_rm.md +4 -0
- package/src/fs_rmdir.md +3 -0
- package/src/fs_rmf.md +2 -0
- package/src/fs_rmrf.md +8 -0
- package/src/fs_sha256.js +16 -0
- package/src/fs_sha256.md +9 -0
- package/src/fs_size.js +2 -2
- package/src/fs_size.md +6 -0
- package/src/fs_stat.md +2 -0
- package/src/fs_tempdir.js +20 -5
- package/src/fs_touch.md +6 -0
- package/src/fs_walk.js +2 -2
- package/src/fs_walk.md +14 -0
- package/src/fs_write.md +3 -0
- package/src/fs_write_json.md +7 -0
- package/src/fs_write_stream.md +2 -0
- package/src/gettype.md +13 -0
- package/src/http_delete.md +11 -0
- package/src/http_get_blob.md +8 -0
- package/src/http_get_buffer.md +10 -0
- package/src/http_get_file.js +8 -8
- package/src/http_get_file.md +14 -0
- package/src/http_get_json.md +10 -0
- package/src/http_get_stream.md +14 -0
- package/src/http_get_stream_range.js +27 -9
- package/src/http_get_stream_range.md +22 -0
- package/src/http_get_utf8.md +9 -0
- package/src/http_head.md +9 -0
- package/src/http_patch_json.md +10 -0
- package/src/http_post_json.md +11 -0
- package/src/http_post_multipart.md +15 -0
- package/src/http_post_urlencoded.md +11 -0
- package/src/http_put_buffer.md +9 -0
- package/src/http_put_file.js +9 -6
- package/src/http_put_file.md +16 -0
- package/src/http_put_json.md +11 -0
- package/src/http_put_utf8.md +9 -0
- package/src/http_range_parse.js +6 -3
- package/src/http_range_parse.md +18 -0
- package/src/http_stream_range.js +35 -22
- package/src/http_stream_range.md +29 -0
- package/src/identity.md +2 -0
- package/src/ignore.md +2 -0
- package/src/json_stringify_safe.md +10 -0
- package/src/json_stringify_stable.md +9 -0
- package/src/logger.js +2 -3
- package/src/logger.md +15 -0
- package/src/make_progress.js +8 -5
- package/src/make_progress.md +20 -0
- package/src/math_gcd.js +2 -1
- package/src/mongo_stream_upsert.js +10 -3
- package/src/mongo_stream_upsert.md +17 -0
- package/src/mongo_stream_write.js +10 -3
- package/src/mongo_stream_write.md +16 -0
- package/src/msval.md +10 -0
- package/src/now_fs.md +7 -0
- package/src/now_human.md +6 -0
- package/src/object_defaults.md +11 -0
- package/src/object_schema.js +2 -1
- package/src/object_schema.md +12 -0
- package/src/object_walk_preorder.md +16 -0
- package/src/parallel.js +23 -10
- package/src/parse_bytes.js +4 -2
- package/src/parse_bytes.md +15 -0
- package/src/parse_hms.js +1 -1
- package/src/parse_http_content_range.js +9 -5
- package/src/parse_http_content_range.md +16 -0
- package/src/perf_end_human.md +10 -0
- package/src/perf_end_ms.md +8 -0
- package/src/perf_measure.md +10 -0
- package/src/perf_measure_human.md +8 -0
- package/src/perf_start.md +9 -0
- package/src/pgid_exists.md +6 -0
- package/src/pgid_kill_grace.js +1 -1
- package/src/pgid_kill_grace.md +15 -0
- package/src/pid_exists.md +5 -0
- package/src/pid_kill_grace.js +1 -1
- package/src/pid_kill_grace.md +14 -0
- package/src/plural.md +13 -0
- package/src/random_hex.md +9 -0
- package/src/random_int.md +8 -0
- package/src/range.js +4 -2
- package/src/range.md +2 -0
- package/src/redis_connect.js +1 -1
- package/src/redis_connect.md +10 -0
- package/src/redis_lshift.md +14 -0
- package/src/redis_poll.js +1 -0
- package/src/redis_poll.md +17 -0
- package/src/redis_poll_zshift_callback_rpush.js +1 -2
- package/src/redis_poll_zshift_callback_rpush.md +17 -0
- package/src/redis_poll_zshift_spawn_rpush.js +2 -1
- package/src/redis_poll_zshift_spawn_rpush.md +20 -0
- package/src/redis_zshift.md +14 -0
- package/src/round.js +7 -8
- package/src/round.md +15 -0
- package/src/sanitize_dash_name.md +13 -0
- package/src/sanitize_filename.md +9 -0
- package/src/sanitize_var_name.md +14 -0
- package/src/sftp_get_file_info.js +2 -2
- package/src/sftp_get_file_info.md +14 -0
- package/src/sftp_get_stream_range.js +32 -22
- package/src/sftp_get_stream_range.md +20 -0
- package/src/shell_curl_progress.js +2 -1
- package/src/shell_curl_progress.md +17 -0
- package/src/shell_lines.js +2 -2
- package/src/shell_lines.md +1 -1
- package/src/shell_spawn.js +7 -0
- package/src/shell_ytdlp_progress.js +2 -1
- package/src/shell_ytdlp_progress.md +17 -0
- package/src/str_camel_to_snake.md +11 -0
- package/src/str_parse_kv.md +11 -0
- package/src/stream_curl_progress.md +14 -0
- package/src/stream_data_ln.js +7 -1
- package/src/stream_discard.md +8 -0
- package/src/stream_group.md +3 -0
- package/src/stream_gunzip.md +7 -0
- package/src/stream_hash.md +10 -0
- package/src/stream_map.js +8 -1
- package/src/stream_map_parallel.js +9 -1
- package/src/stream_md5.md +9 -0
- package/src/stream_multiplex.js +11 -0
- package/src/stream_multiplex.md +16 -0
- package/src/stream_through.md +3 -0
- package/src/stream_transform.md +2 -0
- package/src/stream_xml_analyze.js +9 -1
- package/src/stream_xml_parse.js +9 -1
- package/src/stream_ytdlp_progress.js +1 -1
- package/src/stream_ytdlp_progress.md +18 -0
- package/src/strtr.js +15 -5
- package/src/strtr.md +11 -0
- package/src/urlclean.js +9 -2
- package/src/urlmod.js +5 -0
- package/src/urlparts.md +17 -0
- package/src/wait_while.js +1 -1
- package/src/wait_while.md +1 -1
- package/src/HeartbeatServer.test.js +0 -31
- package/src/array_chunk.test.js +0 -24
- package/src/array_chunk_balanced.test.js +0 -37
- package/src/array_fps.test.js +0 -72
- package/src/array_gcd.test.js +0 -10
- package/src/array_index.test.js +0 -14
- package/src/array_lcm.test.js +0 -12
- package/src/array_max.test.js +0 -20
- package/src/array_min.test.js +0 -20
- package/src/array_permutations.test.js +0 -20
- package/src/array_sort.test.js +0 -85
- package/src/array_sort_other.test.js +0 -9
- package/src/array_sum.test.js +0 -11
- package/src/cli-apps/watchdog.d/connect_close.js +0 -17
- package/src/cli-apps/watchdog.d/connect_close2.js +0 -20
- package/src/cli-apps/watchdog.d/connect_close3.js +0 -25
- package/src/cli-apps/watchdog.d/connect_no_ping.js +0 -13
- package/src/cli-apps/watchdog.d/early_exit.js +0 -7
- package/src/cli-apps/watchdog.d/flood.js +0 -13
- package/src/cli-apps/watchdog.d/flood2.js +0 -15
- package/src/cli-apps/watchdog.d/hang.js +0 -8
- package/src/cli-apps/watchdog.d/huge_delay.js +0 -18
- package/src/cli-apps/watchdog.d/ignore_sigterm.js +0 -29
- package/src/cli-apps/watchdog.d/late_heartbeat.js +0 -21
- package/src/cli-apps/watchdog.d/my-exit-after-2-pings.js +0 -16
- package/src/cli-apps/watchdog.d/my-happy-path.js +0 -16
- package/src/cli-apps/watchdog.d/my-ignore-sigterm.js +0 -22
- package/src/cli-apps/watchdog.d/my-never-ping.js +0 -15
- package/src/cli-apps/watchdog.d/no_heartbeat.js +0 -5
- package/src/cli-apps/watchdog.d/ok.js +0 -17
- package/src/cli-apps/watchdog.d/quick-exit-after-2-pings.js +0 -15
- package/src/cli-apps/watchdog.d/quick-hang-after-1-ping.js +0 -15
- package/src/cli-apps/watchdog.d/spawn_children.js +0 -14
- package/src/cli-apps/watchdog.test.js +0 -48
- package/src/crypto_encrypt_aes256.test.js +0 -10
- package/src/crypto_hash_sha256.test.js +0 -10
- package/src/date_add_months.test.js +0 -40
- package/src/date_is_leap_year.test.js +0 -14
- package/src/escape_content_disposition.test.js +0 -22
- package/src/fcmp_from_spec.test.js +0 -91
- package/src/fcmpx.test.js +0 -173
- package/src/filter1_from_spec.test.js +0 -31
- package/src/format_bytes.test.js +0 -22
- package/src/format_error_report.d/src/1.js +0 -26
- package/src/format_error_report.d/src/2.js +0 -29
- package/src/format_kilo.test.js +0 -25
- package/src/format_ms.test.js +0 -33
- package/src/format_ms2.test.js +0 -33
- package/src/format_ms3.test.js +0 -33
- package/src/format_percents.test.js +0 -22
- package/src/format_progress_bytes.test.js +0 -19
- package/src/format_progress_kilo.test.js +0 -19
- package/src/format_seconds.test.js +0 -42
- package/src/format_thousands.test.js +0 -28
- package/src/fs_file_md5.test.js +0 -11
- package/src/fs_mkdirp.test.js +0 -24
- package/src/fs_path_extname.test.js +0 -22
- package/src/gettype.test.js +0 -27
- package/src/object_schema.test.js +0 -15
- package/src/object_walk_preorder.test.js +0 -17
- package/src/parallel.test.js +0 -11
- package/src/parse_bytes.test.js +0 -21
- package/src/parse_hms.test.js +0 -32
- package/src/parse_http_content_range.test.js +0 -14
- package/src/pid_kill_grace.d/ignore-sigterm-for-10ms.js +0 -33
- package/src/pid_kill_grace.d/ignore-sigterm.js +0 -22
- package/src/pid_kill_grace.test.js +0 -63
- package/src/ping_socket.test.js +0 -58
- package/src/plural.test.js +0 -20
- package/src/range.test.js +0 -41
- package/src/redis_lshift.test.js +0 -57
- package/src/redis_zshift.test.js +0 -58
- package/src/round.test.js +0 -56
- package/src/sanitize_dash_name.test.js +0 -59
- package/src/sanitize_var_name.test.js +0 -39
- package/src/shell_spawn.test.js +0 -30
- package/src/str_camel_to_snake.test.js +0 -17
- package/src/stream_curl_progress.d/basic +0 -3
- package/src/stream_curl_progress.d/basic.json +0 -42
- package/src/stream_curl_progress.test.js +0 -17
- package/src/stream_data_ln.test.js +0 -24
- package/src/stream_map_parallel.test.js +0 -26
- package/src/stream_multiplex.test.js +0 -67
- package/src/stream_strpbrk.test.js +0 -29
- package/src/urlclean.test.js +0 -18
- package/src/urlmod.test.js +0 -40
- package/src/urlparts.test.js +0 -294
package/src/fs_file_md5.test.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs_file_md5 = require('./fs_file_md5');
|
|
3
|
-
const fs_path_resolve = require('./fs_path_resolve');
|
|
4
|
-
|
|
5
|
-
describe('fs_file_md5', function () {
|
|
6
|
-
it('should calculate md5 fs_file_md5.js', async function () {
|
|
7
|
-
const actual = await fs_file_md5(fs_path_resolve(__dirname, 'fs_file_md5.js'));
|
|
8
|
-
const expected = '103bffdc1df3af79bfd3f4b8b1bd2ed7';
|
|
9
|
-
assert.strictEqual(actual, expected);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/src/fs_mkdirp.test.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs_fi = require('./fs_fi');
|
|
3
|
-
const fs_mkdirp = require('./fs_mkdirp');
|
|
4
|
-
const fs_path_resolve = require('./fs_path_resolve');
|
|
5
|
-
const fs_tempdir = require('./fs_tempdir');
|
|
6
|
-
|
|
7
|
-
describe('fs_mkdirp', function () {
|
|
8
|
-
it('should accept empty array', async function () {
|
|
9
|
-
await fs_tempdir(async function (d) {
|
|
10
|
-
const tmp = fs_path_resolve(d, 'a/b/c/d/e');
|
|
11
|
-
await fs_mkdirp(tmp);
|
|
12
|
-
assert(await fs_fi(tmp).then(v => v.isDirectory()));
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
it('should create the same directory structure in parallel', async function () {
|
|
16
|
-
await fs_tempdir(async function (d) {
|
|
17
|
-
const tmp = fs_path_resolve(d, 'a/b/c/d/e/f/g/h');
|
|
18
|
-
await Promise.all(Array(10).fill(tmp).map(async function () {
|
|
19
|
-
await fs_mkdirp(tmp);
|
|
20
|
-
assert(await fs_fi(tmp).then(v => v.isDirectory()));
|
|
21
|
-
}));
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs_path_extname = require('./fs_path_extname');
|
|
3
|
-
|
|
4
|
-
const tests = [
|
|
5
|
-
['.', ''],
|
|
6
|
-
['..', ''],
|
|
7
|
-
['.foo', ''],
|
|
8
|
-
['..foo', '.foo'],
|
|
9
|
-
['.foo.bar', '.bar'],
|
|
10
|
-
['fs_path_extname.js', '.js'],
|
|
11
|
-
['/path/to/file.js', '.js'],
|
|
12
|
-
['/path/to/file.js/foo', ''],
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
describe('fs_path_extname', function () {
|
|
16
|
-
tests.forEach(function ([input, expected]) {
|
|
17
|
-
it(`${input} -> ${expected}`, function () {
|
|
18
|
-
const actual = fs_path_extname(input);
|
|
19
|
-
assert.strictEqual(actual, expected);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
package/src/gettype.test.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const const_type = require('./const_type');
|
|
3
|
-
const gettype = require('./gettype');
|
|
4
|
-
|
|
5
|
-
const items = [
|
|
6
|
-
['null', null, const_type.null],
|
|
7
|
-
['undefined', undefined, const_type.undefined],
|
|
8
|
-
['boolean', true, const_type.boolean],
|
|
9
|
-
['number', 1, const_type.number],
|
|
10
|
-
['bigint', 1n, const_type.bigint],
|
|
11
|
-
['nan', NaN, const_type.nan],
|
|
12
|
-
['-inf', Number.NEGATIVE_INFINITY, const_type.neg_inf],
|
|
13
|
-
['+inf', Number.POSITIVE_INFINITY, const_type.pos_inf],
|
|
14
|
-
['string', 's', const_type.string],
|
|
15
|
-
['symbol', Symbol(), const_type.symbol],
|
|
16
|
-
['function', () => 1, const_type.function],
|
|
17
|
-
['object', {}, const_type.object],
|
|
18
|
-
['array', [], const_type.array],
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
describe('gettype', function () {
|
|
22
|
-
items.forEach(function ([title, input, expected]) {
|
|
23
|
-
it(title, function () {
|
|
24
|
-
assert.deepStrictEqual(gettype(input), expected);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const object_schema = require('./object_schema');
|
|
3
|
-
|
|
4
|
-
describe('object_schema', function () {
|
|
5
|
-
it('basic 1', function () {
|
|
6
|
-
const actual = object_schema({aaa: 1, bbb: 2});
|
|
7
|
-
const expected = {aaa: 'number', bbb: 'number'};
|
|
8
|
-
assert.deepStrictEqual(actual, expected);
|
|
9
|
-
});
|
|
10
|
-
it('basic 2', function () {
|
|
11
|
-
const actual = object_schema({aaa: 1, bbb: [1, 2, 3, 4, 'str']});
|
|
12
|
-
const expected = {aaa: 'number', bbb: ['number', 'string']};
|
|
13
|
-
assert.deepStrictEqual(actual, expected);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const object_walk_preorder = require('./object_walk_preorder');
|
|
3
|
-
|
|
4
|
-
describe('object_walk_preorder', function () {
|
|
5
|
-
it('basic 1', function () {
|
|
6
|
-
const actual = [];
|
|
7
|
-
const expected = ['aaa', 'bbb', 'ccc'];
|
|
8
|
-
object_walk_preorder({aaa: 1, bbb: 2, ccc: 3}, (v,p) => actual.push(p.join('/')));
|
|
9
|
-
assert.deepStrictEqual(actual, expected);
|
|
10
|
-
});
|
|
11
|
-
it('basic 2', function () {
|
|
12
|
-
const actual = [];
|
|
13
|
-
const expected = ['aaa', 'aaa/foo', 'aaa/foo/bar', 'aaa/foo/bar/baz', 'bbb', 'ccc'];
|
|
14
|
-
object_walk_preorder({aaa: {foo: {bar: {baz: 1}}}, bbb: 2, ccc: 3}, (v,p) => actual.push(p.join('/')));
|
|
15
|
-
assert.deepStrictEqual(actual, expected);
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/parallel.test.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const parallel = require('./parallel');
|
|
3
|
-
|
|
4
|
-
describe('parallel', function () {
|
|
5
|
-
it('should reject when [spawn] is async function', function () {
|
|
6
|
-
assert.rejects(parallel({spawn: async function () {}}));
|
|
7
|
-
})
|
|
8
|
-
it('should reject when [spawn] is async generator', function () {
|
|
9
|
-
assert.rejects(parallel({spawn: async function* () {}}));
|
|
10
|
-
})
|
|
11
|
-
});
|
package/src/parse_bytes.test.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const parse_bytes = require('./parse_bytes');
|
|
3
|
-
|
|
4
|
-
const items = [
|
|
5
|
-
['', Number.NaN],
|
|
6
|
-
[null, Number.NaN],
|
|
7
|
-
[undefined, Number.NaN],
|
|
8
|
-
['0KB', 0],
|
|
9
|
-
['1KB', 1024],
|
|
10
|
-
['2KB', 2048],
|
|
11
|
-
['35.45MB', Math.floor(35.45*1024*1024)],
|
|
12
|
-
['3.92GB', Math.floor(3.92*1024*1024*1024)],
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
describe('parse_bytes', function () {
|
|
16
|
-
items.forEach(function ([input, expected]) {
|
|
17
|
-
it(`${input} → ${expected}`, function () {
|
|
18
|
-
assert.strictEqual(expected, parse_bytes(input));
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/parse_hms.test.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const parse_hms = require('./parse_hms');
|
|
3
|
-
|
|
4
|
-
const items = [
|
|
5
|
-
['', 0],
|
|
6
|
-
[null, 0],
|
|
7
|
-
[undefined, 0],
|
|
8
|
-
['0', 0],
|
|
9
|
-
['0:5', 5],
|
|
10
|
-
['00:05', 5],
|
|
11
|
-
['0:15', 15],
|
|
12
|
-
['0:15.123', 15.123],
|
|
13
|
-
['0:75.123', 75.123],
|
|
14
|
-
[' 5', 5],
|
|
15
|
-
[' 0:05 ', 5],
|
|
16
|
-
[100, 100],
|
|
17
|
-
['1:2:3:4', NaN, 'Too many segments'],
|
|
18
|
-
['abc', NaN, 'Non-numeric'],
|
|
19
|
-
['0:ab', NaN, 'Non-numeric'],
|
|
20
|
-
['1:x:3', NaN, 'Non-numeric'],
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
describe('parse_hms', function () {
|
|
24
|
-
items.forEach(function ([input, expected, description]) {
|
|
25
|
-
const title = description
|
|
26
|
-
? `${input} → ${expected} | ${description}`
|
|
27
|
-
: `${input} → ${expected}`;
|
|
28
|
-
it(title, function () {
|
|
29
|
-
assert.strictEqual(expected, parse_hms(input));
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const parse_http_content_range = require('./parse_http_content_range');
|
|
3
|
-
|
|
4
|
-
const items = [
|
|
5
|
-
['bytes 262144000-272629759/5037662208', {type: 'bytes', first: 262144000, last: 272629759, total: 5037662208}],
|
|
6
|
-
];
|
|
7
|
-
|
|
8
|
-
describe('parse_http_content_range', function () {
|
|
9
|
-
items.forEach(function ([expr, expected]) {
|
|
10
|
-
it(expr, function () {
|
|
11
|
-
assert.deepStrictEqual(parse_http_content_range(expr), expected);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const Promise = require('bluebird');
|
|
4
|
-
const cli = require('../cli');
|
|
5
|
-
const now_human = require('../now_human');
|
|
6
|
-
|
|
7
|
-
// Child ignores SIGTERM for 10 ms, but dies naturally before the grace loop ends
|
|
8
|
-
|
|
9
|
-
cli(main);
|
|
10
|
-
|
|
11
|
-
async function main()
|
|
12
|
-
{
|
|
13
|
-
let timer;
|
|
14
|
-
|
|
15
|
-
process.on('SIGTERM', function () {
|
|
16
|
-
console.log(`[${now_human()}][ignore-sigterm-for-10ms] SIGTERM_ignoring...`);
|
|
17
|
-
timer ??= setTimeout(terminate, 10);
|
|
18
|
-
});
|
|
19
|
-
process.on('SIGINT', function () {
|
|
20
|
-
console.log(`[${now_human()}][ignore-sigterm-for-10ms] SIGINT_ignoring...`);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
for (let iter = 1, last = 100; iter <= last; ++iter) {
|
|
24
|
-
console.log(`[${now_human()}][ignore-sigterm-for-10ms] ${iter} of ${last}`);
|
|
25
|
-
await Promise.delay(10);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function terminate()
|
|
30
|
-
{
|
|
31
|
-
console.log(`[${now_human()}][ignore-sigterm-for-10ms] TERMINATE_AFTER_10MS`);
|
|
32
|
-
process.exit(0);
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const Promise = require('bluebird');
|
|
4
|
-
const cli = require('../cli');
|
|
5
|
-
const now_human = require('../now_human');
|
|
6
|
-
|
|
7
|
-
cli(main);
|
|
8
|
-
|
|
9
|
-
async function main()
|
|
10
|
-
{
|
|
11
|
-
process.on('SIGTERM', function () {
|
|
12
|
-
console.log(`[${now_human()}][ignore-sigterm] SIGTERM_ignoring...`);
|
|
13
|
-
});
|
|
14
|
-
process.on('SIGINT', function () {
|
|
15
|
-
console.log(`[${now_human()}][ignore-sigterm] SIGINT_ignoring...`);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
for (let iter = 1, last = 100; iter <= last; ++iter) {
|
|
19
|
-
console.log(`[${now_human()}][ignore-sigterm] ${iter} of ${last}`);
|
|
20
|
-
await Promise.delay(10);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const pid_exists = require('./pid_exists');
|
|
3
|
-
const pid_kill_grace = require('./pid_kill_grace');
|
|
4
|
-
const shell_spawn = require('./shell_spawn');
|
|
5
|
-
const stream = require('stream');
|
|
6
|
-
const stream_each = require('./stream_each');
|
|
7
|
-
const stream_lines = require('./stream_lines');
|
|
8
|
-
const wait_while = require('./wait_while');
|
|
9
|
-
|
|
10
|
-
describe('pid_kill_grace', function() {
|
|
11
|
-
|
|
12
|
-
it('happy path', async function () {
|
|
13
|
-
const proc = await shell_spawn(['sleep', '1m']).init();
|
|
14
|
-
assert(pid_exists(proc.pid));
|
|
15
|
-
await pid_kill_grace(proc.pid);
|
|
16
|
-
assert(!pid_exists(proc.pid));
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// handling errors and edge cases
|
|
20
|
-
|
|
21
|
-
it('should throw "Failed to send SIGTERM to process 123"', async function () {
|
|
22
|
-
const pid = 999999; // 🎲 unlikely to exist
|
|
23
|
-
assert(!pid_exists(pid));
|
|
24
|
-
await assert.rejects(pid_kill_grace(pid), /Failed to send SIGTERM to process \d+:/);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it.skip('should throw "Process 123 survived SIGKILL"', async function () {
|
|
28
|
-
// How to implement this behavior?
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should KILL process after grace period', async function () {
|
|
32
|
-
const logs = [];
|
|
33
|
-
const stdout = [];
|
|
34
|
-
const proc = shell_spawn([`${__dirname}/pid_kill_grace.d/ignore-sigterm.js`]);
|
|
35
|
-
const r = stream.promises.pipeline(proc.stdout, stream_lines(), stream_each(v => stdout.push(v)));
|
|
36
|
-
await wait_while(() => !stdout.length);
|
|
37
|
-
await Promise.all([
|
|
38
|
-
r,
|
|
39
|
-
pid_kill_grace(proc.pid, {grace_timeout_ms: 50, log: s => logs.push(s)})
|
|
40
|
-
]);
|
|
41
|
-
assert(!pid_exists(proc.pid));
|
|
42
|
-
assert(stdout.some(v => v.includes('SIGTERM_ignoring')));
|
|
43
|
-
assert(logs.some(v => v.match(/Terminating process \d+: sending SIGTERM/)));
|
|
44
|
-
assert(logs.some(v => v.match(/SIGTERM grace period expired for process \d+; sending SIGKILL/)));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('Child ignores SIGTERM for 10ms, but dies naturally before the grace loop ends', async function () {
|
|
48
|
-
const logs = [];
|
|
49
|
-
const stdout = [];
|
|
50
|
-
const proc = shell_spawn([`${__dirname}/pid_kill_grace.d/ignore-sigterm-for-10ms.js`]);
|
|
51
|
-
const r = stream.promises.pipeline(proc.stdout, stream_lines(), stream_each(v => stdout.push(v)));
|
|
52
|
-
await wait_while(() => !stdout.length);
|
|
53
|
-
await Promise.all([
|
|
54
|
-
r,
|
|
55
|
-
pid_kill_grace(proc.pid, {grace_timeout_ms: 50, log: s => logs.push(s)})
|
|
56
|
-
]);
|
|
57
|
-
assert(!pid_exists(proc.pid));
|
|
58
|
-
assert(stdout.some(v => v.includes('SIGTERM_ignoring')));
|
|
59
|
-
assert(stdout.some(v => v.includes('TERMINATE_AFTER_10MS')));
|
|
60
|
-
assert(logs.some(v => v.match(/Terminating process \d+: sending SIGTERM/)));
|
|
61
|
-
assert(!logs.some(v => v.match(/SIGTERM grace period expired for process \d+; sending SIGKILL/)));
|
|
62
|
-
});
|
|
63
|
-
});
|
package/src/ping_socket.test.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const Promise = require('bluebird');
|
|
2
|
-
const assert = require('assert');
|
|
3
|
-
const fs_rmf = require('./fs_rmf');
|
|
4
|
-
const net = require('net');
|
|
5
|
-
const ping_socket = require('./ping_socket');
|
|
6
|
-
const random_hex = require('./random_hex');
|
|
7
|
-
|
|
8
|
-
const socket = '/tmp/ping_socket_test.sock';
|
|
9
|
-
|
|
10
|
-
describe('ping_socket', function () {
|
|
11
|
-
|
|
12
|
-
afterEach(async function () {
|
|
13
|
-
await fs_rmf(socket);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should receive exact string from server', async function () {
|
|
17
|
-
const uid = random_hex();
|
|
18
|
-
const server = net.createServer(client => client.resume().end(uid));
|
|
19
|
-
try {
|
|
20
|
-
await new Promise(resolve => server.listen(socket, resolve));
|
|
21
|
-
const buf = await ping_socket(socket);
|
|
22
|
-
assert.strictEqual(buf.toString(), uid);
|
|
23
|
-
}
|
|
24
|
-
finally {
|
|
25
|
-
await server_close(server);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should throw Socket Timeout', async function () {
|
|
30
|
-
const clients = [];
|
|
31
|
-
const server = net.createServer(client => clients.push(client));
|
|
32
|
-
try {
|
|
33
|
-
await new Promise(resolve => server.listen(socket, resolve));
|
|
34
|
-
await assert.rejects(ping_socket(socket, 'PING', 100), {message: 'Socket Timeout'});
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
clients.forEach(v => v.resume().end());
|
|
38
|
-
await server_close(server);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should throw ENOENT', async function () {
|
|
43
|
-
await assert.rejects(ping_socket(socket), {
|
|
44
|
-
code: 'ENOENT',
|
|
45
|
-
syscall: 'connect',
|
|
46
|
-
address: socket,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
async function server_close(server)
|
|
52
|
-
{
|
|
53
|
-
return new Promise(function (resolve, reject) {
|
|
54
|
-
server.close(function (error) {
|
|
55
|
-
error ? reject(error) : resolve();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
package/src/plural.test.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const plural = require('./plural');
|
|
3
|
-
|
|
4
|
-
const tests = [
|
|
5
|
-
['1 apple', 1, '# apple', '# apples'],
|
|
6
|
-
['2 apples', 2, '# apple', '# apples'],
|
|
7
|
-
['10 apples', 10, '# apple', '# apples'],
|
|
8
|
-
['21 apple', 21, '# apple', '# apples'],
|
|
9
|
-
['0 apples', 0, '# apple', '# apples'],
|
|
10
|
-
['No apples', 0, '# apple', '# apples', 'No apples'],
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
describe('plural', function () {
|
|
14
|
-
tests.forEach(function ([expected, ...args],) {
|
|
15
|
-
it(expected, function () {
|
|
16
|
-
const actual = plural(...args);
|
|
17
|
-
assert.deepStrictEqual(actual, expected);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
package/src/range.test.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const range = require('./range');
|
|
3
|
-
|
|
4
|
-
const cases = [
|
|
5
|
-
// 1-argument: (stop)
|
|
6
|
-
{args: [10], expected: [0,1,2,3,4,5,6,7,8,9]},
|
|
7
|
-
{args: [-10], expected: []}, // 💎 Consider non-standard semantics: range(-5) -> [0,-1,-2,-3,-4]
|
|
8
|
-
|
|
9
|
-
// 2-arguments: (start, stop)
|
|
10
|
-
{args: [3, 7], expected: [3,4,5,6]},
|
|
11
|
-
{args: [0, 0], expected: []},
|
|
12
|
-
{args: [5, 3], expected: []}, // positive direction, start > stop → empty
|
|
13
|
-
|
|
14
|
-
// 3-arguments: (start, stop, step)
|
|
15
|
-
{args: [3, 10, 2], expected: [3,5,7,9]},
|
|
16
|
-
{args: [3, 10, 3], expected: [3,6,9]},
|
|
17
|
-
|
|
18
|
-
// Negative step
|
|
19
|
-
{args: [10, 3, -2], expected: [10,8,6,4]},
|
|
20
|
-
{args: [10, 3, -3], expected: [10,7,4]},
|
|
21
|
-
|
|
22
|
-
// Negative step but no progression
|
|
23
|
-
{args: [3, 10, -1], expected: []}, // step direction does not match range
|
|
24
|
-
|
|
25
|
-
// Step = 1 edge
|
|
26
|
-
{args: [5, 5, 1], expected: []},
|
|
27
|
-
{args: [5, 6, 1], expected: [5]},
|
|
28
|
-
|
|
29
|
-
// Step = -1 edge
|
|
30
|
-
{args: [5, 5, -1], expected: []},
|
|
31
|
-
{args: [6, 5, -1], expected: [6]},
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
describe('range', function () {
|
|
35
|
-
cases.forEach(function (item, i) {
|
|
36
|
-
it(`range #${i+1}: ${JSON.stringify(item)}`, function () {
|
|
37
|
-
const actual = range(...item.args);
|
|
38
|
-
assert.deepStrictEqual(actual, item.expected);
|
|
39
|
-
})
|
|
40
|
-
});
|
|
41
|
-
});
|
package/src/redis_lshift.test.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const redis_lshift = require('./redis_lshift');
|
|
3
|
-
|
|
4
|
-
const REDIS_HOST = '127.0.0.1';
|
|
5
|
-
const REDIS_PORT = 6379;
|
|
6
|
-
const REDIS_AUTH = null;
|
|
7
|
-
const REDIS_QUEUE = 'TESTING';
|
|
8
|
-
|
|
9
|
-
describe('redis_lshift', function () {
|
|
10
|
-
it('should work with redis@1', async function () {
|
|
11
|
-
await test_1_2_3(require('redis-v1'));
|
|
12
|
-
});
|
|
13
|
-
it('should work with redis@2', async function () {
|
|
14
|
-
await test_1_2_3(require('redis-v2'));
|
|
15
|
-
});
|
|
16
|
-
it('should work with redis@3', async function () {
|
|
17
|
-
await test_1_2_3(require('redis-v3'));
|
|
18
|
-
});
|
|
19
|
-
it('should work with redis@4', async function () {
|
|
20
|
-
await test_4(require('redis-v4'));
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
async function test_1_2_3(redis)
|
|
25
|
-
{
|
|
26
|
-
const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
|
|
27
|
-
try {
|
|
28
|
-
const expected = 'aa,bb,cc,dd,ee'.split(',');
|
|
29
|
-
await new Promise(function (resolve, reject) {
|
|
30
|
-
r.del(REDIS_QUEUE, (e,v) => e ? reject(e) : resolve(v));
|
|
31
|
-
});
|
|
32
|
-
await new Promise(function (resolve, reject) {
|
|
33
|
-
r.rpush(REDIS_QUEUE, ...expected, (e,v) => e ? reject(e) : resolve(v));
|
|
34
|
-
});
|
|
35
|
-
const actual = await redis_lshift(r, REDIS_QUEUE, expected.length);
|
|
36
|
-
await assert.deepStrictEqual(actual, expected);
|
|
37
|
-
}
|
|
38
|
-
finally {
|
|
39
|
-
await r.quit();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function test_4(redis)
|
|
44
|
-
{
|
|
45
|
-
const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
|
|
46
|
-
await r.connect();
|
|
47
|
-
try {
|
|
48
|
-
const expected = 'aa,bb,cc,dd,ee'.split(',');
|
|
49
|
-
await r.DEL(REDIS_QUEUE);
|
|
50
|
-
await r.RPUSH(REDIS_QUEUE, expected);
|
|
51
|
-
const actual = await redis_lshift(r, REDIS_QUEUE, expected.length);
|
|
52
|
-
await assert.deepStrictEqual(actual, expected);
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
await r.quit();
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/redis_zshift.test.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const redis_zshift = require('./redis_zshift');
|
|
3
|
-
|
|
4
|
-
const REDIS_HOST = '127.0.0.1';
|
|
5
|
-
const REDIS_PORT = 6379;
|
|
6
|
-
const REDIS_AUTH = null;
|
|
7
|
-
const REDIS_QUEUE = 'TESTING';
|
|
8
|
-
|
|
9
|
-
describe('redis_zshift', function () {
|
|
10
|
-
it('should work with redis@1', async function () {
|
|
11
|
-
await test_1_2_3(require('redis-v1'));
|
|
12
|
-
});
|
|
13
|
-
it('should work with redis@2', async function () {
|
|
14
|
-
await test_1_2_3(require('redis-v2'));
|
|
15
|
-
});
|
|
16
|
-
it('should work with redis@3', async function () {
|
|
17
|
-
await test_1_2_3(require('redis-v3'));
|
|
18
|
-
});
|
|
19
|
-
it('should work with redis@4', async function () {
|
|
20
|
-
await test_4(require('redis-v4'));
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
async function test_1_2_3(redis)
|
|
25
|
-
{
|
|
26
|
-
const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
|
|
27
|
-
try {
|
|
28
|
-
const expected = 'aa,bb,cc,dd,ee'.split(',');
|
|
29
|
-
await new Promise(function (resolve, reject) {
|
|
30
|
-
r.del(REDIS_QUEUE, (e,v) => e ? reject(e) : resolve(v));
|
|
31
|
-
});
|
|
32
|
-
await new Promise(function (resolve, reject) {
|
|
33
|
-
const args = [REDIS_QUEUE, ...expected.map((v,i) => [i,v]).flat()];
|
|
34
|
-
r.zadd(args, (e,v) => e ? reject(e) : resolve(v));
|
|
35
|
-
});
|
|
36
|
-
const actual = await redis_zshift(r, REDIS_QUEUE, expected.length);
|
|
37
|
-
await assert.deepStrictEqual(actual, expected);
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
await r.quit();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function test_4(redis)
|
|
45
|
-
{
|
|
46
|
-
const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
|
|
47
|
-
await r.connect();
|
|
48
|
-
try {
|
|
49
|
-
const expected = 'aa,bb,cc,dd,ee'.split(',');
|
|
50
|
-
await r.DEL(REDIS_QUEUE);
|
|
51
|
-
await r.ZADD(REDIS_QUEUE, expected.map((value,i) => ({score: i, value})));
|
|
52
|
-
const actual = await redis_zshift(r, REDIS_QUEUE, 5);
|
|
53
|
-
await assert.deepStrictEqual(actual, expected);
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
await r.quit();
|
|
57
|
-
}
|
|
58
|
-
}
|
package/src/round.test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const round = require('./round');
|
|
3
|
-
|
|
4
|
-
const items = [
|
|
5
|
-
[34, 25, 25],
|
|
6
|
-
[37.5, 25, 50],
|
|
7
|
-
[34.037531, 0.001, 34.038],
|
|
8
|
-
[1.005, 0.01, 1.01],
|
|
9
|
-
[0.99999, 0.00001, 0.99999],
|
|
10
|
-
|
|
11
|
-
// Synthetic cases generated by DeepSeek
|
|
12
|
-
[1.005, 0.001, 1.005], // More precise rounding
|
|
13
|
-
[1.005, 0.1, 1.0], // Less precise rounding
|
|
14
|
-
[1.015, 0.01, 1.02], // Another edge case with 5
|
|
15
|
-
[1.025, 0.01, 1.03], // Yet another edge case
|
|
16
|
-
[0.5, 1, 1], // Round to nearest integer
|
|
17
|
-
[0.4, 1, 0], // Round down to integer
|
|
18
|
-
[123.456, 0.01, 123.46], // Standard decimal rounding
|
|
19
|
-
[123.456, 0.1, 123.5], // Different precision
|
|
20
|
-
[123.456, 1, 123], // Round to whole number
|
|
21
|
-
[123.456, 10, 120], // Round to tens
|
|
22
|
-
[123.456, 100, 100], // Round to hundreds
|
|
23
|
-
[0, 0.01, 0], // Zero value
|
|
24
|
-
[-1.005, 0.01, -1.01], // Negative numbers
|
|
25
|
-
[-1.015, 0.01, -1.02], // Negative edge case
|
|
26
|
-
[-37.5, 25, -50], // Negative with integer precision
|
|
27
|
-
[1.2345e-5, 1e-6, 0.000012], // Very small numbers
|
|
28
|
-
[999.999, 0.001, 999.999], // Rounding that causes carry-over
|
|
29
|
-
[0.0000000000001, 0.01, 0], // Extremely small number
|
|
30
|
-
[Number.MAX_SAFE_INTEGER, 1000, 9007199254741000], // Large numbers
|
|
31
|
-
|
|
32
|
-
[0.005, 0.01, 0.01],
|
|
33
|
-
[-1.5, 1, -2], // Symmetric negative rounding (Math.abs is critical here)
|
|
34
|
-
[-0.5, 1, -1], // Symmetric negative rounding for half
|
|
35
|
-
[123456789123.45, 1000, 123456789000], // Testing very large numbers
|
|
36
|
-
[1.2345e-20, 1e-20, 1e-20], // Testing very small numbers
|
|
37
|
-
[1.0000000000000001, 0.0000000000000001, 1.0000000000000000], // Testing rounding near Number.EPSILON range
|
|
38
|
-
|
|
39
|
-
[9007199254740992, 1, 9007199254740992],
|
|
40
|
-
[9007199254740991.5, 1, 9007199254740992],
|
|
41
|
-
[Number.MIN_SAFE_INTEGER, 1, Number.MIN_SAFE_INTEGER],
|
|
42
|
-
[Number.MAX_SAFE_INTEGER, 1, Number.MAX_SAFE_INTEGER],
|
|
43
|
-
|
|
44
|
-
// Out of scope of standard JS
|
|
45
|
-
// [0.004999999999999999, 0.01, 0.0],
|
|
46
|
-
// [Number.MIN_SAFE_INTEGER, 0.1, Number.MIN_SAFE_INTEGER],
|
|
47
|
-
// [Number.MAX_SAFE_INTEGER, 0.1, Number.MAX_SAFE_INTEGER],
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
describe('round', function () {
|
|
51
|
-
items.forEach(function ([value, precision, expected],) {
|
|
52
|
-
it(`${value} [${precision}] → ${expected}`, function () {
|
|
53
|
-
assert.deepStrictEqual(round(value, precision), expected);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|