feat(build): modernize package configuration, tooling, and tests for ESM-compatible releases

This commit is contained in:
2026-05-02 09:51:34 +00:00
parent f9873b008b
commit 2051335d91
12 changed files with 7768 additions and 4117 deletions
+42
View File
@@ -0,0 +1,42 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartdelay from '../ts/index.js';
tap.test('.delayFor should delay async', async () => {
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 10);
await smartdelay.delayFor(20);
expect(timePassed).toBeTrue();
});
tap.test('.delayForRandom should pass through values', async () => {
const originalRandom = Math.random;
Math.random = () => 0;
try {
const result = await smartdelay.delayForRandom(1, 2, 'random-result');
expect(result).toEqual('random-result');
} finally {
Math.random = originalRandom;
}
});
tap.test('.delayFor should pass on a type', async () => {
const hey = 'heyThere';
const stringArg = await smartdelay.delayFor<string>(1, hey);
expect(stringArg).toEqual('heyThere');
});
tap.test('smartdelay.Timeout', async () => {
const timeout = new smartdelay.Timeout(1);
await timeout.promise;
});
tap.test('smartdelay.Timeout should cancel', async () => {
const timeout = new smartdelay.Timeout(60000);
timeout.cancel();
expect(timeout.getTimeLeft()).toBeGreaterThan(0);
});
export default tap.start();
-53
View File
@@ -1,53 +0,0 @@
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartdelay from '../ts/index.js';
tap.test('.delayFor should delay async', async (tools) => {
tools.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
await smartdelay.delayFor(3000).then(async () => {
// tslint:disable-next-line:no-unused-expression
expect(timePassed).toBeTrue();
});
});
tap.test('.delayForRandom should delay async for a random time period', async (tools) => {
let timePassedBefore = false;
let timePassedAfter = false;
setTimeout(() => {
timePassedBefore = true;
}, 3000);
setTimeout(() => {
timePassedAfter = true;
}, 5000);
await smartdelay.delayForRandom(3000, 4900);
expect(timePassedBefore).toBeTrue();
expect(timePassedAfter).toBeFalse();
});
tap.test('.delayFor should pass on a type', async (tools) => {
tools.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
let hey = 'heyThere';
await smartdelay.delayFor<string>(3000, hey).then(async (stringArg) => {
expect(stringArg).toEqual('heyThere');
});
});
tap.test('smartdelay.Timeout', async () => {
let timeout = new smartdelay.Timeout(2000);
await timeout.promise;
});
tap.test('smartdelay.Timeout should cancel', async (tools) => {
let timeout = new smartdelay.Timeout(60000);
timeout.cancel();
});
tap.start();