Skip to content

Commit

Permalink
Add clientside getServerSideProps integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Aug 31, 2022
1 parent df1d3d9 commit 3f192f7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const WithServerSidePropsPage = ({ data }: { data: string }) => <h1>WithServerSidePropsPage {data}</h1>;

export async function getServerSideProps() {
throw new Error('ServerSideProps Error');
return { props: { data: '[some serverSidePropsData data]' } };
}

export default WithServerSidePropsPage;
Original file line number Diff line number Diff line change
@@ -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 });
};

0 comments on commit 3f192f7

Please sign in to comment.