@mantaq/test 1.0.0 → 2.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/dist/index.d.mts +12 -20
- package/dist/index.mjs +13 -10
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ActorGraph, History } from "@mantaq/traversal";
|
|
2
2
|
import { AnyActor, Snapshot } from "@mantaq/core";
|
|
3
|
-
//#region src/types.d.ts
|
|
4
3
|
interface CoverageReport {
|
|
5
4
|
states: {
|
|
6
5
|
total: number;
|
|
@@ -76,46 +75,39 @@ interface TestHarness<C = Record<string, unknown>> {
|
|
|
76
75
|
}): boolean;
|
|
77
76
|
reset(): void;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare function createTestHarness<C>(actor: AnyActor<C>): TestHarness<C>;
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/coverage.d.ts
|
|
84
|
-
declare function computeCoverage(graph: ActorGraph, tracked: {
|
|
78
|
+
export declare function createTestHarness<C>(actor: AnyActor<C>): TestHarness<C>;
|
|
79
|
+
export declare function computeCoverage(graph: ActorGraph, tracked: {
|
|
85
80
|
history: History;
|
|
86
81
|
}): CoverageReport;
|
|
87
|
-
|
|
88
|
-
//#region src/assertions.d.ts
|
|
89
|
-
declare function assertAllStatesVisited(graph: ActorGraph, checked: {
|
|
82
|
+
export declare function assertAllStatesVisited(graph: ActorGraph, checked: {
|
|
90
83
|
history: History;
|
|
91
84
|
}): void;
|
|
92
|
-
declare function assertAllTransitionsVisited(graph: ActorGraph, checked: {
|
|
85
|
+
export declare function assertAllTransitionsVisited(graph: ActorGraph, checked: {
|
|
93
86
|
history: History;
|
|
94
87
|
}): void;
|
|
95
|
-
declare function assertStateVisited(history: History, target: {
|
|
88
|
+
export declare function assertStateVisited(history: History, target: {
|
|
96
89
|
stateName: string;
|
|
97
90
|
}): void;
|
|
98
|
-
declare function assertStateNeverVisited(history: History, banned: {
|
|
91
|
+
export declare function assertStateNeverVisited(history: History, banned: {
|
|
99
92
|
stateName: string;
|
|
100
93
|
}): void;
|
|
101
|
-
declare function assertTransitionVisited(history: History, expected: {
|
|
94
|
+
export declare function assertTransitionVisited(history: History, expected: {
|
|
102
95
|
from: string;
|
|
103
96
|
event: string;
|
|
104
97
|
}): void;
|
|
105
|
-
declare function assertTransitionNeverVisited(history: History, banned: {
|
|
98
|
+
export declare function assertTransitionNeverVisited(history: History, banned: {
|
|
106
99
|
from: string;
|
|
107
100
|
event: string;
|
|
108
101
|
}): void;
|
|
109
|
-
declare function assertContextNever<C>(actor: AnyActor<C>, check: {
|
|
102
|
+
export declare function assertContextNever<C>(actor: AnyActor<C>, check: {
|
|
110
103
|
predicate: (context: unknown) => boolean;
|
|
111
104
|
}): void;
|
|
112
|
-
declare function assertEffectRan(history: History, expected: {
|
|
105
|
+
export declare function assertEffectRan(history: History, expected: {
|
|
113
106
|
stateName: string;
|
|
114
107
|
effectName: string;
|
|
115
108
|
}): void;
|
|
116
|
-
declare function assertEffectNeverRan(history: History, banned: {
|
|
109
|
+
export declare function assertEffectNeverRan(history: History, banned: {
|
|
117
110
|
stateName: string;
|
|
118
111
|
effectName: string;
|
|
119
112
|
}): void;
|
|
120
|
-
|
|
121
|
-
export { type CoverageReport, type TestHarness, assertAllStatesVisited, assertAllTransitionsVisited, assertContextNever, assertEffectNeverRan, assertEffectRan, assertStateNeverVisited, assertStateVisited, assertTransitionNeverVisited, assertTransitionVisited, computeCoverage, createTestHarness };
|
|
113
|
+
export type { CoverageReport, TestHarness };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { INITIAL_NODE_ID, buildGraph, instrument, parseInternalEventIds } from "@mantaq/traversal";
|
|
2
|
-
|
|
1
|
+
import { INITIAL_NODE_ID, buildGraph, instrument, isAnyNode, parseInternalEventIds } from "@mantaq/traversal";
|
|
2
|
+
// src/assertions.ts
|
|
3
3
|
/**
|
|
4
4
|
* Assertion-style precondition. A violated assertion is a programmer bug in
|
|
5
5
|
* the test (or the code under test), so it cannot be returned as a value —
|
|
@@ -67,20 +67,21 @@ function assertEffectNeverRan(history, banned) {
|
|
|
67
67
|
detail: `assertEffectNeverRan failed: effect "${banned.effectName}" for state "${banned.stateName}" ran`
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
//#region src/coverage.ts
|
|
70
|
+
// src/coverage.ts
|
|
72
71
|
function computeCoverage(graph, tracked) {
|
|
73
72
|
const visitedStates = tracked.history.visitedStates();
|
|
74
73
|
const firedTransitions = tracked.history.firedTransitions();
|
|
75
74
|
const effects = tracked.history.effects();
|
|
76
|
-
const
|
|
75
|
+
const firedRecords = tracked.history.transitions();
|
|
76
|
+
const isFired = (edge) => isAnyNode(edge.source) ? firedRecords.some((record) => record.event === edge.label && isInAnyScope(record.from, edge.source)) : firedTransitions.has(`${edge.source}:${edge.label}`);
|
|
77
|
+
const graphNodes = graph.nodes.filter((node) => node.id !== INITIAL_NODE_ID && !isAnyNode(node.id));
|
|
77
78
|
const graphEdges = graph.edges.filter((edge) => edge.source !== INITIAL_NODE_ID && edge.target !== INITIAL_NODE_ID && !edge.isUndetermined && !edge.isInternal);
|
|
78
79
|
const statesTotal = graphNodes.length;
|
|
79
80
|
const statesVisited = graphNodes.filter((node) => visitedStates.has(node.id)).length;
|
|
80
81
|
const statesUncovered = graphNodes.filter((node) => !visitedStates.has(node.id)).map((node) => node.id);
|
|
81
82
|
const transitionsTotal = graphEdges.length;
|
|
82
|
-
const transitionsVisited = graphEdges.filter(
|
|
83
|
-
const transitionsUncovered = graphEdges.filter((edge) => !
|
|
83
|
+
const transitionsVisited = graphEdges.filter(isFired).length;
|
|
84
|
+
const transitionsUncovered = graphEdges.filter((edge) => !isFired(edge)).map((edge) => ({
|
|
84
85
|
from: edge.source,
|
|
85
86
|
event: edge.label
|
|
86
87
|
}));
|
|
@@ -111,8 +112,11 @@ function computeCoverage(graph, tracked) {
|
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
function isInAnyScope(from, anyNodeId) {
|
|
116
|
+
const prefix = anyNodeId.slice(0, -1);
|
|
117
|
+
return from.startsWith(prefix) && !from.slice(prefix.length).includes(".");
|
|
118
|
+
}
|
|
119
|
+
// src/harness.ts
|
|
116
120
|
function createTestHarness(actor) {
|
|
117
121
|
const instrumented = instrument(actor);
|
|
118
122
|
const internalTypes = parseInternalEventIds(actor.options);
|
|
@@ -149,5 +153,4 @@ function createTestHarness(actor) {
|
|
|
149
153
|
reset: () => instrumented.history.reset()
|
|
150
154
|
};
|
|
151
155
|
}
|
|
152
|
-
//#endregion
|
|
153
156
|
export { assertAllStatesVisited, assertAllTransitionsVisited, assertContextNever, assertEffectNeverRan, assertEffectRan, assertStateNeverVisited, assertStateVisited, assertTransitionNeverVisited, assertTransitionVisited, computeCoverage, createTestHarness };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantaq/test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Test harness and assertion utilities for verifying mantaq actor behavior.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@mantaq/core": "0.
|
|
24
|
-
"@mantaq/traversal": "0.
|
|
23
|
+
"@mantaq/core": "0.5.1",
|
|
24
|
+
"@mantaq/traversal": "0.3.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^26.2.0",
|
|
28
28
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
29
|
-
"@vitest/coverage-v8": "
|
|
29
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
30
30
|
"typescript": "6.0.3",
|
|
31
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@
|
|
32
|
-
"vite-plus": "
|
|
31
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
32
|
+
"vite-plus": "1.4.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "vp pack",
|