@ac-kit/test-util 0.1.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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @ac-kit/test-util
2
+
3
+ Test-harness primitives with no dependency beyond `@ac-kit/core`.
4
+
5
+ Being dependency-free is the design constraint, not an accident: any package's
6
+ test suite may need these, so pulling in a heavier dependency here would force
7
+ it on every consumer.
8
+
9
+ ```ts
10
+ import { busyWaitSync, expectCloseRelative } from "@ac-kit/test-util";
11
+
12
+ // Holds the event loop, unlike `setTimeout`, so a timing test observes real
13
+ // blocking rather than a yield.
14
+ busyWaitSync(50);
15
+
16
+ expectCloseRelative(measured, expected, 1e-9);
17
+ ```
18
+
19
+ Also exposes `expectCompareAgreesWithEquals`, for asserting that a type's
20
+ comparator and its equality agree — the invariant an ordered container silently
21
+ relies on.
22
+
23
+ For helpers that drive and probe real external services (Docker containers,
24
+ TCP/TLS endpoints), see `@ac-kit/integration-test-util` instead — that package
25
+ is allowed heavier dependencies precisely because its own consumers are few.
26
+
27
+ See the
28
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/test-util/)
29
+ for the full reference.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Blocks the thread synchronously for `durationMs`.
3
+ *
4
+ * Deliberately synchronous and busy: the point is to hold the event loop, and
5
+ * anything that yields (a timer, an `await`) would not.
6
+ */
7
+ export declare function busyWaitSync(durationMs: number): void;
8
+ //# sourceMappingURL=busy-wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"busy-wait.d.ts","sourceRoot":"","sources":["../src/busy-wait.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAKrD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Blocks the thread synchronously for `durationMs`.
3
+ *
4
+ * Deliberately synchronous and busy: the point is to hold the event loop, and
5
+ * anything that yields (a timer, an `await`) would not.
6
+ */
7
+ export function busyWaitSync(durationMs) {
8
+ const deadline = performance.now() + durationMs;
9
+ while (performance.now() < deadline) {
10
+ // Spin.
11
+ }
12
+ }
13
+ //# sourceMappingURL=busy-wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"busy-wait.js","sourceRoot":"","sources":["../src/busy-wait.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,UAAkB;IAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC;IAChD,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QACrC,QAAQ;IACT,CAAC;AACF,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Asserts that `actual` matches `expected` to within a **relative** tolerance.
3
+ *
4
+ * Vitest's `toBeCloseTo` counts decimal places, which is an absolute measure:
5
+ * the same call that usefully pins `0.5` to fifteen digits passes on anything
6
+ * at all for `1e308` and fails on everything for `1e-45`. Numerical code is
7
+ * specified in relative error, so that is what this compares.
8
+ *
9
+ * Exact equality short-circuits first, so a pair of zeros — where a relative
10
+ * error is `0/0` — passes rather than reporting `NaN`.
11
+ *
12
+ * @param actual Value under test.
13
+ * @param expected Reference value, typically from an independent
14
+ * implementation.
15
+ * @param tolerance Largest acceptable `|actual / expected − 1|`. Defaults to
16
+ * `1e-14`, about fifty times binary64's epsilon — tight enough to catch a
17
+ * wrong algorithm, loose enough to survive a differently-associated sum.
18
+ */
19
+ export declare function expectCloseRelative(actual: number, expected: number, tolerance?: number): void;
20
+ //# sourceMappingURL=expect-close-relative.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-close-relative.d.ts","sourceRoot":"","sources":["../src/expect-close-relative.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,SAAQ,GACf,IAAI,CAWN"}
@@ -0,0 +1,27 @@
1
+ import { expect } from "vitest";
2
+ /**
3
+ * Asserts that `actual` matches `expected` to within a **relative** tolerance.
4
+ *
5
+ * Vitest's `toBeCloseTo` counts decimal places, which is an absolute measure:
6
+ * the same call that usefully pins `0.5` to fifteen digits passes on anything
7
+ * at all for `1e308` and fails on everything for `1e-45`. Numerical code is
8
+ * specified in relative error, so that is what this compares.
9
+ *
10
+ * Exact equality short-circuits first, so a pair of zeros — where a relative
11
+ * error is `0/0` — passes rather than reporting `NaN`.
12
+ *
13
+ * @param actual Value under test.
14
+ * @param expected Reference value, typically from an independent
15
+ * implementation.
16
+ * @param tolerance Largest acceptable `|actual / expected − 1|`. Defaults to
17
+ * `1e-14`, about fifty times binary64's epsilon — tight enough to catch a
18
+ * wrong algorithm, loose enough to survive a differently-associated sum.
19
+ */
20
+ export function expectCloseRelative(actual, expected, tolerance = 1e-14) {
21
+ if (actual === expected) {
22
+ return;
23
+ }
24
+ const error = Math.abs(actual / expected - 1);
25
+ expect(error, `expected ${actual} to be within ${tolerance} relative of ${expected}`).toBeLessThanOrEqual(tolerance);
26
+ }
27
+ //# sourceMappingURL=expect-close-relative.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-close-relative.js","sourceRoot":"","sources":["../src/expect-close-relative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAAc,EACd,QAAgB,EAChB,SAAS,GAAG,KAAK;IAEjB,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACzB,OAAO;IACR,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;IAE9C,MAAM,CACL,KAAK,EACL,YAAY,MAAM,iBAAiB,SAAS,gBAAgB,QAAQ,EAAE,CACtE,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Comparator, EqualityComparator } from "@ac-kit/core";
2
+ /**
3
+ * Asserts that `compare` and `equals` agree on every ordered pair drawn from
4
+ * `values`: `compare(a, b) === 0` exactly when `equals(a, b)`.
5
+ *
6
+ * Both must be exact for this to hold. An approximate equality is not
7
+ * transitive, so pairing one with an exact comparator lets a container order
8
+ * two elements apart while a dedupe pass calls them the same — the classic
9
+ * source of a set holding two "equal" members.
10
+ *
11
+ * `values` must contain no `NaN`, and no structure holding one: exact equality
12
+ * reports `NaN !== NaN` while a total order must place `NaN` equivalent to
13
+ * itself, so the two disagree there by design.
14
+ */
15
+ export declare function expectCompareAgreesWithEquals<T>(values: readonly T[], compare: Comparator<T>, equals: EqualityComparator<T, T>): void;
16
+ //# sourceMappingURL=expect-compare-agrees-with-equals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-compare-agrees-with-equals.d.ts","sourceRoot":"","sources":["../src/expect-compare-agrees-with-equals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGnE;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAC9C,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EACtB,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC9B,IAAI,CASN"}
@@ -0,0 +1,22 @@
1
+ import { expect } from "vitest";
2
+ /**
3
+ * Asserts that `compare` and `equals` agree on every ordered pair drawn from
4
+ * `values`: `compare(a, b) === 0` exactly when `equals(a, b)`.
5
+ *
6
+ * Both must be exact for this to hold. An approximate equality is not
7
+ * transitive, so pairing one with an exact comparator lets a container order
8
+ * two elements apart while a dedupe pass calls them the same — the classic
9
+ * source of a set holding two "equal" members.
10
+ *
11
+ * `values` must contain no `NaN`, and no structure holding one: exact equality
12
+ * reports `NaN !== NaN` while a total order must place `NaN` equivalent to
13
+ * itself, so the two disagree there by design.
14
+ */
15
+ export function expectCompareAgreesWithEquals(values, compare, equals) {
16
+ for (const a of values) {
17
+ for (const b of values) {
18
+ expect(compare(a, b) === 0, `compare and equals disagree on ${JSON.stringify(a)} / ${JSON.stringify(b)}`).toBe(equals(a, b));
19
+ }
20
+ }
21
+ }
22
+ //# sourceMappingURL=expect-compare-agrees-with-equals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-compare-agrees-with-equals.js","sourceRoot":"","sources":["../src/expect-compare-agrees-with-equals.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,6BAA6B,CAC5C,MAAoB,EACpB,OAAsB,EACtB,MAAgC;IAEhC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACxB,MAAM,CACL,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EACnB,kCAAkC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAC5E,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./busy-wait.js";
2
+ export * from "./expect-close-relative.js";
3
+ export * from "./expect-compare-agrees-with-equals.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./busy-wait.js";
2
+ export * from "./expect-close-relative.js";
3
+ export * from "./expect-compare-agrees-with-equals.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@ac-kit/test-util",
3
+ "version": "0.1.0",
4
+ "description": "Dependency-free test-harness primitives, such as a deterministic synchronous delay for timing-sensitive tests.",
5
+ "keywords": [
6
+ "test-utils",
7
+ "testing",
8
+ "vitest"
9
+ ],
10
+ "homepage": "https://anthochamp.github.io/node-essentials/api/test-util/",
11
+ "bugs": {
12
+ "url": "https://github.com/anthochamp/node-essentials/issues"
13
+ },
14
+ "license": "BSD-3-Clause",
15
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
19
+ "directory": "packages/test-util"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./dist/index.js",
27
+ "publishConfig": {
28
+ "main": "./dist/index.js",
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "compile": "tsc -p ./tsconfig.build.json --outDir dist",
33
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
34
+ "clean": "rimraf dist",
35
+ "build": "yarn clean && yarn compile",
36
+ "test": "yarn run -T vitest run",
37
+ "prepack": "yarn build"
38
+ },
39
+ "dependencies": {
40
+ "@ac-kit/core": "^0.1.0"
41
+ },
42
+ "devDependencies": {
43
+ "@ac-kit/tsconfig": "0.1.0",
44
+ "@ac-kit/typedoc-config": "0.1.0",
45
+ "@ac-kit/vitest-config": "0.1.0",
46
+ "@types/node": "26.5.1",
47
+ "@typescript/native": "typescript@7.0.2",
48
+ "rimraf": "6.1.3",
49
+ "typedoc": "0.28.20",
50
+ "typescript": "@typescript/typescript6@6.0.2",
51
+ "vite": "8.3.0",
52
+ "vitest": "5.0.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=24"
56
+ }
57
+ }