@sentry/wizard
Version:
Sentry wizard helping you to configure your project
122 lines (118 loc) • 4.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const templates_1 = require("../../src/cloudflare/templates");
(0, vitest_1.describe)('Cloudflare code templates', () => {
(0, vitest_1.describe)('getCloudflareWorkerTemplate', () => {
(0, vitest_1.it)('generates worker template with performance monitoring enabled', () => {
const template = (0, templates_1.getCloudflareWorkerTemplate)('my-dsn', {
performance: true,
logs: false,
});
(0, vitest_1.expect)(template).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/cloudflare';
export default Sentry.withSentry(
(env) => ({
dsn: 'my-dsn',
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
}),
{
async fetch(request, env, ctx): Promise<Response> {
// Your worker logic here
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>,
);
"
`);
});
(0, vitest_1.it)('generates worker template with performance monitoring disabled', () => {
const template = (0, templates_1.getCloudflareWorkerTemplate)('my-dsn', {
performance: false,
logs: false,
});
(0, vitest_1.expect)(template).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/cloudflare';
export default Sentry.withSentry(
(env) => ({
dsn: 'my-dsn',
}),
{
async fetch(request, env, ctx): Promise<Response> {
// Your worker logic here
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>,
);
"
`);
});
(0, vitest_1.it)('generates worker template with logs enabled', () => {
const template = (0, templates_1.getCloudflareWorkerTemplate)('my-dsn', {
performance: false,
logs: true,
});
(0, vitest_1.expect)(template).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/cloudflare';
export default Sentry.withSentry(
(env) => ({
dsn: 'my-dsn',
// Enable logs to be sent to Sentry
enableLogs: true,
}),
{
async fetch(request, env, ctx): Promise<Response> {
// Your worker logic here
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>,
);
"
`);
});
(0, vitest_1.it)('generates worker template with both performance and logs enabled', () => {
const template = (0, templates_1.getCloudflareWorkerTemplate)('my-dsn', {
performance: true,
logs: true,
});
(0, vitest_1.expect)(template).toMatchInlineSnapshot(`
"import * as Sentry from '@sentry/cloudflare';
export default Sentry.withSentry(
(env) => ({
dsn: 'my-dsn',
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
// Enable logs to be sent to Sentry
enableLogs: true,
}),
{
async fetch(request, env, ctx): Promise<Response> {
// Your worker logic here
return new Response('Hello World!');
},
} satisfies ExportedHandler<Env>,
);
"
`);
});
(0, vitest_1.it)('includes the correct DSN', () => {
const dsn = 'https://example@sentry.io/123';
const template = (0, templates_1.getCloudflareWorkerTemplate)(dsn, {
performance: true,
logs: false,
});
(0, vitest_1.expect)(template).toContain(`dsn: '${dsn}'`);
});
(0, vitest_1.it)('wraps handler with Sentry.withSentry', () => {
const template = (0, templates_1.getCloudflareWorkerTemplate)('my-dsn', {
performance: false,
logs: false,
});
(0, vitest_1.expect)(template).toContain('Sentry.withSentry');
(0, vitest_1.expect)(template).toContain('async fetch(request, env, ctx)');
(0, vitest_1.expect)(template).toContain('satisfies ExportedHandler<Env>');
});
});
});
//# sourceMappingURL=templates.test.js.map