Skip to content
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

test(e2e): Unflake NestJS e2e tests #13188

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ Sentry.init({
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
transportOptions: {
// We expect the app to send a lot of events in a short time
bufferSize: 1000,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'nestjs',
proxyServerName: 'nestjs-basic',
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForEnvelopeItem } from '@sentry-internal/test-utils';

test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
const inProgressEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
const inProgressEnvelopePromise = waitForEnvelopeItem('nestjs-basic', envelope => {
return envelope[0].type === 'check_in';
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';

test('Sends exception to Sentry', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs', event => {
const errorEventPromise = waitForError('nestjs-basic', event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123';
});

Expand Down Expand Up @@ -32,27 +32,27 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
test('Does not send HttpExceptions to Sentry', async ({ baseURL }) => {
let errorEventOccurred = false;

waitForError('nestjs', event => {
waitForError('nestjs-basic', event => {
if (!event.type && event.exception?.values?.[0]?.value === 'This is an expected 400 exception with id 123') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /test-expected-400-exception/:id';
});

waitForError('nestjs', event => {
waitForError('nestjs-basic', event => {
if (!event.type && event.exception?.values?.[0]?.value === 'This is an expected 500 exception with id 123') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /test-expected-500-exception/:id';
});

const transactionEventPromise400 = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise400 = waitForTransaction('nestjs-basic', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-expected-400-exception/:id';
});

const transactionEventPromise500 = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise500 = waitForTransaction('nestjs-basic', transactionEvent => {
return transactionEvent?.transaction === 'GET /test-expected-500-exception/:id';
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test('Transaction includes span and correct value for decorated async function', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
test('Transaction includes span and correct value for decorated async function', async ({ request }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: Here is one request left. Seems to work nevertheless but probably nicer to be consistent.

const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-span-decorator-async'
);
});

const response = await fetch(`${baseURL}/test-span-decorator-async`);
const response = await request.get(`/test-span-decorator-async`);
const body = await response.json();

expect(body.result).toEqual('test');
Expand Down Expand Up @@ -37,7 +37,7 @@ test('Transaction includes span and correct value for decorated async function',
});

test('Transaction includes span and correct value for decorated sync function', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-span-decorator-sync'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test('Sends an API route transaction', async ({ baseURL }) => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-transaction'
Expand Down Expand Up @@ -125,7 +125,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
test('API route transaction includes nest middleware span. Spans created in and after middleware are nested correctly', async ({
baseURL,
}) => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-middleware-instrumentation'
Expand Down Expand Up @@ -205,7 +205,7 @@ test('API route transaction includes nest middleware span. Spans created in and
test('API route transaction includes nest guard span and span started in guard is nested correctly', async ({
baseURL,
}) => {
const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-guard-instrumentation'
Expand Down Expand Up @@ -268,10 +268,11 @@ test('API route transaction includes nest guard span and span started in guard i
});

test('API route transaction includes nest pipe span for valid request', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-pipe-instrumentation/:id'
transactionEvent?.transaction === 'GET /test-pipe-instrumentation/:id' &&
transactionEvent?.request?.url?.includes('/test-pipe-instrumentation/123')
);
});

Expand Down Expand Up @@ -304,10 +305,11 @@ test('API route transaction includes nest pipe span for valid request', async ({
});

test('API route transaction includes nest pipe span for invalid request', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-pipe-instrumentation/:id'
transactionEvent?.transaction === 'GET /test-pipe-instrumentation/:id' &&
transactionEvent?.request?.url?.includes('/test-pipe-instrumentation/abc')
);
});

Expand Down Expand Up @@ -342,7 +344,7 @@ test('API route transaction includes nest pipe span for invalid request', async
test('API route transaction includes nest interceptor span. Spans created in and after interceptor are nested correctly', async ({
baseURL,
}) => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-interceptor-instrumentation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ Sentry.init({
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
transportOptions: {
// We expect the app to send a lot of events in a short time
bufferSize: 1000,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'nestjs',
proxyServerName: 'nestjs-distributed-tracing',
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { SpanJSON } from '@sentry/types';
test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
const id = crypto.randomUUID();

const inboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const inboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-inbound-headers/${id}`
);
});

const outboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const outboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-outgoing-http/${id}`
Expand Down Expand Up @@ -66,7 +66,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
'http.method': 'GET',
'http.scheme': 'http',
'http.target': `/test-outgoing-http/${id}`,
'http.user_agent': 'node',
'http.user_agent': expect.any(String),
'http.flavor': '1.1',
'net.transport': 'ip_tcp',
'net.host.ip': expect.any(String),
Expand Down Expand Up @@ -121,14 +121,14 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => {
test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
const id = crypto.randomUUID();

const inboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const inboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-inbound-headers/${id}`
);
});

const outboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const outboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-outgoing-fetch/${id}`
Expand Down Expand Up @@ -181,7 +181,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
'http.method': 'GET',
'http.scheme': 'http',
'http.target': `/test-outgoing-fetch/${id}`,
'http.user_agent': 'node',
'http.user_agent': expect.any(String),
'http.flavor': '1.1',
'net.transport': 'ip_tcp',
'net.host.ip': expect.any(String),
Expand Down Expand Up @@ -234,7 +234,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => {
});

test('Propagates trace for outgoing external http requests', async ({ baseURL }) => {
const inboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const inboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-outgoing-http-external-allowed`
Expand Down Expand Up @@ -271,7 +271,7 @@ test('Propagates trace for outgoing external http requests', async ({ baseURL })
});

test('Does not propagate outgoing http requests not covered by tracePropagationTargets', async ({ baseURL }) => {
const inboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const inboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-outgoing-http-external-disallowed`
Expand All @@ -295,7 +295,7 @@ test('Does not propagate outgoing http requests not covered by tracePropagationT
});

test('Propagates trace for outgoing external fetch requests', async ({ baseURL }) => {
const inboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const inboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-outgoing-fetch-external-allowed`
Expand Down Expand Up @@ -332,7 +332,7 @@ test('Propagates trace for outgoing external fetch requests', async ({ baseURL }
});

test('Does not propagate outgoing fetch requests not covered by tracePropagationTargets', async ({ baseURL }) => {
const inboundTransactionPromise = waitForTransaction('nestjs', transactionEvent => {
const inboundTransactionPromise = waitForTransaction('nestjs-distributed-tracing', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.data?.['http.target'] === `/test-outgoing-fetch-external-disallowed`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ Sentry.init({
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
transportOptions: {
// We expect the app to send a lot of events in a short time
bufferSize: 1000,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'nestjs',
proxyServerName: 'nestjs-with-submodules',
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';

test('Sends unexpected exception to Sentry if thrown in module with global filter', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs', event => {
const errorEventPromise = waitForError('nestjs-with-submodules', event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

Expand Down Expand Up @@ -32,7 +32,7 @@ test('Sends unexpected exception to Sentry if thrown in module with global filte
test('Sends unexpected exception to Sentry if thrown in module that was registered before Sentry', async ({
baseURL,
}) => {
const errorEventPromise = waitForError('nestjs', event => {
const errorEventPromise = waitForError('nestjs-with-submodules', event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

Expand Down Expand Up @@ -64,15 +64,15 @@ test('Does not send exception to Sentry if user-defined global exception filter
}) => {
let errorEventOccurred = false;

waitForError('nestjs', event => {
waitForError('nestjs-with-submodules', event => {
if (!event.type && event.exception?.values?.[0]?.value === 'Something went wrong in the example module!') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /example-module/expected-exception';
});

const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module/expected-exception';
});

Expand All @@ -91,7 +91,7 @@ test('Does not send exception to Sentry if user-defined local exception filter a
}) => {
let errorEventOccurred = false;

waitForError('nestjs', event => {
waitForError('nestjs-with-submodules', event => {
if (
!event.type &&
event.exception?.values?.[0]?.value === 'Something went wrong in the example module with local filter!'
Expand All @@ -102,7 +102,7 @@ test('Does not send exception to Sentry if user-defined local exception filter a
return event?.transaction === 'GET /example-module-local-filter/expected-exception';
});

const transactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module-local-filter/expected-exception';
});

Expand All @@ -119,7 +119,7 @@ test('Does not send exception to Sentry if user-defined local exception filter a
test('Does not handle expected exception if exception is thrown in module registered before Sentry', async ({
baseURL,
}) => {
const errorEventPromise = waitForError('nestjs', event => {
const errorEventPromise = waitForError('nestjs-with-submodules', event => {
return !event.type && event.exception?.values?.[0]?.value === 'Something went wrong in the example module!';
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test('Sends an API route transaction from module', async ({ baseURL }) => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs', transactionEvent => {
const pageloadTransactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /example-module/transaction'
Expand Down
Loading