@specter-automation/test 1.0.146 → 1.0.148

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.
@@ -24,7 +24,12 @@ declare global {
24
24
  x: number;
25
25
  y: number;
26
26
  z: number;
27
- }, expectedDistance: number): T extends ActorLocator ? Promise<R> : never;
27
+ }, expectedDistance: number, axisOrOptions?: MovementAxis | {
28
+ axis?: MovementAxis;
29
+ timeout?: number;
30
+ }, options?: {
31
+ timeout?: number;
32
+ }): T extends ActorLocator ? Promise<R> : never;
28
33
  toHaveLocation(expectedLocation: {
29
34
  x: number;
30
35
  y: number;
@@ -101,12 +106,25 @@ declare global {
101
106
  }
102
107
  }
103
108
  }
109
+ /**
110
+ * Which part of the movement toHaveMovedFurtherThan measures: one axis ('z' for a jump or a knock-up), the ground
111
+ * plane ('xy'), or the straight-line distance ('xyz', the default).
112
+ */
113
+ export type MovementAxis = 'x' | 'y' | 'z' | 'xy' | 'xyz';
104
114
  export interface ActorMatchers {
115
+ /**
116
+ * Passes once the actor is further than expectedDistance from startLocation, measured along `axis`:
117
+ * `expect(hero).toHaveMovedFurtherThan(start, 100, 'z')` for thrown 100 up. It polls the location every 50ms, so
118
+ * a short hop counts even when the actor is back down by the time the check ends.
119
+ */
105
120
  toHaveMovedFurtherThan(startLocation: {
106
121
  x: number;
107
122
  y: number;
108
123
  z: number;
109
- }, expectedDistance: number, options?: {
124
+ }, expectedDistance: number, axisOrOptions?: MovementAxis | {
125
+ axis?: MovementAxis;
126
+ timeout?: number;
127
+ }, options?: {
110
128
  timeout?: number;
111
129
  }): Promise<void>;
112
130
  toHaveLocation(expectedLocation: {
@@ -206,7 +224,10 @@ export declare const actorExpect: import("playwright/test").Expect<{
206
224
  x: number;
207
225
  y: number;
208
226
  z: number;
209
- }, expectedDistance: number, options?: {
227
+ }, expectedDistance: number, axisOrOptions?: MovementAxis | {
228
+ axis?: MovementAxis;
229
+ timeout?: number;
230
+ }, options?: {
210
231
  timeout?: number;
211
232
  }): Promise<{
212
233
  pass: true;
@@ -4,36 +4,51 @@ exports.actorExpect = void 0;
4
4
  const test_1 = require("@playwright/test");
5
5
  const instrument_1 = require("./instrument");
6
6
  exports.actorExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
7
- async toHaveMovedFurtherThan(locator, startLocation, expectedDistance, options) {
7
+ async toHaveMovedFurtherThan(locator, startLocation, expectedDistance, axisOrOptions, options) {
8
8
  const assertionName = 'toHaveMovedFurtherThan';
9
- const timeout = options?.timeout ?? 5000;
9
+ const opts = typeof axisOrOptions === 'object' ? axisOrOptions : options;
10
+ const axis = (typeof axisOrOptions === 'string' ? axisOrOptions : axisOrOptions?.axis) ?? 'xyz';
11
+ if (!['x', 'y', 'z', 'xy', 'xyz'].includes(axis)) {
12
+ throw new Error(`${assertionName}: axis must be 'x', 'y', 'z', 'xy' or 'xyz', not '${axis}'`);
13
+ }
14
+ const timeout = opts?.timeout ?? 5000;
10
15
  const startTime = Date.now();
11
- let currentDistance = 0;
16
+ const along = axis === 'xyz' ? '' : ` along ${axis}`;
17
+ const measure = (loc) => {
18
+ const dx = axis.includes('x') ? loc.x - startLocation.x : 0;
19
+ const dy = axis.includes('y') ? loc.y - startLocation.y : 0;
20
+ const dz = axis.includes('z') ? loc.z - startLocation.z : 0;
21
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
22
+ };
23
+ let maxDistance = 0;
24
+ let lastLocation = null;
12
25
  while (Date.now() - startTime < timeout) {
13
26
  const loc = await locator.getLocation();
14
- const dx = loc.x - startLocation.x;
15
- const dy = loc.y - startLocation.y;
16
- const dz = loc.z - startLocation.z;
17
- currentDistance = Math.sqrt(dx * dx + dy * dy + dz * dz);
18
- if (currentDistance > expectedDistance) {
27
+ lastLocation = loc;
28
+ const distance = measure(loc);
29
+ maxDistance = Math.max(maxDistance, distance);
30
+ if (distance > expectedDistance) {
19
31
  return {
20
32
  pass: true,
21
- message: () => 'passed',
22
- actual: currentDistance,
23
- expected: `> ${expectedDistance}`
33
+ message: () => `${this.utils.matcherHint(assertionName, locator.toString(), expectedDistance.toString())}\n\n` +
34
+ `Expected actor "${locator.toString()}" not to move further than ${expectedDistance}${along}, ` +
35
+ `but it moved ${Math.round(distance)}${along} (now at ${JSON.stringify(loc)})`,
36
+ actual: Math.round(distance),
37
+ expected: `> ${expectedDistance}${along}`
24
38
  };
25
39
  }
26
- // Sleep for 100ms before polling again
27
- await new Promise(resolve => setTimeout(resolve, 100));
40
+ // Often enough to catch a short hop (a knock-up is up and down in well under a second)
41
+ await new Promise(resolve => setTimeout(resolve, 50));
28
42
  }
29
43
  return {
30
44
  pass: false,
31
45
  message: () => `${this.utils.matcherHint(assertionName, locator.toString(), expectedDistance.toString())}\n\n` +
32
- `Timed out after ${timeout}ms waiting for actor "${locator.toString()}" to move.\n` +
33
- `Expected distance: > ${expectedDistance}\n` +
34
- `Received max distance: ${currentDistance}`,
35
- actual: currentDistance,
36
- expected: `> ${expectedDistance}`
46
+ `Timed out after ${timeout}ms waiting for actor "${locator.toString()}" to move${along}.\n` +
47
+ `Expected distance${along}: > ${expectedDistance}\n` +
48
+ `Received max distance${along}: ${Math.round(maxDistance)}\n` +
49
+ `Start: ${JSON.stringify(startLocation)}, last seen at: ${JSON.stringify(lastLocation)}`,
50
+ actual: Math.round(maxDistance),
51
+ expected: `> ${expectedDistance}${along}`
37
52
  };
38
53
  },
39
54
  async toHaveLocation(locator, expectedLocation, tolerance = 5.0, options) {
@@ -403,7 +403,7 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
403
403
  const matched = (actual) => ({
404
404
  pass: true,
405
405
  message: () => `${this.utils.matcherHint(assertionName, locator.toString(), expectedParts.join(', '), { isNot })}\n\n` +
406
- `Expected no change matching { ${expectedParts.join(', ')} }, but got:\n${JSON.stringify(actual, null, 2)}`,
406
+ `Expected no change matching { ${expectedParts.join(', ')} }, but got: ${describeAttributeChange(actual)}`,
407
407
  actual,
408
408
  expected: expectedChange
409
409
  });
@@ -426,7 +426,7 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
426
426
  }
427
427
  try {
428
428
  // In parallel: resolve initial value and locator names
429
- const [resolvedInitialVal, expectedInstigatorName, expectedEffectCauserName] = await Promise.all([
429
+ const [resolvedInitialVal, expectedInstigatorName, expectedEffectCauserName, targetName] = await Promise.all([
430
430
  locator.getAttributeValue(attributeSet, attributeName).catch(() => undefined),
431
431
  expectedChange.instigator
432
432
  ? (typeof expectedChange.instigator === 'string' ? Promise.resolve(expectedChange.instigator) : expectedChange.instigator.getObjectName().catch(() => undefined))
@@ -434,6 +434,8 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
434
434
  expectedChange.effectCauser
435
435
  ? (typeof expectedChange.effectCauser === 'string' ? Promise.resolve(expectedChange.effectCauser) : expectedChange.effectCauser.getObjectName().catch(() => undefined))
436
436
  : Promise.resolve(undefined),
437
+ // The actor this checks: events come from every actor in the game
438
+ locator.getObjectName().catch(() => undefined),
437
439
  ]);
438
440
  initialValue = resolvedInitialVal;
439
441
  // Evaluates whether an event matches all expected criteria
@@ -444,6 +446,11 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
444
446
  if (event.eventName !== attributeName && !event.eventName?.includes(attributeName)) {
445
447
  return false;
446
448
  }
449
+ // Only changes to this actor's attributes count (the event's target is the avatar, a hero rather than its
450
+ // PlayerState). Engines older than the target field don't send it: those events can't be told apart.
451
+ if (targetName && event.target && event.target.trim() !== targetName.trim()) {
452
+ return false;
453
+ }
447
454
  lastEvent = event;
448
455
  lastFailedReasons = [];
449
456
  let isMatch = true;
@@ -526,6 +533,7 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
526
533
  // Verify whether any conflicting attribute change events arrived
527
534
  const conflictingEvent = capturedEvents.find(ev => (ev.eventType === specter_client_1.SpecterEventType.GameplayAttribute || ev.eventType === 'GameplayAttribute') &&
528
535
  (ev.eventName === attributeName || ev.eventName?.includes(attributeName)) &&
536
+ (!targetName || !ev.target || ev.target.trim() === targetName.trim()) &&
529
537
  parseFloat(ev.oldValue) !== parseFloat(ev.newValue));
530
538
  if (!conflictingEvent) {
531
539
  const currentVal = await locator.getAttributeValue(attributeSet, attributeName).catch(() => initialValue);
@@ -1618,3 +1626,24 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
1618
1626
  })();
1619
1627
  },
1620
1628
  }));
1629
+ /** One line for an attribute change event: what changed, on whom, and from what (the raw event was cut short in reports) */
1630
+ function describeAttributeChange(event) {
1631
+ if (!event || event.oldValue === undefined) {
1632
+ return JSON.stringify(event);
1633
+ }
1634
+ const oldValue = parseFloat(event.oldValue);
1635
+ const newValue = parseFloat(event.newValue);
1636
+ const delta = newValue - oldValue;
1637
+ const parts = [`${event.eventName} ${oldValue} -> ${newValue} (${delta >= 0 ? '+' : ''}${delta})`];
1638
+ if (event.target)
1639
+ parts.push(`on ${event.target}`);
1640
+ if (typeof event.timestamp === 'number')
1641
+ parts.push(`at ${event.timestamp.toFixed(2)}s`);
1642
+ if (event.gameplayEffect)
1643
+ parts.push(`effect ${event.gameplayEffect}`);
1644
+ if (event.instigator)
1645
+ parts.push(`instigator ${event.instigator}`);
1646
+ if (event.ability)
1647
+ parts.push(`ability ${event.ability}`);
1648
+ return parts.join(', ');
1649
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specter-automation/test",
3
- "version": "1.0.146",
3
+ "version": "1.0.148",
4
4
  "description": "Playwright integration for Unreal Engine automation via Specter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",