performance-helpers 1.0.0 → 1.0.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 +12 -2
- package/package.json +146 -1
- package/src/index.js +1 -0
- package/.eslintrc.cjs +0 -22
- package/.nojekyll +0 -0
- package/.prettierrc +0 -6
- package/CONTRIBUTING.md +0 -178
- package/assets/1_Caching.md +0 -4
- package/assets/2_Parallelizing.md +0 -18
- package/assets/3_Logging.md +0 -3
- package/assets/404.md +0 -3
- package/assets/4_Utils.md +0 -10
- package/assets/logo.png +0 -0
- package/assets/navigation.md +0 -10
- package/bench/README.md +0 -97
- package/bench/results.json +0 -94
- package/bench/results.md +0 -233
- package/bench/run.js +0 -2639
- package/bench/worker.js +0 -43
- package/docs/README.md +0 -38
- package/docs/docs-typedoc.json +0 -38714
- package/docs/helpers/constants/README.md +0 -34
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_BACKOFF_MAX_MULTIPLIER.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_COOLDOWN_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_AUTOSCALE_MIN_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_BACKPRESSURE_QUEUE_CAPACITY.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_BACKPRESSURE_REFILL_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_BATCH_MAX_SIZE.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_CACHE_DEFAULT_TTL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_CACHE_MAX_POOL_SIZE.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_CACHE_MAX_WEIGHT_BYTES.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_HISTOGRAM_BUCKET_COUNT.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_HISTOGRAM_MAX_VALUE.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_MAX_CLEANUP_PER_TICK.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_QUEUE_CAPACITY.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_REAPER_MIN_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_REFILL_INTERVAL_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_RETRY_BASE_DELAY_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_RETRY_MAX_DELAY_MS.md +0 -9
- package/docs/helpers/constants/variables/DEFAULT_TIMEOUT_MS.md +0 -9
- package/docs/helpers/constants/variables/ENCODE_CACHE_LARGE_KEY_LENGTH.md +0 -9
- package/docs/helpers/constants/variables/MAX_DEEP_EQUAL_DEPTH.md +0 -9
- package/docs/helpers/constants/variables/MS_PER_MIN.md +0 -9
- package/docs/helpers/constants/variables/MS_PER_SEC.md +0 -9
- package/docs/helpers/constants/variables/default.md +0 -103
- package/docs/helpers/jsdoc-types/README.md +0 -33
- package/docs/helpers/jsdoc-types/interfaces/BufferDecoder.md +0 -23
- package/docs/helpers/jsdoc-types/interfaces/BufferEncoder.md +0 -23
- package/docs/helpers/jsdoc-types/interfaces/CacheNode.md +0 -43
- package/docs/helpers/jsdoc-types/interfaces/CommonPoolOptions.md +0 -31
- package/docs/helpers/jsdoc-types/interfaces/PendingResponseEntry.md +0 -51
- package/docs/helpers/jsdoc-types/interfaces/PostMessageOptions.md +0 -39
- package/docs/helpers/jsdoc-types/interfaces/PowerBatchOptions.md +0 -13
- package/docs/helpers/jsdoc-types/interfaces/PowerCacheOptions.md +0 -115
- package/docs/helpers/jsdoc-types/interfaces/PowerChunkingOptions.md +0 -31
- package/docs/helpers/jsdoc-types/interfaces/PowerCircuitOptions.md +0 -45
- package/docs/helpers/jsdoc-types/interfaces/PowerDeadlineOptions.md +0 -101
- package/docs/helpers/jsdoc-types/interfaces/PowerDeferOptions.md +0 -13
- package/docs/helpers/jsdoc-types/interfaces/PowerEventBusOptions.md +0 -19
- package/docs/helpers/jsdoc-types/interfaces/PowerLatchOptions.md +0 -23
- package/docs/helpers/jsdoc-types/interfaces/PowerLoggerOptions.md +0 -51
- package/docs/helpers/jsdoc-types/interfaces/PowerObserverOptions.md +0 -25
- package/docs/helpers/jsdoc-types/interfaces/PowerPoolOptions.md +0 -85
- package/docs/helpers/jsdoc-types/interfaces/PowerQueueOptions.md +0 -13
- package/docs/helpers/jsdoc-types/interfaces/PowerRetryOptions.md +0 -83
- package/docs/helpers/jsdoc-types/interfaces/PowerSlidingWindowOptions.md +0 -19
- package/docs/helpers/jsdoc-types/interfaces/PowerTTLMapOptions.md +0 -27
- package/docs/helpers/jsdoc-types/interfaces/PowerThrottleOptions.md +0 -31
- package/docs/helpers/jsdoc-types/interfaces/WorkerObj.md +0 -55
- package/docs/helpers/powerBackpressure/README.md +0 -17
- package/docs/helpers/powerBackpressure/classes/PowerBackpressure.md +0 -368
- package/docs/helpers/powerBatch/README.md +0 -17
- package/docs/helpers/powerBatch/classes/PowerBatch.md +0 -139
- package/docs/helpers/powerBuffer/README.md +0 -26
- package/docs/helpers/powerBuffer/functions/b2o.md +0 -25
- package/docs/helpers/powerBuffer/functions/o2b.md +0 -23
- package/docs/helpers/powerBuffer/functions/o2u8.md +0 -33
- package/docs/helpers/powerBuffer/functions/u82o.md +0 -30
- package/docs/helpers/powerBulkhead/README.md +0 -17
- package/docs/helpers/powerBulkhead/classes/PowerBulkhead.md +0 -302
- package/docs/helpers/powerCache/README.md +0 -29
- package/docs/helpers/powerCache/classes/PowerCache.md +0 -933
- package/docs/helpers/powerCache/classes/PowerMemoizer.md +0 -244
- package/docs/helpers/powerCache/classes/PowerTimedCache.md +0 -302
- package/docs/helpers/powerCache/functions/simpleArgsKey.md +0 -31
- package/docs/helpers/powerChunking/README.md +0 -17
- package/docs/helpers/powerChunking/classes/PowerChunker.md +0 -78
- package/docs/helpers/powerCircuit/README.md +0 -23
- package/docs/helpers/powerCircuit/classes/PowerCircuit.md +0 -167
- package/docs/helpers/powerDeadline/README.md +0 -23
- package/docs/helpers/powerDeadline/classes/PowerDeadline.md +0 -88
- package/docs/helpers/powerDefer/README.md +0 -17
- package/docs/helpers/powerDefer/classes/PowerDefer.md +0 -134
- package/docs/helpers/powerEventBus/README.md +0 -23
- package/docs/helpers/powerEventBus/classes/PowerEventBus.md +0 -330
- package/docs/helpers/powerHistogram/README.md +0 -17
- package/docs/helpers/powerHistogram/classes/PowerHistogram.md +0 -285
- package/docs/helpers/powerLatch/README.md +0 -17
- package/docs/helpers/powerLatch/classes/PowerLatch.md +0 -264
- package/docs/helpers/powerLogger/README.md +0 -17
- package/docs/helpers/powerLogger/classes/PowerLogger.md +0 -290
- package/docs/helpers/powerObserver/README.md +0 -23
- package/docs/helpers/powerObserver/classes/PowerObserver.md +0 -213
- package/docs/helpers/powerPermitGate/README.md +0 -11
- package/docs/helpers/powerPermitGate/classes/PowerPermitGate.md +0 -248
- package/docs/helpers/powerPool/README.md +0 -36
- package/docs/helpers/powerPool/classes/PowerPool.md +0 -973
- package/docs/helpers/powerPool/classes/PowerPoolShutdownError.md +0 -67
- package/docs/helpers/powerQueue/README.md +0 -11
- package/docs/helpers/powerQueue/classes/PowerQueue.md +0 -302
- package/docs/helpers/powerRateLimit/README.md +0 -17
- package/docs/helpers/powerRateLimit/classes/PowerRateLimit.md +0 -187
- package/docs/helpers/powerRetry/README.md +0 -23
- package/docs/helpers/powerRetry/classes/PowerRetry.md +0 -106
- package/docs/helpers/powerScheduler/README.md +0 -11
- package/docs/helpers/powerScheduler/classes/PowerScheduler.md +0 -135
- package/docs/helpers/powerSemaphore/README.md +0 -17
- package/docs/helpers/powerSemaphore/classes/PowerSemaphore.md +0 -173
- package/docs/helpers/powerSlidingWindow/README.md +0 -11
- package/docs/helpers/powerSlidingWindow/classes/PowerSlidingWindow.md +0 -83
- package/docs/helpers/powerSubscriberSet/README.md +0 -15
- package/docs/helpers/powerSubscriberSet/classes/PowerSubscriberSet.md +0 -251
- package/docs/helpers/powerSubscriberSet/functions/cleanupWeakRefs.md +0 -21
- package/docs/helpers/powerTTLMap/README.md +0 -17
- package/docs/helpers/powerTTLMap/classes/PowerTTLMap.md +0 -326
- package/docs/helpers/powerThrottle/README.md +0 -17
- package/docs/helpers/powerThrottle/classes/PowerThrottle.md +0 -216
- package/docs/index/README.md +0 -205
- package/docs/utils/errors/README.md +0 -12
- package/docs/utils/errors/functions/formatErrorObj.md +0 -30
- package/docs/utils/errors/functions/normalizeError.md +0 -50
- package/docs/utils/now/README.md +0 -19
- package/docs/utils/now/functions/measureAsync.md +0 -37
- package/docs/utils/now/functions/measureSync.md +0 -54
- package/docs/utils/now/functions/nowMs.md +0 -24
- package/guides/autoscale.md +0 -80
- package/guides/errors.md +0 -41
- package/guides/metaGuide.md +0 -440
- package/guides/now.md +0 -56
- package/guides/powerBackpressure.md +0 -110
- package/guides/powerBatch.md +0 -82
- package/guides/powerBuffer.md +0 -86
- package/guides/powerBulkhead.md +0 -61
- package/guides/powerCache.md +0 -269
- package/guides/powerChunking.md +0 -130
- package/guides/powerCircuit.md +0 -84
- package/guides/powerDeadline.md +0 -99
- package/guides/powerDefer.md +0 -56
- package/guides/powerEventBus.md +0 -89
- package/guides/powerHistogram.md +0 -71
- package/guides/powerLatch.md +0 -94
- package/guides/powerLogger.md +0 -129
- package/guides/powerObserver.md +0 -65
- package/guides/powerPermitGate.md +0 -52
- package/guides/powerPool.md +0 -321
- package/guides/powerQueue.md +0 -112
- package/guides/powerRateLimit.md +0 -37
- package/guides/powerRetry.md +0 -54
- package/guides/powerScheduler.md +0 -41
- package/guides/powerSemaphore.md +0 -65
- package/guides/powerSlidingWindow.md +0 -63
- package/guides/powerSubscriberSet.md +0 -48
- package/guides/powerTTLMap.md +0 -58
- package/guides/powerThrottle.md +0 -152
- package/index.html +0 -57
- package/results.json +0 -6692
- package/scripts/find-missing-jsdoc.js +0 -62
- package/scripts/modernize-optional-chaining.cjs +0 -36
- package/scripts/pool-debug.mjs +0 -29
- package/scripts/repro_powercache.js +0 -14
- package/scripts/static-audit-exports.cjs +0 -93
- package/scripts/static-audit-exports.json +0 -518
- package/test/powerBackpressure.test.js +0 -114
- package/test/powerBatch.branches.extra.test.js +0 -122
- package/test/powerBatch.test.js +0 -79
- package/test/powerBuffer.test.js +0 -125
- package/test/powerBulkhead.test.js +0 -210
- package/test/powerCache.branches.test.js +0 -233
- package/test/powerCache.bulk.test.js +0 -31
- package/test/powerCache.getorset.test.js +0 -110
- package/test/powerCache.hitRate.test.js +0 -35
- package/test/powerCache.inflight.test.js +0 -24
- package/test/powerCache.iterator.test.js +0 -18
- package/test/powerCache.misses.test.js +0 -52
- package/test/powerCache.more.test.js +0 -118
- package/test/powerCache.test.js +0 -37
- package/test/powerCache.timeout.test.js +0 -25
- package/test/powerCache.touch.test.js +0 -46
- package/test/powerChunking.branches.extra.test.js +0 -155
- package/test/powerChunking.errors.test.js +0 -177
- package/test/powerChunking.test.js +0 -39
- package/test/powerCircuit.observability.test.js +0 -71
- package/test/powerCircuit.test.js +0 -74
- package/test/powerDeadline.test.js +0 -140
- package/test/powerDefer.test.js +0 -55
- package/test/powerErrors.test.js +0 -32
- package/test/powerEventBus.branches.extra.test.js +0 -70
- package/test/powerEventBus.extra.test.js +0 -72
- package/test/powerEventBus.max.test.js +0 -43
- package/test/powerEventBus.more.test.js +0 -121
- package/test/powerEventBus.once_off.test.js +0 -17
- package/test/powerEventBus.test.js +0 -74
- package/test/powerEventBus.uncovered.test.js +0 -57
- package/test/powerEventBus.weak.test.js +0 -18
- package/test/powerHistogram.test.js +0 -73
- package/test/powerLatch.branches.extra.test.js +0 -115
- package/test/powerLatch.test.js +0 -57
- package/test/powerLogger.branches.test.js +0 -98
- package/test/powerLogger.formatter.name.test.js +0 -58
- package/test/powerLogger.json.test.js +0 -88
- package/test/powerLogger.output.test.js +0 -81
- package/test/powerLogger.table.debug.test.js +0 -77
- package/test/powerLogger.test.js +0 -59
- package/test/powerMemoizer.memoize.test.js +0 -100
- package/test/powerMemoizer.test.js +0 -85
- package/test/powerObserver.test.js +0 -129
- package/test/powerPermitGate.test.js +0 -66
- package/test/powerPool.autoTransfer.test.js +0 -100
- package/test/powerPool.autoscale.extra.test.js +0 -88
- package/test/powerPool.autoscale.test.js +0 -136
- package/test/powerPool.awaitDefaultTimeout.test.js +0 -52
- package/test/powerPool.awaitTimeout.test.js +0 -22
- package/test/powerPool.batch.test.js +0 -170
- package/test/powerPool.branches.extra2.test.js +0 -42
- package/test/powerPool.branches.test.js +0 -102
- package/test/powerPool.browser.messageerror.test.js +0 -45
- package/test/powerPool.correlation.test.js +0 -26
- package/test/powerPool.correlationId.test.js +0 -63
- package/test/powerPool.dispose.test.js +0 -49
- package/test/powerPool.drain.test.js +0 -57
- package/test/powerPool.events.test.js +0 -131
- package/test/powerPool.more.extra.test.js +0 -99
- package/test/powerPool.more.test.js +0 -283
- package/test/powerPool.node.messageerror.test.js +0 -46
- package/test/powerPool.postMessage.promise.test.js +0 -83
- package/test/powerPool.queueHigh.test.js +0 -55
- package/test/powerPool.queueSaturation.test.js +0 -51
- package/test/powerPool.rapidResize.test.js +0 -55
- package/test/powerPool.resize.overload.test.js +0 -65
- package/test/powerPool.resize.test.js +0 -70
- package/test/powerPool.shutdown.test.js +0 -38
- package/test/powerPool.stats.test.js +0 -40
- package/test/powerPool.stopThePress.test.js +0 -94
- package/test/powerPool.terminateShutdown.test.js +0 -22
- package/test/powerPool.test.js +0 -525
- package/test/powerPool.timers.test.js +0 -55
- package/test/powerPool.uncovered.test.js +0 -407
- package/test/powerPool.workerId.test.js +0 -47
- package/test/powerQueue.iterators.test.js +0 -67
- package/test/powerQueue.saturation.test.js +0 -18
- package/test/powerQueue.test.js +0 -48
- package/test/powerQueue.unshiftMany.test.js +0 -49
- package/test/powerRateLimit.atomic.test.js +0 -80
- package/test/powerRateLimit.extra.test.js +0 -145
- package/test/powerRateLimit.functions.test.js +0 -106
- package/test/powerRateLimit.test.js +0 -38
- package/test/powerRetry.attemptTimeout.test.js +0 -51
- package/test/powerRetry.test.js +0 -121
- package/test/powerScheduler.test.js +0 -126
- package/test/powerSemaphore.test.js +0 -108
- package/test/powerSlidingWindow.pool.test.js +0 -55
- package/test/powerSlidingWindow.test.js +0 -25
- package/test/powerSubscriberSet.test.js +0 -125
- package/test/powerTTLMap.test.js +0 -125
- package/test/powerThrottle.pool.test.js +0 -54
- package/test/powerThrottle.refill.test.js +0 -22
- package/test/powerThrottle.reserve.test.js +0 -46
- package/test/powerThrottle.test.js +0 -45
- package/test/powerTimedCache.test.js +0 -73
- package/test/umd.bundle.branches.test.js +0 -100
- package/test/umd.bundle.cache-timers.test.js +0 -48
- package/test/umd.bundle.exhaustive.test.js +0 -158
- package/test/umd.bundle.fuzz.test.js +0 -86
- package/test/umd.bundle.hasEqual.more.test.js +0 -68
- package/test/umd.bundle.hasEqual.test.js +0 -104
- package/test/umd.bundle.logger-extra.test.js +0 -48
- package/test/umd.bundle.more-coverage-2.test.js +0 -67
- package/test/umd.bundle.pool.test.js +0 -134
- package/test/umd.bundle.test.js +0 -265
- package/test/utils.measure.test.js +0 -49
- package/test/utils.now.extra.test.js +0 -30
- package/test/utils.now.more.test.js +0 -57
- package/tsconfig.json +0 -16
- package/typedoc.json +0 -25
- package/vite.config.js +0 -31
- package/vitest.config.js +0 -17
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
describe('UMD bundle - branches', () => {
|
|
8
|
-
it('loads under CommonJS (module.exports) branch and encodes/decodes via Buffer when TextEncoder missing', () => {
|
|
9
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
10
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
11
|
-
const code = readFileSync(distFile, 'utf8');
|
|
12
|
-
|
|
13
|
-
const sandbox = { console, setTimeout, clearTimeout, setInterval, clearInterval };
|
|
14
|
-
// Provide Buffer and Uint8Array but intentionally omit TextEncoder/TextDecoder
|
|
15
|
-
sandbox.Buffer = Buffer;
|
|
16
|
-
sandbox.Uint8Array = Uint8Array;
|
|
17
|
-
// Provide CommonJS globals
|
|
18
|
-
sandbox.module = { exports: {} };
|
|
19
|
-
sandbox.exports = sandbox.module.exports;
|
|
20
|
-
|
|
21
|
-
const ctx = vm.createContext(sandbox);
|
|
22
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
23
|
-
|
|
24
|
-
const lib = sandbox.module.exports;
|
|
25
|
-
expect(lib).toBeDefined();
|
|
26
|
-
expect(typeof lib.PowerCache).toBe('function');
|
|
27
|
-
|
|
28
|
-
// Check encode/decode using Buffer path (since TextEncoder undefined)
|
|
29
|
-
const encoded = lib.o2u8({ foo: 'bar' });
|
|
30
|
-
expect(encoded).toBeInstanceOf(Uint8Array);
|
|
31
|
-
const decoded = lib.u82o(encoded);
|
|
32
|
-
expect(decoded).toEqual({ foo: 'bar' });
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('loads under AMD (define.amd) branch', () => {
|
|
36
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
37
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
38
|
-
const code = readFileSync(distFile, 'utf8');
|
|
39
|
-
|
|
40
|
-
const sandbox = {
|
|
41
|
-
console,
|
|
42
|
-
setTimeout,
|
|
43
|
-
clearTimeout,
|
|
44
|
-
setInterval,
|
|
45
|
-
clearInterval,
|
|
46
|
-
globalThis: {},
|
|
47
|
-
};
|
|
48
|
-
// implement AMD define
|
|
49
|
-
sandbox.__amd = null;
|
|
50
|
-
sandbox.define = function (deps, factory) {
|
|
51
|
-
const exports = {};
|
|
52
|
-
factory(exports);
|
|
53
|
-
sandbox.__amd = exports;
|
|
54
|
-
};
|
|
55
|
-
sandbox.define.amd = true;
|
|
56
|
-
|
|
57
|
-
const ctx = vm.createContext(sandbox);
|
|
58
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
59
|
-
|
|
60
|
-
const lib = sandbox.__amd;
|
|
61
|
-
expect(lib).toBeDefined();
|
|
62
|
-
expect(typeof lib.PowerPool).toBe('function');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('throws when no TextEncoder or Buffer is available for o2u8', () => {
|
|
66
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
67
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
68
|
-
const code = readFileSync(distFile, 'utf8');
|
|
69
|
-
|
|
70
|
-
const sandbox = {
|
|
71
|
-
console,
|
|
72
|
-
setTimeout,
|
|
73
|
-
clearTimeout,
|
|
74
|
-
setInterval,
|
|
75
|
-
clearInterval,
|
|
76
|
-
globalThis: {},
|
|
77
|
-
};
|
|
78
|
-
// ensure no TextEncoder and no Buffer
|
|
79
|
-
sandbox.TextEncoder = undefined;
|
|
80
|
-
sandbox.TextDecoder = undefined;
|
|
81
|
-
sandbox.Buffer = undefined;
|
|
82
|
-
sandbox.module = { exports: {} };
|
|
83
|
-
sandbox.exports = sandbox.module.exports;
|
|
84
|
-
|
|
85
|
-
const ctx = vm.createContext(sandbox);
|
|
86
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
87
|
-
|
|
88
|
-
const lib = sandbox.module.exports;
|
|
89
|
-
expect(lib).toBeDefined();
|
|
90
|
-
|
|
91
|
-
// calling o2u8 should throw due to missing encoders
|
|
92
|
-
let threw = false;
|
|
93
|
-
try {
|
|
94
|
-
lib.o2u8({ x: 1 });
|
|
95
|
-
} catch (e) {
|
|
96
|
-
threw = true;
|
|
97
|
-
}
|
|
98
|
-
expect(threw).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle PowerCache timer branches', () => {
|
|
12
|
-
it('startCleanup accepts numeric interval and options object', () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
globalThis: {},
|
|
22
|
-
};
|
|
23
|
-
sandbox.window = sandbox.globalThis;
|
|
24
|
-
sandbox.self = sandbox.globalThis;
|
|
25
|
-
sandbox.global = sandbox.globalThis;
|
|
26
|
-
|
|
27
|
-
const ctx = vm.createContext(sandbox);
|
|
28
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
29
|
-
|
|
30
|
-
const res = vm.runInContext(
|
|
31
|
-
`(function(){
|
|
32
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
33
|
-
const cache = new lib.PowerCache({ maxEntries: 5, defaultTTL: 10 })
|
|
34
|
-
// numeric interval
|
|
35
|
-
cache.startCleanup(1)
|
|
36
|
-
cache.stopCleanup()
|
|
37
|
-
// options object
|
|
38
|
-
cache.startCleanup({ interval: 1, maxCleanupPerTick: 2 })
|
|
39
|
-
cache.stopCleanup()
|
|
40
|
-
return true
|
|
41
|
-
})()`,
|
|
42
|
-
ctx,
|
|
43
|
-
{ filename: distFile }
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
expect(res).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle exhaustive branches', () => {
|
|
12
|
-
it('global context with TextEncoder/TextDecoder exercises many APIs', async () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
globalThis: {},
|
|
22
|
-
};
|
|
23
|
-
sandbox.window = sandbox.globalThis;
|
|
24
|
-
sandbox.self = sandbox.globalThis;
|
|
25
|
-
sandbox.global = sandbox.globalThis;
|
|
26
|
-
|
|
27
|
-
const ctx = vm.createContext(sandbox);
|
|
28
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
29
|
-
|
|
30
|
-
const lib =
|
|
31
|
-
sandbox.globalThis.PerformanceHelpers ||
|
|
32
|
-
sandbox.globalThis.performanceHelpers ||
|
|
33
|
-
sandbox.PerformanceHelpers ||
|
|
34
|
-
sandbox.performanceHelpers;
|
|
35
|
-
expect(lib).toBeDefined();
|
|
36
|
-
|
|
37
|
-
// Buffer/encoding paths (TextEncoder present) -> o2u8/u82o roundtrip (do full roundtrip inside VM)
|
|
38
|
-
const obj = { hello: 'world' };
|
|
39
|
-
const round = vm.runInContext(
|
|
40
|
-
`(function(){ const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers; const u8 = lib.o2u8(${JSON.stringify(obj)}); return lib.u82o(u8); })()`,
|
|
41
|
-
ctx,
|
|
42
|
-
{ filename: distFile }
|
|
43
|
-
);
|
|
44
|
-
expect(round).toEqual(obj);
|
|
45
|
-
|
|
46
|
-
// b2o/o2b conversions
|
|
47
|
-
// perform ArrayBuffer roundtrip inside the VM to avoid cross-realm checks
|
|
48
|
-
vm.runInContext(
|
|
49
|
-
`(function(){ const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers; lib.o2b(${JSON.stringify(obj)}); return true })()`,
|
|
50
|
-
ctx,
|
|
51
|
-
{ filename: distFile }
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// PowerLogger: enable verbose and call with lazy-throwing functions
|
|
55
|
-
const logger = new lib.PowerLogger(3);
|
|
56
|
-
expect(typeof logger.setDebugLevel).toBe('function');
|
|
57
|
-
// call with a lazy function that throws; should not propagate
|
|
58
|
-
logger.info(
|
|
59
|
-
() => 'ok',
|
|
60
|
-
() => {
|
|
61
|
-
throw new Error('boom-in-lazy');
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
logger.warn('plain', () => 'value');
|
|
65
|
-
|
|
66
|
-
// PowerCache basic ops
|
|
67
|
-
const cache = new lib.PowerCache({ maxEntries: 3 });
|
|
68
|
-
cache.set('a', 1);
|
|
69
|
-
expect(cache.get('a')).toBe(1);
|
|
70
|
-
cache.set('b', 2);
|
|
71
|
-
expect(cache.has('b')).toBe(true);
|
|
72
|
-
cache.delete('b');
|
|
73
|
-
expect(cache.has('b')).toBe(false);
|
|
74
|
-
|
|
75
|
-
// PowerMemoizer: sync and async caching behavior
|
|
76
|
-
const syncFn = (x) => x * 2;
|
|
77
|
-
const memoSync = new lib.PowerMemoizer(syncFn, { cacheOptions: { maxEntries: 10 } });
|
|
78
|
-
const callSync = typeof memoSync === 'function' ? memoSync : (...args) => memoSync.run(...args);
|
|
79
|
-
expect(callSync(2)).toBe(4);
|
|
80
|
-
expect(callSync(2)).toBe(4);
|
|
81
|
-
|
|
82
|
-
const asyncFn = async (n) => n + 1;
|
|
83
|
-
const memoAsync = new lib.PowerMemoizer(asyncFn, { cacheOptions: { maxEntries: 10 } });
|
|
84
|
-
const callAsync =
|
|
85
|
-
typeof memoAsync === 'function' ? memoAsync : (...args) => memoAsync.run(...args);
|
|
86
|
-
const p1 = callAsync(3);
|
|
87
|
-
const p2 = callAsync(3);
|
|
88
|
-
expect(p1).toBe(p2);
|
|
89
|
-
const res = await p1;
|
|
90
|
-
expect(res).toBe(4);
|
|
91
|
-
|
|
92
|
-
// PowerPool: use mock underlying to exercise encode path
|
|
93
|
-
vm.runInContext(
|
|
94
|
-
`(function(){
|
|
95
|
-
class MockUnderlying {
|
|
96
|
-
constructor(){ this.onmessage=null; this.postMessageCalls=[] }
|
|
97
|
-
postMessage(msg, transfer){ this.postMessageCalls.push(msg); setTimeout(()=>{ if(this.onmessage) this.onmessage({ data: msg }) }, 0) }
|
|
98
|
-
addEventListener(t, cb){ if(t==='message') this.onmessage = cb }
|
|
99
|
-
terminate(){ this.__terminated = true }
|
|
100
|
-
}
|
|
101
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
102
|
-
const pool = new lib.PowerPool(MockUnderlying, { size: 1, idleTimeout: 1000, maxTasksPerWorker: 1, taskQueue: true })
|
|
103
|
-
this.__p = pool
|
|
104
|
-
this.__r = []
|
|
105
|
-
pool.onmessage = (e) => { this.__r.push(e.data) }
|
|
106
|
-
pool.postMessage({ ping: 'pong' })
|
|
107
|
-
return true
|
|
108
|
-
})()`,
|
|
109
|
-
ctx,
|
|
110
|
-
{ filename: distFile }
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// allow async replies
|
|
114
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
115
|
-
const summary = vm.runInContext(
|
|
116
|
-
`(function(){
|
|
117
|
-
const count = (this.__r && this.__r.length) || 0
|
|
118
|
-
const underlying = (this.__p && this.__p.workers && this.__p.workers[0] && this.__p.workers[0]._underlying) || (this.__p && this.__p.workers && this.__p.workers[0] && this.__p.workers[0].worker && this.__p.workers[0].worker._underlying)
|
|
119
|
-
const postArg = underlying && underlying.postMessageCalls && underlying.postMessageCalls[0]
|
|
120
|
-
return { count, postArg }
|
|
121
|
-
})()`,
|
|
122
|
-
ctx,
|
|
123
|
-
{ filename: distFile }
|
|
124
|
-
);
|
|
125
|
-
expect(summary.count).toBeGreaterThanOrEqual(1);
|
|
126
|
-
expect(summary.postArg).not.toBeNull();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('CommonJS/module.exports path with Buffer fallback exercises Buffer encoder path', () => {
|
|
130
|
-
const sandbox = { console, setTimeout, clearTimeout, setInterval, clearInterval };
|
|
131
|
-
// remove TextEncoder/TextDecoder to force Buffer fallback
|
|
132
|
-
sandbox.TextEncoder = undefined;
|
|
133
|
-
sandbox.TextDecoder = undefined;
|
|
134
|
-
sandbox.Buffer = Buffer;
|
|
135
|
-
sandbox.module = { exports: {} };
|
|
136
|
-
sandbox.exports = sandbox.module.exports;
|
|
137
|
-
|
|
138
|
-
const ctx = vm.createContext(sandbox);
|
|
139
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
140
|
-
|
|
141
|
-
const lib = sandbox.module.exports;
|
|
142
|
-
expect(lib).toBeDefined();
|
|
143
|
-
|
|
144
|
-
// Buffer-based encoding should work when TextEncoder absent
|
|
145
|
-
const obj = { x: 1 };
|
|
146
|
-
// run encode/decode entirely inside the VM to avoid cross-realm instanceof failures
|
|
147
|
-
const decoded = vm.runInContext(
|
|
148
|
-
`(function(){ const lib = module.exports; const u8 = lib.o2u8(${JSON.stringify(obj)}); return lib.u82o(u8); })()`,
|
|
149
|
-
ctx,
|
|
150
|
-
{ filename: distFile }
|
|
151
|
-
);
|
|
152
|
-
expect(decoded).toEqual(obj);
|
|
153
|
-
|
|
154
|
-
// logger still functions
|
|
155
|
-
const logger = new lib.PowerLogger(2);
|
|
156
|
-
logger.error(() => 'err', 'plain');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle broader exercise', () => {
|
|
12
|
-
it('runs a wide set of operations to exercise branches', () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
Buffer: global.Buffer,
|
|
22
|
-
globalThis: {},
|
|
23
|
-
};
|
|
24
|
-
sandbox.window = sandbox.globalThis;
|
|
25
|
-
sandbox.self = sandbox.globalThis;
|
|
26
|
-
sandbox.global = sandbox.globalThis;
|
|
27
|
-
|
|
28
|
-
const ctx = vm.createContext(sandbox);
|
|
29
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
30
|
-
|
|
31
|
-
const res = vm.runInContext(
|
|
32
|
-
`(function(){
|
|
33
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
34
|
-
const cache = new lib.PowerCache({ maxEntries: 50, maxWeight: 1000 })
|
|
35
|
-
|
|
36
|
-
// circular object to make JSON.stringify throw
|
|
37
|
-
const a = { }
|
|
38
|
-
a.self = a
|
|
39
|
-
try { cache.set('circ', a) } catch(e){}
|
|
40
|
-
|
|
41
|
-
// object with toJSON throwing
|
|
42
|
-
const bad = { toJSON(){ throw new Error('bad') } }
|
|
43
|
-
try { cache.set('bad', bad) } catch(e){}
|
|
44
|
-
|
|
45
|
-
// DataView
|
|
46
|
-
const buf = new ArrayBuffer(8);
|
|
47
|
-
const dv = new DataView(buf);
|
|
48
|
-
dv.setUint8(0, 42);
|
|
49
|
-
cache.set('dv', dv);
|
|
50
|
-
const dvOk = cache.hasEqual('dv', new DataView(buf));
|
|
51
|
-
|
|
52
|
-
// Buffer (Node)
|
|
53
|
-
const bufNode = Buffer.from([1,2,3]);
|
|
54
|
-
cache.set('nodebuf', bufNode);
|
|
55
|
-
const bufOk = cache.hasEqual('nodebuf', Buffer.from([1,2,3]));
|
|
56
|
-
|
|
57
|
-
// Map/Set edgecases
|
|
58
|
-
const m = new Map([[{k:1}, 2]]);
|
|
59
|
-
cache.set('m2', m);
|
|
60
|
-
const s = new Set([1,2,3]);
|
|
61
|
-
cache.set('s2', s);
|
|
62
|
-
|
|
63
|
-
// Pool interactions: create a mock worker factory
|
|
64
|
-
const WorkerCtor = function(){
|
|
65
|
-
this.postMessage = (msg, transfer)=>{}
|
|
66
|
-
this.addEventListener = ()=>{}
|
|
67
|
-
this.removeEventListener = ()=>{}
|
|
68
|
-
this.terminate = ()=>{}
|
|
69
|
-
this.onmessage = null
|
|
70
|
-
this.onerror = null
|
|
71
|
-
this.onmessageerror = null
|
|
72
|
-
}
|
|
73
|
-
const pool = new lib.PowerPool(WorkerCtor)
|
|
74
|
-
const posted = pool.postMessage({a:1})
|
|
75
|
-
|
|
76
|
-
return { dvOk, bufOk, posted }
|
|
77
|
-
})()`,
|
|
78
|
-
ctx,
|
|
79
|
-
{ filename: distFile }
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
expect(res.dvOk).toBe(true);
|
|
83
|
-
expect(res.bufOk).toBe(true);
|
|
84
|
-
expect(res.posted).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle additional deep-equality branches', () => {
|
|
12
|
-
it('handles prototype mismatches and primitive set fast-path', () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
globalThis: {},
|
|
22
|
-
};
|
|
23
|
-
sandbox.window = sandbox.globalThis;
|
|
24
|
-
sandbox.self = sandbox.globalThis;
|
|
25
|
-
sandbox.global = sandbox.globalThis;
|
|
26
|
-
|
|
27
|
-
const ctx = vm.createContext(sandbox);
|
|
28
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
29
|
-
|
|
30
|
-
const result = vm.runInContext(
|
|
31
|
-
`(function(){
|
|
32
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
33
|
-
const cache = new lib.PowerCache({ maxEntries: 20 })
|
|
34
|
-
|
|
35
|
-
// Prototype mismatch
|
|
36
|
-
const a = Object.create(null); a.x = 1
|
|
37
|
-
const b = { x: 1 }
|
|
38
|
-
cache.set('proto', a)
|
|
39
|
-
const pmatch = cache.hasEqual('proto', b)
|
|
40
|
-
|
|
41
|
-
// Set primitive fast-path
|
|
42
|
-
const s = new Set([1,2,3])
|
|
43
|
-
cache.set('primset', s)
|
|
44
|
-
const primOk = cache.hasEqual('primset', new Set([1,2,3]))
|
|
45
|
-
|
|
46
|
-
// Array mismatch
|
|
47
|
-
const arr = [1, {x:2}, 3]
|
|
48
|
-
cache.set('arr', arr)
|
|
49
|
-
const arrOk = cache.hasEqual('arr', [1, {x:2}, 3])
|
|
50
|
-
|
|
51
|
-
// TypedArray view with offset should cause slice branch in o2b/buffer helpers when used elsewhere
|
|
52
|
-
const buf = new ArrayBuffer(10)
|
|
53
|
-
const view = new Uint8Array(buf, 2, 4)
|
|
54
|
-
cache.set('view', view)
|
|
55
|
-
const viewOk = cache.hasEqual('view', new Uint8Array(buf, 2, 4))
|
|
56
|
-
|
|
57
|
-
return { pmatch, primOk, arrOk, viewOk }
|
|
58
|
-
})()`,
|
|
59
|
-
ctx,
|
|
60
|
-
{ filename: distFile }
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
expect(result.pmatch).toBe(false);
|
|
64
|
-
expect(result.primOk).toBe(true);
|
|
65
|
-
expect(result.arrOk).toBe(true);
|
|
66
|
-
expect(result.viewOk).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle deep-equality and logger edge branches', () => {
|
|
12
|
-
it('PowerCache.hasEqual exercises many deep-equality branches', () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
globalThis: {},
|
|
22
|
-
};
|
|
23
|
-
sandbox.window = sandbox.globalThis;
|
|
24
|
-
sandbox.self = sandbox.globalThis;
|
|
25
|
-
sandbox.global = sandbox.globalThis;
|
|
26
|
-
|
|
27
|
-
const ctx = vm.createContext(sandbox);
|
|
28
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
29
|
-
|
|
30
|
-
// Run several hasEqual scenarios inside VM to exercise many branches
|
|
31
|
-
const result = vm.runInContext(
|
|
32
|
-
`(function(){
|
|
33
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
34
|
-
const cache = new lib.PowerCache({ maxEntries: 20 })
|
|
35
|
-
|
|
36
|
-
// TypedArray / ArrayBuffer
|
|
37
|
-
const buf = new ArrayBuffer(8)
|
|
38
|
-
const ua = new Uint8Array(buf)
|
|
39
|
-
ua[0] = 1
|
|
40
|
-
cache.set('ta', ua)
|
|
41
|
-
const ok1 = cache.hasEqual('ta', new Uint8Array(buf))
|
|
42
|
-
|
|
43
|
-
// Date
|
|
44
|
-
const d = new Date(123456)
|
|
45
|
-
cache.set('date', d)
|
|
46
|
-
const ok2 = cache.hasEqual('date', new Date(123456))
|
|
47
|
-
|
|
48
|
-
// RegExp
|
|
49
|
-
const re = /abc/g
|
|
50
|
-
cache.set('re', re)
|
|
51
|
-
const ok3 = cache.hasEqual('re', /abc/g)
|
|
52
|
-
|
|
53
|
-
// Map of nested objects
|
|
54
|
-
const m = new Map(); m.set('x', { a: [1,2,3] })
|
|
55
|
-
cache.set('map', m)
|
|
56
|
-
const m2 = new Map(); m2.set('x', { a: [1,2,3] })
|
|
57
|
-
const ok4 = cache.hasEqual('map', m2)
|
|
58
|
-
|
|
59
|
-
// Set with object requiring O(n^2) fallback
|
|
60
|
-
const s = new Set(); s.add({ k: 1 })
|
|
61
|
-
cache.set('set', s)
|
|
62
|
-
const s2 = new Set(); s2.add({ k: 1 })
|
|
63
|
-
const ok5 = cache.hasEqual('set', s2)
|
|
64
|
-
|
|
65
|
-
return { ok1, ok2, ok3, ok4, ok5 }
|
|
66
|
-
})()`,
|
|
67
|
-
ctx,
|
|
68
|
-
{ filename: distFile }
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
expect(result.ok1).toBe(true);
|
|
72
|
-
expect(result.ok2).toBe(true);
|
|
73
|
-
expect(result.ok3).toBe(true);
|
|
74
|
-
expect(result.ok4).toBe(true);
|
|
75
|
-
expect(result.ok5).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('PowerLogger handles missing console methods and lazy args safely', () => {
|
|
79
|
-
const sandbox = { setTimeout, clearTimeout, setInterval, clearInterval, globalThis: {} };
|
|
80
|
-
sandbox.window = sandbox.globalThis;
|
|
81
|
-
sandbox.self = sandbox.globalThis;
|
|
82
|
-
sandbox.global = sandbox.globalThis;
|
|
83
|
-
// Provide a console with missing methods
|
|
84
|
-
sandbox.console = { log: () => {}, warn: () => {} };
|
|
85
|
-
|
|
86
|
-
const ctx = vm.createContext(sandbox);
|
|
87
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
88
|
-
|
|
89
|
-
const res = vm.runInContext(
|
|
90
|
-
`(function(){
|
|
91
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
92
|
-
const logger = new lib.PowerLogger(3)
|
|
93
|
-
// these calls should not throw even if console.info/error are missing
|
|
94
|
-
try { logger.info(() => 'a', () => { throw new Error('boom') }); } catch (e) { return false }
|
|
95
|
-
try { logger.error('x', () => 'y'); } catch (e) { return false }
|
|
96
|
-
return true
|
|
97
|
-
})()`,
|
|
98
|
-
ctx,
|
|
99
|
-
{ filename: distFile }
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
expect(res).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle logger extra branches', () => {
|
|
12
|
-
it('invokes counter APIs and handles odd inputs', () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
globalThis: {},
|
|
22
|
-
};
|
|
23
|
-
sandbox.window = sandbox.globalThis;
|
|
24
|
-
sandbox.self = sandbox.globalThis;
|
|
25
|
-
sandbox.global = sandbox.globalThis;
|
|
26
|
-
|
|
27
|
-
const ctx = vm.createContext(sandbox);
|
|
28
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
29
|
-
|
|
30
|
-
const ok = vm.runInContext(
|
|
31
|
-
`(function(){
|
|
32
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
33
|
-
const logger = new lib.PowerLogger(2)
|
|
34
|
-
logger.incrementCounter('k')
|
|
35
|
-
const before = logger.getDebugCounters()
|
|
36
|
-
logger.resetDebugCounters()
|
|
37
|
-
const after = logger.getDebugCounters()
|
|
38
|
-
// weird setDebugLevel input
|
|
39
|
-
logger.setDebugLevel({ toString: () => { throw new Error('boom') } })
|
|
40
|
-
return before && typeof after === 'object'
|
|
41
|
-
})()`,
|
|
42
|
-
ctx,
|
|
43
|
-
{ filename: distFile }
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
expect(ok).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { existsSync, readFileSync } from 'fs';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import vm from 'vm';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
const distFile = path.resolve(process.cwd(), 'dist', 'performance-helpers.js');
|
|
8
|
-
if (!existsSync(distFile)) execSync('npm run build', { stdio: 'inherit' });
|
|
9
|
-
const code = readFileSync(distFile, 'utf8');
|
|
10
|
-
|
|
11
|
-
describe('UMD bundle more coverage permutations', () => {
|
|
12
|
-
it('exercises map/set/typed-array key cases and buffer decode errors', () => {
|
|
13
|
-
const sandbox = {
|
|
14
|
-
console,
|
|
15
|
-
setTimeout,
|
|
16
|
-
clearTimeout,
|
|
17
|
-
setInterval,
|
|
18
|
-
clearInterval,
|
|
19
|
-
TextEncoder,
|
|
20
|
-
TextDecoder,
|
|
21
|
-
Buffer: global.Buffer,
|
|
22
|
-
globalThis: {},
|
|
23
|
-
};
|
|
24
|
-
sandbox.window = sandbox.globalThis;
|
|
25
|
-
sandbox.self = sandbox.globalThis;
|
|
26
|
-
sandbox.global = sandbox.globalThis;
|
|
27
|
-
|
|
28
|
-
const ctx = vm.createContext(sandbox);
|
|
29
|
-
vm.runInContext(code, ctx, { filename: distFile });
|
|
30
|
-
|
|
31
|
-
const res = vm.runInContext(
|
|
32
|
-
`(function(){
|
|
33
|
-
const lib = (typeof globalThis !== 'undefined' && (globalThis.PerformanceHelpers || globalThis.performanceHelpers)) || (typeof PerformanceHelpers !== 'undefined' && (PerformanceHelpers || performanceHelpers)) || this.PerformanceHelpers || this.performanceHelpers
|
|
34
|
-
const cache = new lib.PowerCache({ maxEntries: 50 })
|
|
35
|
-
|
|
36
|
-
// Map with typed-array key
|
|
37
|
-
const key = new Uint8Array([1,2,3])
|
|
38
|
-
const m = new Map(); m.set(key, 'v')
|
|
39
|
-
cache.set('mapt', m)
|
|
40
|
-
const mapRes = cache.hasEqual('mapt', new Map([[new Uint8Array([1,2,3]), 'v']]))
|
|
41
|
-
|
|
42
|
-
// Set primitive vs complex
|
|
43
|
-
const s1 = new Set([1,2,3])
|
|
44
|
-
cache.set('s1', s1)
|
|
45
|
-
const s1ok = cache.hasEqual('s1', new Set([1,2,3]))
|
|
46
|
-
|
|
47
|
-
const s2 = new Set([{a:1}])
|
|
48
|
-
cache.set('s2', s2)
|
|
49
|
-
const s2ok = cache.hasEqual('s2', new Set([{a:1}]))
|
|
50
|
-
|
|
51
|
-
// u82o error for unsupported value (simulate by passing number)
|
|
52
|
-
let threw = false
|
|
53
|
-
try { lib.u82o(123) } catch(e){ threw = true }
|
|
54
|
-
|
|
55
|
-
return { mapRes, s1ok, s2ok, threw }
|
|
56
|
-
})()`,
|
|
57
|
-
ctx,
|
|
58
|
-
{ filename: distFile }
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
// mapRes should be false (different key references)
|
|
62
|
-
expect(res.mapRes).toBe(false);
|
|
63
|
-
expect(res.s1ok).toBe(true);
|
|
64
|
-
expect(res.s2ok).toBe(true);
|
|
65
|
-
expect(res.threw).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
});
|