-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(remix): Add server-side instrumentation integration tests. (#5538)
Adds a basic set of tests to ensure `loader`, `action` and `documentRequest` functions are properly instrumented. Also, switches `node-integration-test` utilities to use `axios` to simulate requests, instead of `http` package, to easily switch between `post` and `get` requests.
- Loading branch information
1 parent
b903fd1
commit 11bb8ed
Showing
10 changed files
with
343 additions
and
16 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
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
31 changes: 31 additions & 0 deletions
31
packages/remix/test/integration/app/routes/action-json-response/$id.tsx
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,31 @@ | ||
import { ActionFunction, json, redirect, LoaderFunction } from '@remix-run/node'; | ||
import { useActionData } from '@remix-run/react'; | ||
|
||
export const loader: LoaderFunction = async ({ params: { id } }) => { | ||
if (id === '-1') { | ||
throw new Error('Unexpected Server Error from Loader'); | ||
} | ||
}; | ||
|
||
export const action: ActionFunction = async ({ params: { id } }) => { | ||
if (id === '-1') { | ||
throw new Error('Unexpected Server Error'); | ||
} | ||
|
||
if (id === '-2') { | ||
// Note: This GET request triggers to the `Loader` of the URL, not the `Action`. | ||
throw redirect('/action-json-response/-1'); | ||
} | ||
|
||
return json({ test: 'test' }); | ||
}; | ||
|
||
export default function ActionJSONResponse() { | ||
const data = useActionData(); | ||
|
||
return ( | ||
<div> | ||
<h1>{data && data.test ? data.test : 'Not Found'}</h1> | ||
</div> | ||
); | ||
} |
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
131 changes: 131 additions & 0 deletions
131
packages/remix/test/integration/test/server/action.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,131 @@ | ||
import { | ||
assertSentryTransaction, | ||
getEnvelopeRequest, | ||
runServer, | ||
getMultipleEnvelopeRequest, | ||
assertSentryEvent, | ||
} from './utils/helpers'; | ||
|
||
jest.spyOn(console, 'error').mockImplementation(); | ||
|
||
describe('Remix API Actions', () => { | ||
it('correctly instruments a parameterized Remix API action', async () => { | ||
const baseURL = await runServer(); | ||
const url = `${baseURL}/action-json-response/123123`; | ||
const envelope = await getEnvelopeRequest(url, 'post'); | ||
const transaction = envelope[2]; | ||
|
||
assertSentryTransaction(transaction, { | ||
transaction: 'routes/action-json-response/$id', | ||
spans: [ | ||
{ | ||
description: 'routes/action-json-response/$id', | ||
op: 'remix.server.action', | ||
}, | ||
{ | ||
description: 'routes/action-json-response/$id', | ||
op: 'remix.server.loader', | ||
}, | ||
{ | ||
description: 'routes/action-json-response/$id', | ||
op: 'remix.server.documentRequest', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('reports an error thrown from the action', async () => { | ||
const baseURL = await runServer(); | ||
const url = `${baseURL}/action-json-response/-1`; | ||
|
||
const [transaction, event] = await getMultipleEnvelopeRequest(url, 2, 'post'); | ||
|
||
assertSentryTransaction(transaction[2], { | ||
contexts: { | ||
trace: { | ||
status: 'internal_error', | ||
tags: { | ||
'http.status_code': '500', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
assertSentryEvent(event[2], { | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'Unexpected Server Error', | ||
stacktrace: expect.any(Object), | ||
mechanism: { | ||
data: { | ||
function: 'action', | ||
}, | ||
handled: true, | ||
type: 'instrument', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it('handles a thrown 500 response', async () => { | ||
const baseURL = await runServer(); | ||
const url = `${baseURL}/action-json-response/-2`; | ||
|
||
const [transaction_1, event, transaction_2] = await getMultipleEnvelopeRequest(url, 3, 'post'); | ||
|
||
assertSentryTransaction(transaction_1[2], { | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
status: 'ok', | ||
tags: { | ||
method: 'POST', | ||
'http.status_code': '302', | ||
}, | ||
}, | ||
}, | ||
tags: { | ||
transaction: 'routes/action-json-response/$id', | ||
}, | ||
}); | ||
|
||
assertSentryTransaction(transaction_2[2], { | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
status: 'internal_error', | ||
tags: { | ||
method: 'GET', | ||
'http.status_code': '500', | ||
}, | ||
}, | ||
}, | ||
tags: { | ||
transaction: 'routes/action-json-response/$id', | ||
}, | ||
}); | ||
|
||
assertSentryEvent(event[2], { | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'Unexpected Server Error from Loader', | ||
stacktrace: expect.any(Object), | ||
mechanism: { | ||
data: { | ||
function: 'loader', | ||
}, | ||
handled: true, | ||
type: 'instrument', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.