-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(e2e): Fix node E2E test app #11682
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
dev-packages/e2e-tests/test-applications/node-express-app/tests/error.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError } from '@sentry-internal/event-proxy-server'; | ||
import axios, { AxiosError, AxiosResponse } from 'axios'; | ||
|
||
const authToken = process.env.E2E_TEST_AUTH_TOKEN; | ||
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG; | ||
const sentryTestProject = process.env.E2E_TEST_SENTRY_TEST_PROJECT; | ||
const EVENT_POLLING_TIMEOUT = 90_000; | ||
|
||
test('Sends exception to Sentry', async ({ baseURL }) => { | ||
const { data } = await axios.get(`${baseURL}/test-error`); | ||
const { exceptionId } = data; | ||
|
||
const url = `https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionId}/`; | ||
|
||
console.log(`Polling for error eventId: ${exceptionId}`); | ||
|
||
await expect | ||
.poll( | ||
async () => { | ||
try { | ||
const response = await axios.get(url, { headers: { Authorization: `Bearer ${authToken}` } }); | ||
|
||
return response.status; | ||
} catch (e) { | ||
if (e instanceof AxiosError && e.response) { | ||
if (e.response.status !== 404) { | ||
throw e; | ||
} else { | ||
return e.response.status; | ||
} | ||
} else { | ||
throw e; | ||
} | ||
} | ||
}, | ||
{ timeout: EVENT_POLLING_TIMEOUT }, | ||
) | ||
.toBe(200); | ||
}); | ||
|
||
test('Sends correct error event', async ({ baseURL }) => { | ||
const errorEventPromise = waitForError('node-express-app', event => { | ||
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123'; | ||
}); | ||
|
||
try { | ||
await axios.get(`${baseURL}/test-exception/123`); | ||
} catch { | ||
// this results in an error, but we don't care - we want to check the error event | ||
} | ||
|
||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.exception?.values).toHaveLength(1); | ||
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123'); | ||
|
||
expect(errorEvent.request).toEqual({ | ||
method: 'GET', | ||
cookies: {}, | ||
headers: expect.any(Object), | ||
url: 'http://localhost:3030/test-exception/123', | ||
}); | ||
|
||
expect(errorEvent.transaction).toEqual('GET /test-exception/:id'); | ||
|
||
expect(errorEvent.contexts?.trace).toEqual({ | ||
trace_id: expect.any(String), | ||
span_id: expect.any(String), | ||
}); | ||
}); | ||
|
||
test('Should record caught exceptions with local variable', async ({ baseURL }) => { | ||
const { data } = await axios.get(`${baseURL}/test-local-variables-caught`); | ||
const { exceptionId } = data; | ||
|
||
const url = `https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionId}/json/`; | ||
|
||
console.log(`Polling for error eventId: ${exceptionId}`); | ||
|
||
let response: AxiosResponse; | ||
|
||
await expect | ||
.poll( | ||
async () => { | ||
try { | ||
response = await axios.get(url, { headers: { Authorization: `Bearer ${authToken}` } }); | ||
|
||
return response.status; | ||
} catch (e) { | ||
if (e instanceof AxiosError && e.response) { | ||
if (e.response.status !== 404) { | ||
throw e; | ||
} else { | ||
return e.response.status; | ||
} | ||
} else { | ||
throw e; | ||
} | ||
} | ||
}, | ||
{ timeout: EVENT_POLLING_TIMEOUT }, | ||
) | ||
.toBe(200); | ||
|
||
const frames = response!.data.exception.values[0].stacktrace.frames; | ||
|
||
expect(frames[frames.length - 1].vars?.randomVariableToRecord).toBeDefined(); | ||
}); | ||
|
||
test('Should record uncaught exceptions with local variable', async ({ baseURL }) => { | ||
const errorEventPromise = waitForError('node-express-app', errorEvent => { | ||
return !!errorEvent?.exception?.values?.[0]?.value?.includes('Uncaught Local Variable Error'); | ||
}); | ||
|
||
await axios.get(`${baseURL}/test-local-variables-uncaught`).catch(() => { | ||
// noop | ||
}); | ||
|
||
const routehandlerError = await errorEventPromise; | ||
|
||
const frames = routehandlerError!.exception!.values![0]!.stacktrace!.frames!; | ||
|
||
expect(frames[frames.length - 1].vars?.randomVariableToRecord).toBeDefined(); | ||
}); |
227 changes: 0 additions & 227 deletions
227
dev-packages/e2e-tests/test-applications/node-express-app/tests/server.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is new