(expectedEvents: TestLogEntry[])
| 753 | * Unexpected VE events are ignored. |
| 754 | **/ |
| 755 | export async function expectVeEvents(expectedEvents: TestLogEntry[]): Promise<void> { |
| 756 | if (pendingEventExpectation) { |
| 757 | throw new Error('VE events expectation already set. Cannot set another one until the previous is resolved'); |
| 758 | } |
| 759 | const {promise, resolve: success, reject: fail} = Promise.withResolvers<void>(); |
| 760 | pendingEventExpectation = {expectedEvents, success, fail, unmatchedEvents: []}; |
| 761 | checkPendingEventExpectation(); |
| 762 | |
| 763 | const timeout = setTimeout(() => { |
| 764 | if (pendingEventExpectation?.missingEvents?.length) { |
| 765 | const allLogs = veDebugEventsLog.filter(ve => { |
| 766 | if ('interaction' in ve) { |
| 767 | // Very noisy in the error and not providing context |
| 768 | return ve.interaction !== 'SettingAccess'; |
| 769 | } |
| 770 | |
| 771 | return true; |
| 772 | }); |
| 773 | pendingEventExpectation.fail(new Error(` |
| 774 | Missing VE Events: |
| 775 | ${formatVeEvents(pendingEventExpectation.missingEvents)} |
| 776 | Unmatched VE Events: |
| 777 | ${formatVeEvents(pendingEventExpectation.unmatchedEvents)} |
| 778 | All events: |
| 779 | ${JSON.stringify(allLogs, null, 2)} |
| 780 | `)); |
| 781 | } |
| 782 | }, EVENT_EXPECTATION_TIMEOUT); |
| 783 | |
| 784 | return await promise.finally(() => { |
| 785 | clearTimeout(timeout); |
| 786 | pendingEventExpectation = null; |
| 787 | }); |
| 788 | } |
| 789 | |
| 790 | let numMatchedEvents = 0; |
| 791 |
nothing calls this directly
no test coverage detected