Skip to content

Commit

Permalink
test(e2e): Unflake NestJS e2e tests (#13188)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Aug 5, 2024
1 parent 7ad5054 commit 5f4a71c
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 71 deletions.
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,11 +2,11 @@ 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' && envelope[1]['status'] === 'in_progress';
});

const okEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
const okEnvelopePromise = waitForEnvelopeItem('nestjs-basic', envelope => {
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'ok';
});

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
Expand Up @@ -2,7 +2,7 @@ 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 => {
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-span-decorator-async'
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
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: 'node-nestjs-basic',
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ 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('node-nestjs-basic', envelope => {
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'in_progress';
});

const okEnvelopePromise = waitForEnvelopeItem('nestjs', envelope => {
const okEnvelopePromise = waitForEnvelopeItem('node-nestjs-basic', envelope => {
return envelope[0].type === 'check_in' && envelope[1]['status'] === 'ok';
});

Expand Down
Loading

0 comments on commit 5f4a71c

Please sign in to comment.