From 3f192f7634522d47152aa389ac3260b831c251c5 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 31 Aug 2022 09:26:30 +0000 Subject: [PATCH] Add clientside getServerSideProps integration test --- .../integration/pages/withServerSideProps.tsx | 2 +- .../client/tracingClientGetServerSideProps.js | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/nextjs/test/integration/test/client/tracingClientGetServerSideProps.js diff --git a/packages/nextjs/test/integration/pages/withServerSideProps.tsx b/packages/nextjs/test/integration/pages/withServerSideProps.tsx index dda4f8f31dd2..e0220a577586 100644 --- a/packages/nextjs/test/integration/pages/withServerSideProps.tsx +++ b/packages/nextjs/test/integration/pages/withServerSideProps.tsx @@ -1,7 +1,7 @@ const WithServerSidePropsPage = ({ data }: { data: string }) =>

WithServerSidePropsPage {data}

; export async function getServerSideProps() { - throw new Error('ServerSideProps Error'); + return { props: { data: '[some serverSidePropsData data]' } }; } export default WithServerSidePropsPage; diff --git a/packages/nextjs/test/integration/test/client/tracingClientGetServerSideProps.js b/packages/nextjs/test/integration/test/client/tracingClientGetServerSideProps.js new file mode 100644 index 000000000000..4b3f4a5b8337 --- /dev/null +++ b/packages/nextjs/test/integration/test/client/tracingClientGetServerSideProps.js @@ -0,0 +1,45 @@ +const { + expectRequestCount, + isTransactionRequest, + expectTransaction, + extractEnvelopeFromRequest, +} = require('../utils/client'); +const assert = require('assert').strict; + +module.exports = async ({ page, url, requests }) => { + await page.goto(`${url}/withServerSideProps`); + await page.waitForRequest(isTransactionRequest); + + const transactionEnvelope = extractEnvelopeFromRequest(requests.transactions[0]); + + expectTransaction(requests.transactions[0], { + contexts: { + trace: { + op: 'pageload', + }, + }, + }); + + const nextDataTag = await page.waitForSelector('#__NEXT_DATA__'); + const nextDataTagValue = JSON.parse(await nextDataTag.evaluate(tag => tag.innerText)); + + assert.strictEqual( + nextDataTagValue.props.pageProps.data, + '[some serverSidePropsData data]', + 'Returned data must contain original data returned from getServerSideProps.', + ); + + assert.strictEqual( + nextDataTagValue.props.pageProps._sentryTraceData.split('-')[0], + transactionEnvelope.envelopeHeader.trace.trace_id, + 'Trace id in envelope header must be the same as in trace parent data returned from getServerSideProps', + ); + + assert.strictEqual( + nextDataTagValue.props.pageProps._sentryBaggage.match(/sentry-trace_id=([a-f0-9]*),/)[1], + transactionEnvelope.envelopeHeader.trace.trace_id, + 'Trace id in envelope header must be the same as in baggage returned from getServerSideProps', + ); + + await expectRequestCount(requests, { transactions: 1 }); +};