@specter-automation/test 1.0.141 → 1.0.142
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.
|
@@ -196,6 +196,8 @@ export interface SpawnOptions {
|
|
|
196
196
|
location?: Vector3;
|
|
197
197
|
rotation?: Rotator;
|
|
198
198
|
properties?: Record<string, any>;
|
|
199
|
+
/** Pawns only. Default true: the pawn gets its controller (its AI). False spawns it with none, even when its class
|
|
200
|
+
* would possess it with AI on spawn: it stands where it's put, e.g. a target dummy. Needs the Specter plugin from 2026-10-15. */
|
|
199
201
|
spawnController?: boolean;
|
|
200
202
|
name?: string;
|
|
201
203
|
/** If true, the actor will not be destroyed by ClearAllSpawned between tests. */
|
|
@@ -17,6 +17,9 @@ function formatTarget(target) {
|
|
|
17
17
|
}
|
|
18
18
|
/** What a blackboard value is expected to be, ready to compare with the trail's text: an actor locator becomes its name */
|
|
19
19
|
async function resolveExpectedValue(expected) {
|
|
20
|
+
if (Array.isArray(expected)) {
|
|
21
|
+
return Promise.all(expected.map(e => resolveExpectedValue(e)));
|
|
22
|
+
}
|
|
20
23
|
if (expected && typeof expected === 'object' && !(expected instanceof RegExp) && typeof expected.getObjectName === 'function') {
|
|
21
24
|
try {
|
|
22
25
|
return await expected.getObjectName();
|
|
@@ -29,6 +32,9 @@ async function resolveExpectedValue(expected) {
|
|
|
29
32
|
}
|
|
30
33
|
/** A value from the trail (DescribeKeyValue text) against what the test expects */
|
|
31
34
|
function trailValueMatches(value, expected) {
|
|
35
|
+
if (Array.isArray(expected)) {
|
|
36
|
+
return expected.some(singleExp => trailValueMatches(value, singleExp));
|
|
37
|
+
}
|
|
32
38
|
if (expected instanceof RegExp)
|
|
33
39
|
return expected.test(value);
|
|
34
40
|
if (typeof expected === 'number')
|
|
@@ -38,6 +44,9 @@ function trailValueMatches(value, expected) {
|
|
|
38
44
|
return value.toLowerCase() === String(expected).toLowerCase();
|
|
39
45
|
}
|
|
40
46
|
function describeExpected(expected) {
|
|
47
|
+
if (Array.isArray(expected)) {
|
|
48
|
+
return `[${expected.map(describeExpected).join(', ')}]`;
|
|
49
|
+
}
|
|
41
50
|
return expected instanceof RegExp ? String(expected) : `'${expected}'`;
|
|
42
51
|
}
|
|
43
52
|
/** The blackboard keys a matcher is about, shown first in its trail */
|
|
@@ -76,42 +85,48 @@ exports.aiExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)(wit
|
|
|
76
85
|
const isNot = this.isNot;
|
|
77
86
|
const timeout = options?.timeout ?? 5000;
|
|
78
87
|
const startTime = Date.now();
|
|
88
|
+
const resolvedExpected = await resolveExpectedValue(expectedValue);
|
|
79
89
|
return await (async () => {
|
|
80
90
|
let lastValue = null;
|
|
81
91
|
let lastObjName = undefined;
|
|
82
92
|
let lastObjTags = [];
|
|
93
|
+
const checkMatch = (exp) => {
|
|
94
|
+
if (Array.isArray(exp)) {
|
|
95
|
+
return exp.some(singleExp => checkMatch(singleExp));
|
|
96
|
+
}
|
|
97
|
+
if (exp instanceof RegExp) {
|
|
98
|
+
return exp.test(lastValue) || (lastObjName ? exp.test(lastObjName) : false);
|
|
99
|
+
}
|
|
100
|
+
else if (typeof exp === 'string') {
|
|
101
|
+
const expLower = exp.toLowerCase();
|
|
102
|
+
return (lastValue ?? '').toLowerCase() === expLower ||
|
|
103
|
+
(lastObjName ?? '').toLowerCase() === expLower ||
|
|
104
|
+
lastObjTags.some((t) => t.toLowerCase() === expLower);
|
|
105
|
+
}
|
|
106
|
+
else if (typeof exp === 'number') {
|
|
107
|
+
return Number(lastValue) === exp;
|
|
108
|
+
}
|
|
109
|
+
else if (typeof exp === 'boolean') {
|
|
110
|
+
const valLower = String(lastValue).toLowerCase();
|
|
111
|
+
const boolVal = valLower === 'true' || valLower === '1';
|
|
112
|
+
return boolVal === exp;
|
|
113
|
+
}
|
|
114
|
+
else if (exp && typeof exp === 'object') {
|
|
115
|
+
const expStr = exp.toString ? exp.toString().toLowerCase() : '';
|
|
116
|
+
return (lastObjName ?? '').toLowerCase().includes(expStr) ||
|
|
117
|
+
lastObjTags.some((t) => expStr.includes(t.toLowerCase()));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return lastValue === exp;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
83
123
|
while (Date.now() - startTime < timeout) {
|
|
84
124
|
try {
|
|
85
125
|
const info = await locator.getBlackboardValue(keyName);
|
|
86
126
|
lastValue = info.value;
|
|
87
127
|
lastObjName = info.objectName;
|
|
88
128
|
lastObjTags = info.objectTags ?? [];
|
|
89
|
-
|
|
90
|
-
if (expectedValue instanceof RegExp) {
|
|
91
|
-
matches = expectedValue.test(lastValue) || (lastObjName ? expectedValue.test(lastObjName) : false);
|
|
92
|
-
}
|
|
93
|
-
else if (typeof expectedValue === 'string') {
|
|
94
|
-
const expLower = expectedValue.toLowerCase();
|
|
95
|
-
matches = (lastValue ?? '').toLowerCase() === expLower ||
|
|
96
|
-
(lastObjName ?? '').toLowerCase() === expLower ||
|
|
97
|
-
lastObjTags.some((t) => t.toLowerCase() === expLower);
|
|
98
|
-
}
|
|
99
|
-
else if (typeof expectedValue === 'number') {
|
|
100
|
-
matches = Number(lastValue) === expectedValue;
|
|
101
|
-
}
|
|
102
|
-
else if (typeof expectedValue === 'boolean') {
|
|
103
|
-
const valLower = String(lastValue).toLowerCase();
|
|
104
|
-
const boolVal = valLower === 'true' || valLower === '1';
|
|
105
|
-
matches = boolVal === expectedValue;
|
|
106
|
-
}
|
|
107
|
-
else if (expectedValue && typeof expectedValue === 'object') {
|
|
108
|
-
const expStr = expectedValue.toString ? expectedValue.toString().toLowerCase() : '';
|
|
109
|
-
matches = (lastObjName ?? '').toLowerCase().includes(expStr) ||
|
|
110
|
-
lastObjTags.some((t) => expStr.includes(t.toLowerCase()));
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
matches = lastValue === expectedValue;
|
|
114
|
-
}
|
|
129
|
+
const matches = checkMatch(resolvedExpected);
|
|
115
130
|
if (isNot ? !matches : matches) {
|
|
116
131
|
return { pass: !isNot, message: () => 'passed' };
|
|
117
132
|
}
|
|
@@ -121,7 +136,7 @@ exports.aiExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)(wit
|
|
|
121
136
|
}
|
|
122
137
|
return {
|
|
123
138
|
pass: isNot,
|
|
124
|
-
message: () => `Expected Blackboard key '${keyName}' to ${isNot ? 'not ' : ''}match
|
|
139
|
+
message: () => `Expected Blackboard key '${keyName}' to ${isNot ? 'not ' : ''}match ${describeExpected(resolvedExpected)}.\n` +
|
|
125
140
|
`Received value: '${lastValue}'${lastObjName ? ` (Object: '${lastObjName}', Tags: [${lastObjTags.join(', ')}])` : ''}`
|
|
126
141
|
};
|
|
127
142
|
})();
|