|
| 1 | +const { |
| 2 | + expectRequestCount, |
| 3 | + isTransactionRequest, |
| 4 | + expectTransaction, |
| 5 | + extractEnvelopeFromRequest, |
| 6 | +} = require('../utils/client'); |
| 7 | +const assert = require('assert').strict; |
| 8 | + |
| 9 | +module.exports = async ({ page, url, requests }) => { |
| 10 | + await page.goto(`${url}/withServerSideProps`); |
| 11 | + await page.waitForRequest(isTransactionRequest); |
| 12 | + |
| 13 | + const transactionEnvelope = extractEnvelopeFromRequest(requests.transactions[0]); |
| 14 | + |
| 15 | + expectTransaction(requests.transactions[0], { |
| 16 | + contexts: { |
| 17 | + trace: { |
| 18 | + op: 'pageload', |
| 19 | + }, |
| 20 | + }, |
| 21 | + }); |
| 22 | + |
| 23 | + const nextDataTag = await page.waitForSelector('#__NEXT_DATA__'); |
| 24 | + const nextDataTagValue = JSON.parse(await nextDataTag.evaluate(tag => tag.innerText)); |
| 25 | + |
| 26 | + assert.strictEqual( |
| 27 | + nextDataTagValue.props.pageProps.data, |
| 28 | + '[some serverSidePropsData data]', |
| 29 | + 'Returned data must contain original data returned from getServerSideProps.', |
| 30 | + ); |
| 31 | + |
| 32 | + assert.strictEqual( |
| 33 | + nextDataTagValue.props.pageProps._sentryTraceData.split('-')[0], |
| 34 | + transactionEnvelope.envelopeHeader.trace.trace_id, |
| 35 | + 'Trace id in envelope header must be the same as in trace parent data returned from getServerSideProps', |
| 36 | + ); |
| 37 | + |
| 38 | + assert.strictEqual( |
| 39 | + nextDataTagValue.props.pageProps._sentryBaggage.match(/sentry-trace_id=([a-f0-9]*),/)[1], |
| 40 | + transactionEnvelope.envelopeHeader.trace.trace_id, |
| 41 | + 'Trace id in envelope header must be the same as in baggage returned from getServerSideProps', |
| 42 | + ); |
| 43 | + |
| 44 | + await expectRequestCount(requests, { transactions: 1 }); |
| 45 | +}; |
0 commit comments