@specter-automation/test 1.0.152 → 1.0.154
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.
|
@@ -10,6 +10,8 @@ export default class SpecterReporter implements Reporter {
|
|
|
10
10
|
private runEnded;
|
|
11
11
|
private testStepCounters;
|
|
12
12
|
private stepIdMap;
|
|
13
|
+
/** Specter expect steps whose wrapper step has started */
|
|
14
|
+
private wrappedExpectSteps;
|
|
13
15
|
/** Playwright's outer `Expect "<matcher>"` steps for Specter matchers. They are shown under their wrapper step's name. */
|
|
14
16
|
private specterExpectSteps;
|
|
15
17
|
/** Image paths already sent to the runner, per test, so step and test attachments aren't sent twice. */
|
|
@@ -49,8 +51,15 @@ export default class SpecterReporter implements Reporter {
|
|
|
49
51
|
onBegin(config: FullConfig, suite: Suite): void;
|
|
50
52
|
onTestBegin(test: TestCase): void;
|
|
51
53
|
private isNestedExpect;
|
|
52
|
-
/** The step opened by instrumentMatchers directly under a Specter expect step. */
|
|
54
|
+
/** The step opened by instrumentMatchers directly under a Specter expect step (the first one there). */
|
|
55
|
+
private specterWrapperSteps;
|
|
53
56
|
private isSpecterWrapper;
|
|
57
|
+
/**
|
|
58
|
+
* Any other step directly under a Specter expect step, opened after the matcher's own step ended: the failure
|
|
59
|
+
* screenshot a failing matcher takes, for one. Not shown as rows (and never taken for the wrapper, which would
|
|
60
|
+
* rename the expect step and leave rows that never end); their images still go to the expect step's row.
|
|
61
|
+
*/
|
|
62
|
+
private isExtraStepInMatcher;
|
|
54
63
|
private readPerfCapture;
|
|
55
64
|
private readMatcherReport;
|
|
56
65
|
private getParentStepName;
|
|
@@ -141,6 +141,8 @@ class SpecterReporter {
|
|
|
141
141
|
runEnded = false;
|
|
142
142
|
testStepCounters = new Map();
|
|
143
143
|
stepIdMap = new WeakMap();
|
|
144
|
+
/** Specter expect steps whose wrapper step has started */
|
|
145
|
+
wrappedExpectSteps = new WeakSet();
|
|
144
146
|
/** Playwright's outer `Expect "<matcher>"` steps for Specter matchers. They are shown under their wrapper step's name. */
|
|
145
147
|
specterExpectSteps = new WeakSet();
|
|
146
148
|
/** Image paths already sent to the runner, per test, so step and test attachments aren't sent twice. */
|
|
@@ -322,9 +324,19 @@ class SpecterReporter {
|
|
|
322
324
|
}
|
|
323
325
|
return false;
|
|
324
326
|
}
|
|
325
|
-
/** The step opened by instrumentMatchers directly under a Specter expect step. */
|
|
327
|
+
/** The step opened by instrumentMatchers directly under a Specter expect step (the first one there). */
|
|
328
|
+
specterWrapperSteps = new WeakSet();
|
|
326
329
|
isSpecterWrapper(step) {
|
|
327
|
-
return
|
|
330
|
+
return this.specterWrapperSteps.has(step);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Any other step directly under a Specter expect step, opened after the matcher's own step ended: the failure
|
|
334
|
+
* screenshot a failing matcher takes, for one. Not shown as rows (and never taken for the wrapper, which would
|
|
335
|
+
* rename the expect step and leave rows that never end); their images still go to the expect step's row.
|
|
336
|
+
*/
|
|
337
|
+
isExtraStepInMatcher(step) {
|
|
338
|
+
return step.category === 'test.step' && !!step.parent && this.specterExpectSteps.has(step.parent)
|
|
339
|
+
&& !this.specterWrapperSteps.has(step);
|
|
328
340
|
}
|
|
329
341
|
readPerfCapture(step) {
|
|
330
342
|
const attachment = step.attachments?.find(a => a.name === specter_perf_1.SPECTER_PERF_ATTACHMENT && a.body);
|
|
@@ -376,6 +388,14 @@ class SpecterReporter {
|
|
|
376
388
|
this.specterExpectSteps.add(step);
|
|
377
389
|
return;
|
|
378
390
|
}
|
|
391
|
+
// The first test.step under a Specter expect step is the matcher's wrapper; later ones are extras
|
|
392
|
+
if (step.category === 'test.step' && step.parent && this.specterExpectSteps.has(step.parent)) {
|
|
393
|
+
if (this.wrappedExpectSteps.has(step.parent)) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.wrappedExpectSteps.add(step.parent);
|
|
397
|
+
this.specterWrapperSteps.add(step);
|
|
398
|
+
}
|
|
379
399
|
const isCustomWrapper = this.isSpecterWrapper(step);
|
|
380
400
|
// 2. Ignore other expect wrapper steps (e.g. from helpers that title steps "expect(...)")
|
|
381
401
|
if (step.category === 'test.step' && step.title.startsWith('expect(') && !isCustomWrapper) {
|
|
@@ -429,8 +449,8 @@ class SpecterReporter {
|
|
|
429
449
|
}
|
|
430
450
|
return;
|
|
431
451
|
}
|
|
432
|
-
// 2. Ignore inner expect steps nested under matchers
|
|
433
|
-
if (this.isNestedExpect(step)) {
|
|
452
|
+
// 2. Ignore inner expect steps nested under matchers, and other steps a matcher opened after its own
|
|
453
|
+
if (this.isNestedExpect(step) || this.isExtraStepInMatcher(step)) {
|
|
434
454
|
return;
|
|
435
455
|
}
|
|
436
456
|
const isSpecterExpect = this.specterExpectSteps.has(step);
|
|
@@ -414,6 +414,9 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
414
414
|
const transport = locator.transport;
|
|
415
415
|
let lastEvent;
|
|
416
416
|
let lastFailedReasons = [];
|
|
417
|
+
// Each change to this actor's attribute that didn't match, and why (events are checked more than once)
|
|
418
|
+
const nearMisses = new Map();
|
|
419
|
+
let subjectName;
|
|
417
420
|
let initialValue;
|
|
418
421
|
// Synchronously register live listener immediately to capture all events during setup & action
|
|
419
422
|
const capturedEvents = [];
|
|
@@ -441,6 +444,7 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
441
444
|
locator.getObjectName().catch(() => undefined),
|
|
442
445
|
]);
|
|
443
446
|
initialValue = resolvedInitialVal;
|
|
447
|
+
subjectName = targetName;
|
|
444
448
|
// Evaluates whether an event matches all expected criteria
|
|
445
449
|
const evaluateEvent = (event) => {
|
|
446
450
|
if (event.eventType !== specter_client_1.SpecterEventType.GameplayAttribute && event.eventType !== 'GameplayAttribute') {
|
|
@@ -468,15 +472,16 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
468
472
|
Math.abs(Math.abs(actualDelta) - Math.abs(expDelta)) <= tolerance;
|
|
469
473
|
if (!deltaMatch) {
|
|
470
474
|
isMatch = false;
|
|
471
|
-
lastFailedReasons.push(`delta
|
|
475
|
+
lastFailedReasons.push(`delta: expected ${expDelta}, but it was ${actualDelta}`);
|
|
472
476
|
}
|
|
473
477
|
}
|
|
474
478
|
// 2. Instigator check
|
|
479
|
+
// The instigator is the ability system's owner, which is often the PlayerState rather than the
|
|
480
|
+
// hero: the hero is then the effect causer, and either one names who caused the change
|
|
475
481
|
if (expectedInstigatorName !== undefined) {
|
|
476
|
-
|
|
477
|
-
if (!inst || (!inst.includes(expectedInstigatorName) && !expectedInstigatorName.includes(inst))) {
|
|
482
|
+
if (!namesSource(expectedInstigatorName, event.instigator, event.effectCauser)) {
|
|
478
483
|
isMatch = false;
|
|
479
|
-
lastFailedReasons.push(`instigator
|
|
484
|
+
lastFailedReasons.push(`instigator: expected ${expectedInstigatorName}, but it came from ${describeSource(event)}`);
|
|
480
485
|
}
|
|
481
486
|
}
|
|
482
487
|
// 3. Effect Causer check
|
|
@@ -484,23 +489,27 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
484
489
|
const causer = (event.effectCauser || '').trim();
|
|
485
490
|
if (!causer || (!causer.includes(expectedEffectCauserName) && !expectedEffectCauserName.includes(causer))) {
|
|
486
491
|
isMatch = false;
|
|
487
|
-
lastFailedReasons.push(`effectCauser
|
|
492
|
+
lastFailedReasons.push(`effectCauser: expected ${expectedEffectCauserName}, but it was ${event.effectCauser || 'not recorded'}`);
|
|
488
493
|
}
|
|
489
494
|
}
|
|
490
495
|
// 4. Gameplay Effect check
|
|
491
496
|
if (expectedChange.gameplayEffect !== undefined) {
|
|
492
497
|
if (!event.gameplayEffect || (!event.gameplayEffect.includes(expectedChange.gameplayEffect) && !expectedChange.gameplayEffect.includes(event.gameplayEffect))) {
|
|
493
498
|
isMatch = false;
|
|
494
|
-
lastFailedReasons.push(`gameplayEffect
|
|
499
|
+
lastFailedReasons.push(`gameplayEffect: expected ${expectedChange.gameplayEffect}, but it was ${event.gameplayEffect || 'not recorded'}`);
|
|
495
500
|
}
|
|
496
501
|
}
|
|
497
502
|
// 5. Ability check
|
|
498
503
|
if (expectedChange.ability !== undefined) {
|
|
499
504
|
if (!event.ability || (!event.ability.includes(expectedChange.ability) && !expectedChange.ability.includes(event.ability))) {
|
|
500
505
|
isMatch = false;
|
|
501
|
-
lastFailedReasons.push(`ability
|
|
506
|
+
lastFailedReasons.push(`ability: expected ${expectedChange.ability}, but it was ${event.ability || 'not recorded'}`);
|
|
502
507
|
}
|
|
503
508
|
}
|
|
509
|
+
if (!isMatch) {
|
|
510
|
+
const key = `${event.timestamp}_${event.oldValue}_${event.newValue}_${event.instigator}_${event.gameplayEffect}_${event.networkRole}`;
|
|
511
|
+
nearMisses.set(key, { event, reasons: [...lastFailedReasons] });
|
|
512
|
+
}
|
|
504
513
|
return isMatch;
|
|
505
514
|
};
|
|
506
515
|
// --- 1. TRY ONCE IMMEDIATELY ---
|
|
@@ -610,10 +619,19 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
610
619
|
if (!e.message?.includes('Timed out')) {
|
|
611
620
|
throw e;
|
|
612
621
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
622
|
+
const subject = `${attributeName} on ${subjectName ?? locator.toString()}`;
|
|
623
|
+
const misses = [...nearMisses.values()];
|
|
624
|
+
let headline;
|
|
625
|
+
if (misses.length === 0) {
|
|
626
|
+
headline = `${subject} didn't change within ${timeout}ms.`;
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
const shown = misses.slice(-5);
|
|
630
|
+
headline = `${subject} changed ${misses.length === 1 ? 'once' : `${misses.length} times`} within ${timeout}ms, but no change matched:\n` +
|
|
631
|
+
shown.map(m => ` - ${describeChangeValues(m.event)}: ${m.reasons.join('; ')}`).join('\n') +
|
|
632
|
+
(misses.length > shown.length ? `\n - and ${misses.length - shown.length} earlier change(s)` : '');
|
|
616
633
|
}
|
|
634
|
+
const failureDetails = lastEvent ? `\n\nLast checked event: ${JSON.stringify(lastEvent, null, 2)}` : '';
|
|
617
635
|
let diagStr = '';
|
|
618
636
|
try {
|
|
619
637
|
const diags = await locator.getDiagnostics({
|
|
@@ -644,8 +662,8 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
644
662
|
return {
|
|
645
663
|
pass: false,
|
|
646
664
|
message: () => `${this.utils.matcherHint(assertionName, locator.toString(), expectedParts.join(', '))}\n\n` +
|
|
647
|
-
|
|
648
|
-
`Expected
|
|
665
|
+
`${headline}\n\n` +
|
|
666
|
+
`Expected: { ${expectedParts.join(', ')} }` +
|
|
649
667
|
failureDetails +
|
|
650
668
|
timelineStr +
|
|
651
669
|
diagStr,
|
|
@@ -926,10 +944,9 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
926
944
|
return false;
|
|
927
945
|
}
|
|
928
946
|
// Instigator match
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
if (!evInst.includes(cleanInst) && !cleanInst.includes(evInst)) {
|
|
947
|
+
// (the instigator or the effect causer: the instigator is often the PlayerState that owns the ability system)
|
|
948
|
+
if (expectedInstigatorName && (ev.instigator || ev.effectCauser)) {
|
|
949
|
+
if (!namesSource(expectedInstigatorName, ev.instigator, ev.effectCauser)) {
|
|
933
950
|
return false;
|
|
934
951
|
}
|
|
935
952
|
}
|
|
@@ -1629,6 +1646,38 @@ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
|
1629
1646
|
})();
|
|
1630
1647
|
},
|
|
1631
1648
|
}));
|
|
1649
|
+
/** Whether any of an event's source names (instigator, effect causer) names the expected actor */
|
|
1650
|
+
function namesSource(expected, ...names) {
|
|
1651
|
+
const want = expected.trim();
|
|
1652
|
+
if (!want)
|
|
1653
|
+
return false;
|
|
1654
|
+
return names.some(name => {
|
|
1655
|
+
const got = (name || '').trim();
|
|
1656
|
+
return !!got && (got.includes(want) || want.includes(got));
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
/** Who an event came from: its instigator, and its effect causer when that's a different actor */
|
|
1660
|
+
function describeSource(event) {
|
|
1661
|
+
const inst = (event?.instigator || '').trim();
|
|
1662
|
+
const causer = (event?.effectCauser || '').trim();
|
|
1663
|
+
if (!inst && !causer)
|
|
1664
|
+
return 'no recorded instigator';
|
|
1665
|
+
if (!causer || causer === inst)
|
|
1666
|
+
return inst;
|
|
1667
|
+
if (!inst)
|
|
1668
|
+
return `effect causer ${causer}`;
|
|
1669
|
+
return `${inst} (effect causer ${causer})`;
|
|
1670
|
+
}
|
|
1671
|
+
/** "2500 -> 2150 (-350) at 12.40s" */
|
|
1672
|
+
function describeChangeValues(event) {
|
|
1673
|
+
const oldValue = parseFloat(event?.oldValue);
|
|
1674
|
+
const newValue = parseFloat(event?.newValue);
|
|
1675
|
+
const delta = newValue - oldValue;
|
|
1676
|
+
let text = `${oldValue} -> ${newValue} (${delta >= 0 ? '+' : ''}${delta})`;
|
|
1677
|
+
if (typeof event?.timestamp === 'number')
|
|
1678
|
+
text += ` at ${event.timestamp.toFixed(2)}s`;
|
|
1679
|
+
return text;
|
|
1680
|
+
}
|
|
1632
1681
|
/** One line for an attribute change event: what changed, on whom, and from what (the raw event was cut short in reports) */
|
|
1633
1682
|
function describeAttributeChange(event) {
|
|
1634
1683
|
if (!event || event.oldValue === undefined) {
|
|
@@ -1646,6 +1695,8 @@ function describeAttributeChange(event) {
|
|
|
1646
1695
|
parts.push(`effect ${event.gameplayEffect}`);
|
|
1647
1696
|
if (event.instigator)
|
|
1648
1697
|
parts.push(`instigator ${event.instigator}`);
|
|
1698
|
+
if (event.effectCauser && event.effectCauser !== event.instigator)
|
|
1699
|
+
parts.push(`effect causer ${event.effectCauser}`);
|
|
1649
1700
|
if (event.ability)
|
|
1650
1701
|
parts.push(`ability ${event.ability}`);
|
|
1651
1702
|
return parts.join(', ');
|