-
-
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.
fix(remix): Support merging
json
responses from root loader functio…
…ns. (#5548) Introduces support of `json` responses while injecting `sentryTrace` and `sentryBaggage` into the `root` loader. Added a set of tests to ensure that we don't omit user-defined loader responses.
- Loading branch information
1 parent
8db56b1
commit 9d38065
Showing
6 changed files
with
214 additions
and
24 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
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
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
141 changes: 141 additions & 0 deletions
141
packages/remix/test/integration/test/client/root-loader.test.ts
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,141 @@ | ||
import { test, expect, Page } from '@playwright/test'; | ||
|
||
async function getRouteData(page: Page): Promise<any> { | ||
return page.evaluate('window.__remixContext.routeData').catch(err => { | ||
console.warn(err); | ||
|
||
return {}; | ||
}); | ||
} | ||
|
||
async function extractTraceAndBaggageFromMeta( | ||
page: Page, | ||
): Promise<{ sentryTrace?: string | null; sentryBaggage?: string | null }> { | ||
const sentryTraceTag = await page.$('meta[name="sentry-trace"]'); | ||
const sentryTraceContent = await sentryTraceTag?.getAttribute('content'); | ||
|
||
const sentryBaggageTag = await page.$('meta[name="baggage"]'); | ||
const sentryBaggageContent = await sentryBaggageTag?.getAttribute('content'); | ||
|
||
return { sentryTrace: sentryTraceContent, sentryBaggage: sentryBaggageContent }; | ||
} | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning an empty object.', async ({ page }) => { | ||
await page.goto('/?type=empty'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
sentryTrace, | ||
sentryBaggage, | ||
}); | ||
}); | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning a plain object.', async ({ page }) => { | ||
await page.goto('/?type=plain'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
data_one: [], | ||
data_two: 'a string', | ||
sentryTrace: sentryTrace, | ||
sentryBaggage: sentryBaggage, | ||
}); | ||
}); | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning a `JSON response`.', async ({ page }) => { | ||
await page.goto('/?type=json'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
data_one: [], | ||
data_two: 'a string', | ||
sentryTrace: sentryTrace, | ||
sentryBaggage: sentryBaggage, | ||
}); | ||
}); | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning `null`.', async ({ page }) => { | ||
await page.goto('/?type=null'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
sentryTrace: sentryTrace, | ||
sentryBaggage: sentryBaggage, | ||
}); | ||
}); | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning `undefined`.', async ({ page }) => { | ||
await page.goto('/?type=undefined'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
sentryTrace: sentryTrace, | ||
sentryBaggage: sentryBaggage, | ||
}); | ||
}); | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader throwing a redirection to a plain object.', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/?type=throwRedirect'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
sentryTrace: sentryTrace, | ||
sentryBaggage: sentryBaggage, | ||
}); | ||
}); | ||
|
||
test('should inject `sentry-trace` and `baggage` into root loader returning a redirection to a plain object', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/?type=returnRedirect'); | ||
|
||
const { sentryTrace, sentryBaggage } = await extractTraceAndBaggageFromMeta(page); | ||
|
||
expect(sentryTrace).toEqual(expect.any(String)); | ||
expect(sentryBaggage).toEqual(expect.any(String)); | ||
|
||
const rootData = (await getRouteData(page))['root']; | ||
|
||
expect(rootData).toMatchObject({ | ||
sentryTrace: sentryTrace, | ||
sentryBaggage: sentryBaggage, | ||
}); | ||
}); |
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
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