@specter-automation/test 1.0.107 → 1.0.108
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.
|
@@ -134,7 +134,10 @@ export declare class ActorLocator<T = any> extends SpecterLocator<T> {
|
|
|
134
134
|
/**
|
|
135
135
|
* Waits for a Gameplay Attribute to reach a specific value, tracking its history.
|
|
136
136
|
*/
|
|
137
|
-
waitForAttributeValue(attributeSet: string, attributeName: string, expectedValue: number,
|
|
137
|
+
waitForAttributeValue(attributeSet: string, attributeName: string, expectedValue: number, options?: {
|
|
138
|
+
timeout?: number;
|
|
139
|
+
tolerance?: number;
|
|
140
|
+
} | number): Promise<{
|
|
138
141
|
finalValue: number;
|
|
139
142
|
history: number[];
|
|
140
143
|
}>;
|
|
@@ -383,38 +383,87 @@ class ActorLocator extends specter_locator_1.SpecterLocator {
|
|
|
383
383
|
/**
|
|
384
384
|
* Waits for a Gameplay Attribute to reach a specific value, tracking its history.
|
|
385
385
|
*/
|
|
386
|
-
async waitForAttributeValue(attributeSet, attributeName, expectedValue,
|
|
386
|
+
async waitForAttributeValue(attributeSet, attributeName, expectedValue, options) {
|
|
387
387
|
const { test } = await Promise.resolve().then(() => __importStar(require('@playwright/test')));
|
|
388
388
|
const { SpecterEventType } = await Promise.resolve().then(() => __importStar(require('../specter-client')));
|
|
389
|
+
const timeout = typeof options === 'number' ? options : (options?.timeout ?? 5000);
|
|
390
|
+
const tolerance = typeof options === 'object' ? (options.tolerance ?? 0.01) : 0.01;
|
|
391
|
+
const isMatch = (val) => {
|
|
392
|
+
if (val === expectedValue)
|
|
393
|
+
return true;
|
|
394
|
+
return Math.abs(val - expectedValue) <= tolerance;
|
|
395
|
+
};
|
|
389
396
|
return await test.step(`Specter: Wait For Attribute [${attributeSet}.${attributeName} == ${expectedValue}]`, async () => {
|
|
390
397
|
let lastValue;
|
|
391
398
|
let history = [];
|
|
392
399
|
try {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
400
|
+
try {
|
|
401
|
+
lastValue = await this.getAttributeValue(attributeSet, attributeName);
|
|
402
|
+
if (lastValue !== undefined && !isNaN(lastValue)) {
|
|
403
|
+
history.push(lastValue);
|
|
404
|
+
if (isMatch(lastValue)) {
|
|
405
|
+
return { finalValue: lastValue, history };
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
catch {
|
|
410
|
+
// Suppress initial read error if transient
|
|
398
411
|
}
|
|
399
412
|
return await new Promise((resolve, reject) => {
|
|
400
413
|
let timeoutId;
|
|
414
|
+
let pollIntervalId;
|
|
415
|
+
let isResolved = false;
|
|
416
|
+
const cleanup = () => {
|
|
417
|
+
if (isResolved)
|
|
418
|
+
return;
|
|
419
|
+
isResolved = true;
|
|
420
|
+
clearTimeout(timeoutId);
|
|
421
|
+
clearInterval(pollIntervalId);
|
|
422
|
+
this.transport.removeEventListener('GLOBAL_timeline-event', listener);
|
|
423
|
+
};
|
|
401
424
|
const listener = (event) => {
|
|
425
|
+
if (isResolved)
|
|
426
|
+
return;
|
|
402
427
|
if (event.eventType === SpecterEventType.GameplayAttribute &&
|
|
403
428
|
(event.eventName === attributeName || event.eventName.includes(attributeName))) {
|
|
404
429
|
const val = parseFloat(event.newValue);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
430
|
+
if (!isNaN(val)) {
|
|
431
|
+
history.push(val);
|
|
432
|
+
lastValue = val;
|
|
433
|
+
if (isMatch(val)) {
|
|
434
|
+
cleanup();
|
|
435
|
+
resolve({ finalValue: val, history });
|
|
436
|
+
}
|
|
410
437
|
}
|
|
411
438
|
}
|
|
412
439
|
};
|
|
440
|
+
this.transport.registerEventListener('GLOBAL_timeline-event', listener);
|
|
441
|
+
pollIntervalId = setInterval(async () => {
|
|
442
|
+
if (isResolved)
|
|
443
|
+
return;
|
|
444
|
+
try {
|
|
445
|
+
const val = await this.getAttributeValue(attributeSet, attributeName);
|
|
446
|
+
if (isResolved)
|
|
447
|
+
return;
|
|
448
|
+
if (val !== undefined && !isNaN(val)) {
|
|
449
|
+
if (lastValue !== val) {
|
|
450
|
+
history.push(val);
|
|
451
|
+
}
|
|
452
|
+
lastValue = val;
|
|
453
|
+
if (isMatch(val)) {
|
|
454
|
+
cleanup();
|
|
455
|
+
resolve({ finalValue: val, history });
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
catch {
|
|
460
|
+
// Transient poll errors suppressed
|
|
461
|
+
}
|
|
462
|
+
}, 100);
|
|
413
463
|
timeoutId = setTimeout(() => {
|
|
414
|
-
|
|
464
|
+
cleanup();
|
|
415
465
|
reject(new Error(`Timed out after ${timeout}ms waiting for GAS Attribute '${attributeName}' to reach value '${expectedValue}'.\nHistory: [${history.join(', ')}]`));
|
|
416
466
|
}, timeout);
|
|
417
|
-
this.transport.registerEventListener('GLOBAL_timeline-event', listener);
|
|
418
467
|
});
|
|
419
468
|
}
|
|
420
469
|
catch (e) {
|
|
@@ -3,7 +3,10 @@ import { SpecterTimelineEvent } from '../core/specter-client';
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace PlaywrightTest {
|
|
5
5
|
interface Matchers<R, T> {
|
|
6
|
-
toHaveAttributeValue(attributeSet: string, attributeName: string, expectedValue: number
|
|
6
|
+
toHaveAttributeValue(attributeSet: string, attributeName: string, expectedValue: number, options?: {
|
|
7
|
+
timeout?: number;
|
|
8
|
+
tolerance?: number;
|
|
9
|
+
}): T extends SpecterLocator ? Promise<R> : never;
|
|
7
10
|
toHaveAttributeChange(attributeSet: string, attributeName: string, expectedChange: {
|
|
8
11
|
delta?: number;
|
|
9
12
|
instigator?: string | ActorLocator;
|
|
@@ -32,7 +35,10 @@ declare global {
|
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
export interface GasMatchers {
|
|
35
|
-
toHaveAttributeValue(attributeSet: string, attributeName: string, expectedValue: number
|
|
38
|
+
toHaveAttributeValue(attributeSet: string, attributeName: string, expectedValue: number, options?: {
|
|
39
|
+
timeout?: number;
|
|
40
|
+
tolerance?: number;
|
|
41
|
+
}): Promise<void>;
|
|
36
42
|
toHaveAttributeChange(attributeSet: string, attributeName: string, expectedChange: {
|
|
37
43
|
delta?: number;
|
|
38
44
|
instigator?: string | ActorLocator;
|
|
@@ -59,13 +65,11 @@ export interface GasMatchers {
|
|
|
59
65
|
toHaveAllGameplayTags(tags: string[]): Promise<void>;
|
|
60
66
|
}
|
|
61
67
|
export declare const gasExpect: import("playwright/test").Expect<{
|
|
62
|
-
toHaveAttributeValue(this: import("playwright/test").ExpectMatcherState, locator: ActorLocator, attributeSet: string, attributeName: string, expectedValue: number
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} | {
|
|
68
|
-
pass: false;
|
|
68
|
+
toHaveAttributeValue(this: import("playwright/test").ExpectMatcherState, locator: ActorLocator, attributeSet: string, attributeName: string, expectedValue: number, options?: {
|
|
69
|
+
timeout?: number;
|
|
70
|
+
tolerance?: number;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
pass: boolean;
|
|
69
73
|
message: () => string;
|
|
70
74
|
actual: any;
|
|
71
75
|
expected: number;
|
|
@@ -37,70 +37,117 @@ exports.gasExpect = void 0;
|
|
|
37
37
|
const test_1 = __importStar(require("@playwright/test"));
|
|
38
38
|
const specter_client_1 = require("../core/specter-client");
|
|
39
39
|
exports.gasExpect = test_1.expect.extend({
|
|
40
|
-
async toHaveAttributeValue(locator, attributeSet, attributeName, expectedValue) {
|
|
40
|
+
async toHaveAttributeValue(locator, attributeSet, attributeName, expectedValue, options) {
|
|
41
41
|
const assertionName = 'toHaveAttributeValue';
|
|
42
42
|
const isNot = this.isNot;
|
|
43
43
|
const prefix = isNot ? 'not.toHaveAttributeValue' : 'toHaveAttributeValue';
|
|
44
|
+
const timeout = options?.timeout ?? 5000;
|
|
45
|
+
const tolerance = options?.tolerance ?? 0.01;
|
|
44
46
|
const stepName = `${prefix}('${attributeSet}', '${attributeName}', ${expectedValue}) @ ${locator.toString()}`;
|
|
47
|
+
const isMatch = (val) => {
|
|
48
|
+
if (val === expectedValue)
|
|
49
|
+
return true;
|
|
50
|
+
return Math.abs(val - expectedValue) <= tolerance;
|
|
51
|
+
};
|
|
45
52
|
return await test_1.default.step(stepName, async () => {
|
|
46
53
|
let lastValue;
|
|
47
54
|
let valueHistory = [];
|
|
48
55
|
try {
|
|
49
|
-
// 1. Check the current value immediately (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
// 1. Check the current value immediately (try once)
|
|
57
|
+
try {
|
|
58
|
+
lastValue = await locator.getAttributeValue(attributeSet, attributeName);
|
|
59
|
+
if (lastValue !== undefined && !isNaN(lastValue)) {
|
|
60
|
+
valueHistory.push(lastValue);
|
|
61
|
+
if (isMatch(lastValue)) {
|
|
62
|
+
return {
|
|
63
|
+
pass: !isNot,
|
|
64
|
+
message: () => 'passed',
|
|
65
|
+
actual: lastValue,
|
|
66
|
+
expected: expectedValue
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
60
70
|
}
|
|
61
|
-
|
|
71
|
+
catch (initialErr) {
|
|
72
|
+
// Suppress initial read error if transient, but proceed to listen
|
|
73
|
+
}
|
|
74
|
+
// 2. If it does not match immediately, listen for the live attribute change event
|
|
62
75
|
const transport = locator.transport;
|
|
63
|
-
const timeout = 5000;
|
|
64
|
-
// Wait for the live broadcast
|
|
65
76
|
const finalValue = await new Promise((resolve, reject) => {
|
|
66
77
|
let timeoutId;
|
|
78
|
+
let pollIntervalId;
|
|
79
|
+
let isResolved = false;
|
|
80
|
+
const cleanup = () => {
|
|
81
|
+
if (isResolved)
|
|
82
|
+
return;
|
|
83
|
+
isResolved = true;
|
|
84
|
+
clearTimeout(timeoutId);
|
|
85
|
+
clearInterval(pollIntervalId);
|
|
86
|
+
if (transport && typeof transport.removeEventListener === 'function') {
|
|
87
|
+
transport.removeEventListener('GLOBAL_timeline-event', listener);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
67
90
|
const listener = (event) => {
|
|
68
|
-
|
|
69
|
-
|
|
91
|
+
if (isResolved)
|
|
92
|
+
return;
|
|
70
93
|
if (event.eventType === specter_client_1.SpecterEventType.GameplayAttribute &&
|
|
71
94
|
(event.eventName === attributeName || event.eventName.includes(attributeName))) {
|
|
72
95
|
const val = parseFloat(event.newValue);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
clearTimeout(timeoutId);
|
|
76
|
-
transport.removeEventListener('GLOBAL_timeline-event', listener);
|
|
77
|
-
resolve(val);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
// Keep track of the latest value we saw during the wait
|
|
96
|
+
if (!isNaN(val)) {
|
|
97
|
+
valueHistory.push(val);
|
|
81
98
|
lastValue = val;
|
|
99
|
+
if (isMatch(val)) {
|
|
100
|
+
cleanup();
|
|
101
|
+
resolve(val);
|
|
102
|
+
}
|
|
82
103
|
}
|
|
83
104
|
}
|
|
84
105
|
};
|
|
106
|
+
// Register event listener immediately to catch incoming push events
|
|
107
|
+
if (transport && typeof transport.registerEventListener === 'function') {
|
|
108
|
+
transport.registerEventListener('GLOBAL_timeline-event', listener);
|
|
109
|
+
}
|
|
110
|
+
// Parallel polling fallback in case the event was already broadcast or missed
|
|
111
|
+
pollIntervalId = setInterval(async () => {
|
|
112
|
+
if (isResolved)
|
|
113
|
+
return;
|
|
114
|
+
try {
|
|
115
|
+
const val = await locator.getAttributeValue(attributeSet, attributeName);
|
|
116
|
+
if (isResolved)
|
|
117
|
+
return;
|
|
118
|
+
if (val !== undefined && !isNaN(val)) {
|
|
119
|
+
if (lastValue !== val) {
|
|
120
|
+
valueHistory.push(val);
|
|
121
|
+
}
|
|
122
|
+
lastValue = val;
|
|
123
|
+
if (isMatch(val)) {
|
|
124
|
+
cleanup();
|
|
125
|
+
resolve(val);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Transient poll errors are suppressed during wait
|
|
131
|
+
}
|
|
132
|
+
}, 100);
|
|
85
133
|
timeoutId = setTimeout(() => {
|
|
86
|
-
|
|
134
|
+
cleanup();
|
|
87
135
|
reject(new Error(`Timed out after ${timeout}ms waiting for GAS Attribute '${attributeName}' to reach value '${expectedValue}'`));
|
|
88
136
|
}, timeout);
|
|
89
|
-
transport.registerEventListener('GLOBAL_timeline-event', listener);
|
|
90
137
|
});
|
|
91
138
|
return {
|
|
92
|
-
pass:
|
|
139
|
+
pass: !isNot,
|
|
93
140
|
message: () => 'passed',
|
|
94
141
|
actual: finalValue,
|
|
95
142
|
expected: expectedValue
|
|
96
143
|
};
|
|
97
144
|
}
|
|
98
145
|
catch (e) {
|
|
99
|
-
if (!e.message
|
|
146
|
+
if (!e.message?.includes('Timed out')) {
|
|
100
147
|
throw e;
|
|
101
148
|
}
|
|
102
149
|
return {
|
|
103
|
-
pass:
|
|
150
|
+
pass: isNot,
|
|
104
151
|
message: () => `${this.utils.matcherHint(assertionName, locator.toString(), expectedValue.toString())}\n\n` +
|
|
105
152
|
`Expected: ${this.utils.printExpected(expectedValue)}\n` +
|
|
106
153
|
`Received: ${lastValue !== undefined ? this.utils.printReceived(lastValue) : 'Timeout'}\n` +
|