Skip to content

Commit

Permalink
remove hasSentryCode check && adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed May 24, 2023
1 parent 78beffa commit df5667a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
7 changes: 0 additions & 7 deletions packages/sveltekit/src/vite/autoInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
const code = (await fs.promises.readFile(id, 'utf8')).toString();
const mod = parseModule(code);

const hasSentryContent = mod.imports.$items.find(importExpression => importExpression.from === '@sentry/sveltekit');
if (hasSentryContent) {
// eslint-disable-next-line no-console
debug && console.log(`Skipping wrapping ${id} because it already contains Sentry code`);
return false;
}

const program = mod.$ast.type === 'Program' && mod.$ast;
if (!program) {
// eslint-disable-next-line no-console
Expand Down
10 changes: 1 addition & 9 deletions packages/sveltekit/test/vite/autoInstrument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('canWrapLoad', () => {
`import type { LayoutLoad } from './$types';
export const load : LayoutLoad = async () => { return { props: { msg: "hi" } } }`,
],
])('returns `true` if a load declaration (%s) exists and no Sentry code was found', async (_, code) => {
])('returns `true` if a load declaration (%s) exists', async (_, code) => {
fileContent = code;
expect(await canWrapLoad('+page.ts', false)).toEqual(true);
});
Expand All @@ -209,12 +209,4 @@ describe('canWrapLoad', () => {
fileContent = code;
expect(await canWrapLoad('+page.ts', false)).toEqual(true);
});

it.each([
'import * as Sentry from "@sentry/sveltekit"; export const prerender = true;',
'export const a = 1; import { init } from "@sentry/sveltekit"; export const load = () => {}',
])('returns `false` if Sentry code was found', async code => {
fileContent = code;
expect(await canWrapLoad('+page.ts', false)).toEqual(false);
});
});

0 comments on commit df5667a

Please sign in to comment.