Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Jul 8, 2022
1 parent 19d72d5 commit 4eefcdf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/nextjs/test/integration/test/server/tracing200.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = async ({ url: urlBase, argv }) => {
},
},
transaction: 'GET /api/users',
transaction_info: {
source: 'route',
},
type: 'transaction',
request: {
url,
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/test/integration/test/server/tracing500.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module.exports = async ({ url: urlBase, argv }) => {
},
},
transaction: 'GET /api/broken',
transaction_info: {
source: 'route',
},
type: 'transaction',
request: {
url,
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/test/integration/test/server/tracingHttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports = async ({ url: urlBase, argv }) => {
},
],
transaction: 'GET /api/http',
transaction_info: {
source: 'route',
},
type: 'transaction',
request: {
url,
Expand Down
18 changes: 18 additions & 0 deletions packages/nextjs/test/performance/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ describe('client', () => {
tags: {
'routing.instrumentation': 'next-router',
},
metadata: {
source: 'route',
},
});
});

Expand All @@ -68,6 +71,9 @@ describe('client', () => {
method: 'pushState',
'routing.instrumentation': 'next-router',
},
metadata: {
source: 'route',
},
},
],
[
Expand All @@ -81,6 +87,9 @@ describe('client', () => {
method: 'replaceState',
'routing.instrumentation': 'next-router',
},
metadata: {
source: 'route',
},
},
],
[
Expand All @@ -94,6 +103,9 @@ describe('client', () => {
method: 'pushState',
'routing.instrumentation': 'next-router',
},
metadata: {
source: 'route',
},
},
],
];
Expand All @@ -120,6 +132,9 @@ describe('client', () => {
name: '/login',
op: 'navigation',
tags: { from: '/[user]/posts/[id]', method: 'pushState', 'routing.instrumentation': 'next-router' },
metadata: {
source: 'route',
},
});

Router.router?.changeState('pushState', '/login', '/login', {});
Expand All @@ -131,6 +146,9 @@ describe('client', () => {
name: '/posts/[id]',
op: 'navigation',
tags: { from: '/login', method: 'pushState', 'routing.instrumentation': 'next-router' },
metadata: {
source: 'route',
},
});
});
});
Expand Down
26 changes: 26 additions & 0 deletions packages/nextjs/test/utils/withSentry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as hub from '@sentry/hub';
import * as Sentry from '@sentry/node';
import { Client, ClientOptions } from '@sentry/types';
import * as utils from '@sentry/utils';
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';

Expand Down Expand Up @@ -43,6 +45,7 @@ const flushSpy = jest.spyOn(Sentry, 'flush').mockImplementation(async () => {
await sleep(FLUSH_DURATION);
return true;
});
const startTransactionSpy = jest.spyOn(Sentry, 'startTransaction');

describe('withSentry', () => {
let req: NextApiRequest, res: NextApiResponse;
Expand Down Expand Up @@ -99,4 +102,27 @@ describe('withSentry', () => {
expect(loggerSpy).toHaveBeenCalledWith('Done flushing events');
});
});

describe('tracing', () => {
it('starts a transaction when tracing is enabled', async () => {
jest
.spyOn(hub.Hub.prototype, 'getClient')
.mockReturnValueOnce({ getOptions: () => ({ tracesSampleRate: 1 } as ClientOptions) } as Client);

await callWrappedHandler(wrappedHandlerNoError, req, res);

expect(startTransactionSpy).toHaveBeenCalledWith(
{
name: 'GET http://dogs.are.great',
op: 'http.server',

metadata: {
baggage: expect.any(Array),
source: 'route',
},
},
{ request: { url: 'http://dogs.are.great' } },
);
});
});
});

0 comments on commit 4eefcdf

Please sign in to comment.