-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clientside getInitialProps integration test
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const WithInitialPropsPage = ({ data }: { data: string }) => <h1>WithInitialPropsPage {data}</h1>; | ||
|
||
WithInitialPropsPage.getInitialProps = () => { | ||
return { data: '[some getInitialProps data]' }; | ||
}; | ||
|
||
export default WithInitialPropsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
return { props: { data: '[some serverSidePropsData data]' } }; | ||
return { props: { data: '[some getServerSideProps data]' } }; | ||
} | ||
|
||
export default WithServerSidePropsPage; |
45 changes: 45 additions & 0 deletions
45
packages/nextjs/test/integration/test/client/tracingClientGetInitialProps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/withInitialProps`); | ||
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 getInitialProps data]', | ||
'Returned data must contain original data returned from getInitialProps.', | ||
); | ||
|
||
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 getInitialProps', | ||
); | ||
|
||
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 getInitialProps', | ||
); | ||
|
||
await expectRequestCount(requests, { transactions: 1 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters