Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
test: Introduce .unordered in node-integration-tests#21697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -131,6 +131,7 @@ export function createRunner(...paths: string[]) { | ||
| const flags: string[] = []; | ||
| // By default, we ignore session & sessions | ||
| const ignored: Set<EnvelopeItemType> = new Set(['session', 'sessions', 'client_report']); | ||
| let unordered = false; | ||
| let withEnv: Record<string, string> = {}; | ||
| let withSentryServer = false; | ||
| let dockerOptions: DockerOptions | undefined; | ||
| @@ -211,6 +212,10 @@ export function createRunner(...paths: string[]) { | ||
| } | ||
| return this; | ||
| }, | ||
| unordered: function () { | ||
| unordered = true; | ||
| return this; | ||
| }, | ||
| withDockerCompose: function (options: DockerOptions) { | ||
| dockerOptions = options; | ||
| return this; | ||
| @@ -284,58 +289,50 @@ export function createRunner(...paths: string[]) { | ||
| return; | ||
| } | ||
| const expected = expectedEnvelopes.shift(); | ||
| if (unordered) { | ||
| const matchIndex = expectedEnvelopes.findIndex(candidate => { | ||
| const candidateType = Object.keys(candidate)[0]; | ||
| if (candidateType !== envelopeItemType) { | ||
| return false; | ||
| } | ||
| try { | ||
| assertExpectedEnvelope(candidate, item); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }); | ||
| // Catch any error or failed assertions and pass them to done to end the test quickly | ||
| try { | ||
| if (!expected) { | ||
| if (matchIndex < 0) { | ||
| return; | ||
| } | ||
sentry[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const expectedType = Object.keys(expected)[0]; | ||
| expectedEnvelopes.splice(matchIndex, 1); | ||
| expectCallbackCalled(); | ||
| } else { | ||
| const expected = expectedEnvelopes.shift(); | ||
| if (expectedType !== envelopeItemType) { | ||
| throw new Error( | ||
| `Expected envelope item type '${expectedType}' but got '${envelopeItemType}'. \nItem: ${JSON.stringify( | ||
| item, | ||
| )}`, | ||
| ); | ||
| } | ||
| // Catch any error or failed assertions and pass them to done to end the test quickly | ||
| try { | ||
| if (!expected) { | ||
| return; | ||
| } | ||
| if ('event' in expected) { | ||
| expectErrorEvent(item[1] as Event, expected.event); | ||
| expectCallbackCalled(); | ||
JPeer264 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } else if ('transaction' in expected) { | ||
| expectTransactionEvent(item[1] as TransactionEvent, expected.transaction); | ||
| expectCallbackCalled(); | ||
| } else if ('session' in expected) { | ||
| expectSessionEvent(item[1] as SerializedSession, expected.session); | ||
| expectCallbackCalled(); | ||
| } else if ('sessions' in expected) { | ||
| expectSessionsEvent(item[1] as SessionAggregates, expected.sessions); | ||
| expectCallbackCalled(); | ||
| } else if ('check_in' in expected) { | ||
| expectCheckInEvent(item[1] as SerializedCheckIn, expected.check_in); | ||
| expectCallbackCalled(); | ||
| } else if ('client_report' in expected) { | ||
| expectClientReport(item[1] as ClientReport, expected.client_report); | ||
| expectCallbackCalled(); | ||
| } else if ('log' in expected) { | ||
| expectLog(item[1] as SerializedLogContainer, expected.log); | ||
| expectCallbackCalled(); | ||
| } else if ('trace_metric' in expected) { | ||
| expectMetric(item[1] as SerializedMetricContainer, expected.trace_metric); | ||
| expectCallbackCalled(); | ||
| } else if ('span' in expected) { | ||
| expectSpanContainer(item[1] as SerializedStreamedSpanContainer, expected.span); | ||
| const expectedType = Object.keys(expected)[0]; | ||
| if (expectedType !== envelopeItemType) { | ||
| throw new Error( | ||
| `Expected envelope item type '${expectedType}' but got '${envelopeItemType}'. \nItem: ${JSON.stringify( | ||
| item, | ||
| )}`, | ||
| ); | ||
| } | ||
| assertExpectedEnvelope(expected, item); | ||
| expectCallbackCalled(); | ||
| } else { | ||
| throw new Error( | ||
| `Unhandled expected envelope item type: ${JSON.stringify(expected)}\nItem: ${JSON.stringify(item)}`, | ||
| ); | ||
| } catch (e) { | ||
| complete(e as Error); | ||
| } | ||
| } catch (e) { | ||
| complete(e as Error); | ||
| } | ||
| } | ||
| } | ||
| @@ -641,6 +638,32 @@ function expectErrorEvent(item: Event, expected: ExpectedEvent): void { | ||
| } | ||
| } | ||
| function assertExpectedEnvelope(expected: Expected, item: Envelope[1][number]): void { | ||
| if ('event' in expected) { | ||
| expectErrorEvent(item[1] as Event, expected.event); | ||
| } else if ('transaction' in expected) { | ||
| expectTransactionEvent(item[1] as TransactionEvent, expected.transaction); | ||
| } else if ('session' in expected) { | ||
| expectSessionEvent(item[1] as SerializedSession, expected.session); | ||
| } else if ('sessions' in expected) { | ||
| expectSessionsEvent(item[1] as SessionAggregates, expected.sessions); | ||
| } else if ('check_in' in expected) { | ||
| expectCheckInEvent(item[1] as SerializedCheckIn, expected.check_in); | ||
| } else if ('client_report' in expected) { | ||
| expectClientReport(item[1] as ClientReport, expected.client_report); | ||
| } else if ('log' in expected) { | ||
| expectLog(item[1] as SerializedLogContainer, expected.log); | ||
| } else if ('trace_metric' in expected) { | ||
| expectMetric(item[1] as SerializedMetricContainer, expected.trace_metric); | ||
| } else if ('span' in expected) { | ||
| expectSpanContainer(item[1] as SerializedStreamedSpanContainer, expected.span); | ||
| } else { | ||
| throw new Error( | ||
| `Unhandled expected envelope item type: ${JSON.stringify(expected)}\nItem: ${JSON.stringify(item)}`, | ||
| ); | ||
| } | ||
| } | ||
| function expectTransactionEvent(item: TransactionEvent, expected: ExpectedTransaction): void { | ||
| if (typeof expected === 'function') { | ||
| expected(item); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.