Skip to content

Commit

Permalink
feat(angular): Add Angular menu option and install SDK (#765)
Browse files Browse the repository at this point in the history
Adds Angular menu option with SDK installation

---------

Co-authored-by: Andrei <[email protected]>
  • Loading branch information
onurtemizkan and andreiborza authored Jan 22, 2025
1 parent e706055 commit 8181920
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 78 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/tests/nextjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const onRequestError = Sentry.captureRequestError;`,
});

test('builds correctly', async () => {
await checkIfBuilds(projectDir, 'server-rendered on demand');
await checkIfBuilds(projectDir);
});

test('runs on prod mode correctly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/tests/nuxt-3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function testNuxtProjectConfigs(projectDir: string) {

function testNuxtProjectBuildsAndRuns(projectDir: string) {
test('builds successfully', async () => {
await checkIfBuilds(projectDir, 'preview this build');
await checkIfBuilds(projectDir);
});

test('runs on prod mode correctly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/tests/nuxt-4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function testNuxtProjectConfigs(projectDir: string) {

function testNuxtProjectBuildsAndRuns(projectDir: string) {
test('builds successfully', async () => {
await checkIfBuilds(projectDir, 'preview this build');
await checkIfBuilds(projectDir);
});

test('runs on prod mode correctly', async () => {
Expand Down
49 changes: 30 additions & 19 deletions e2e-tests/tests/remix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,27 @@ app.all(
app.listen(0, () => console.log('Express server listening'));
`;


async function runWizardOnRemixProject(projectDir: string, integration: Integration, fileModificationFn?: (projectDir: string, integration: Integration) => unknown) {
async function runWizardOnRemixProject(
projectDir: string,
integration: Integration,
fileModificationFn?: (
projectDir: string,
integration: Integration,
) => unknown,
) {
const wizardInstance = startWizardInstance(integration, projectDir);
let packageManagerPrompted = false;

if (fileModificationFn) {
fileModificationFn(projectDir, integration);

await wizardInstance.waitForOutput(
'Do you want to continue anyway?',
);
await wizardInstance.waitForOutput('Do you want to continue anyway?');

packageManagerPrompted = await wizardInstance.sendStdinAndWaitForOutput(
[KEYS.ENTER],
'Please select your package manager.',
);
} else {

packageManagerPrompted = await wizardInstance.waitForOutput(
'Please select your package manager.',
);
Expand Down Expand Up @@ -119,12 +122,16 @@ async function runWizardOnRemixProject(projectDir: string, integration: Integrat
);

wizardInstance.kill();
};
}

function checkRemixProject(projectDir: string, integration: Integration, options?: {
devModeExpectedOutput?: string;
prodModeExpectedOutput?: string;
}) {
function checkRemixProject(
projectDir: string,
integration: Integration,
options?: {
devModeExpectedOutput?: string;
prodModeExpectedOutput?: string;
},
) {
test('package.json is updated correctly', () => {
checkPackageJson(projectDir, integration);
});
Expand Down Expand Up @@ -195,15 +202,21 @@ function checkRemixProject(projectDir: string, integration: Integration, options
});

test('builds successfully', async () => {
await checkIfBuilds(projectDir, 'built');
await checkIfBuilds(projectDir);
});

test('runs on dev mode correctly', async () => {
await checkIfRunsOnDevMode(projectDir, options?.devModeExpectedOutput || 'to expose');
await checkIfRunsOnDevMode(
projectDir,
options?.devModeExpectedOutput || 'to expose',
);
});

test('runs on prod mode correctly', async () => {
await checkIfRunsOnProdMode(projectDir, options?.prodModeExpectedOutput || '[remix-serve]');
await checkIfRunsOnProdMode(
projectDir,
options?.prodModeExpectedOutput || '[remix-serve]',
);
});
}

Expand Down Expand Up @@ -236,13 +249,11 @@ describe('Remix', () => {

beforeAll(async () => {
await runWizardOnRemixProject(projectDir, integration, (projectDir) => {
createFile(
`${projectDir}/server.mjs`,
SERVER_TEMPLATE,
);
createFile(`${projectDir}/server.mjs`, SERVER_TEMPLATE);

modifyFile(`${projectDir}/package.json`, {
'"start": "remix-serve ./build/server/index.js"': '"start": "node ./server.mjs"',
'"start": "remix-serve ./build/server/index.js"':
'"start": "node ./server.mjs"',
'"dev": "remix vite:dev"': '"dev": "node ./server.mjs"',
});
});
Expand Down
129 changes: 79 additions & 50 deletions e2e-tests/tests/sveltekit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,30 @@ export async function handleError({ error, event }) {
}
`;

async function runWizardOnSvelteKitProject(projectDir: string, integration: Integration, fileModificationFn?: (projectDir: string, integration: Integration) => unknown) {
async function runWizardOnSvelteKitProject(
projectDir: string,
integration: Integration,
fileModificationFn?: (
projectDir: string,
integration: Integration,
) => unknown,
) {
const wizardInstance = startWizardInstance(integration, projectDir);
let packageManagerPrompted = false;

if (fileModificationFn) {
fileModificationFn(projectDir, integration);

// As we modified project, we have a warning prompt before we get the package manager prompt
await wizardInstance.waitForOutput(
'Do you want to continue anyway?',
);
await wizardInstance.waitForOutput('Do you want to continue anyway?');

packageManagerPrompted = await wizardInstance.sendStdinAndWaitForOutput(
[KEYS.ENTER],
'Please select your package manager.',
);
} else {
packageManagerPrompted = await wizardInstance.waitForOutput(
'Please select your package manager'
'Please select your package manager',
);
}

Expand All @@ -72,7 +77,7 @@ async function runWizardOnSvelteKitProject(projectDir: string, integration: Inte
'to track the performance of your application?',
{
timeout: 240_000,
}
},
));

const replayOptionPrompted =
Expand Down Expand Up @@ -100,10 +105,14 @@ async function runWizardOnSvelteKitProject(projectDir: string, integration: Inte
wizardInstance.kill();
}

function checkSvelteKitProject(projectDir: string, integration: Integration, options?: {
devModeExpectedOutput: string;
prodModeExpectedOutput: string;
}) {
function checkSvelteKitProject(
projectDir: string,
integration: Integration,
options?: {
devModeExpectedOutput: string;
prodModeExpectedOutput: string;
},
) {
test('should have the correct package.json', () => {
checkPackageJson(projectDir, integration);
});
Expand All @@ -113,14 +122,21 @@ function checkSvelteKitProject(projectDir: string, integration: Integration, opt
});

test('example page exists', () => {
checkFileExists(path.resolve(projectDir, 'src/routes/sentry-example/+page.svelte'));
checkFileExists(path.resolve(projectDir, 'src/routes/sentry-example/+server.js'));
checkFileExists(
path.resolve(projectDir, 'src/routes/sentry-example/+page.svelte'),
);
checkFileExists(
path.resolve(projectDir, 'src/routes/sentry-example/+server.js'),
);
});

test('vite.config contains sentry plugin', () => {
checkFileContents(path.resolve(projectDir, 'vite.config.ts'), `plugins: [sentrySvelteKit({
checkFileContents(
path.resolve(projectDir, 'vite.config.ts'),
`plugins: [sentrySvelteKit({
sourceMapsUploadOptions: {
`);
`,
);
});

test('hook files created', () => {
Expand All @@ -129,15 +145,22 @@ function checkSvelteKitProject(projectDir: string, integration: Integration, opt
});

test('builds successfully', async () => {
await checkIfBuilds(projectDir, 'Successfully uploaded source maps to Sentry');
await checkIfBuilds(projectDir);
});

test('runs on dev mode correctly', async () => {
await checkIfRunsOnDevMode(projectDir, options?.devModeExpectedOutput || 'ready in');
await checkIfRunsOnDevMode(
projectDir,
options?.devModeExpectedOutput || 'ready in',
);
});

test('runs on prod mode correctly', async () => {
await checkIfRunsOnProdMode(projectDir, options?.prodModeExpectedOutput || 'to expose', 'preview');
await checkIfRunsOnProdMode(
projectDir,
options?.prodModeExpectedOutput || 'to expose',
'preview',
);
});
}

Expand All @@ -161,10 +184,9 @@ describe('Sveltekit', () => {
checkSvelteKitProject(projectDir, integration);

test('hooks.client.ts contains sentry', () => {
checkFileContents(
path.resolve(projectDir, 'src/hooks.client.ts'),
[`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
checkFileContents(path.resolve(projectDir, 'src/hooks.client.ts'), [
`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
dsn: '${TEST_ARGS.PROJECT_DSN}',
tracesSampleRate: 1.0,
Expand All @@ -179,22 +201,24 @@ describe('Sveltekit', () => {
// If you don't want to use Session Replay, just remove the line below:
integrations: [replayIntegration()],
});`, 'export const handleError = handleErrorWithSentry(']);
});`,
'export const handleError = handleErrorWithSentry(',
]);
});

test('hooks.server.ts contains sentry', () => {
checkFileContents(
path.resolve(projectDir, 'src/hooks.server.ts'),
[
`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
checkFileContents(path.resolve(projectDir, 'src/hooks.server.ts'), [
`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
dsn: '${TEST_ARGS.PROJECT_DSN}',
tracesSampleRate: 1.0,
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: import.meta.env.DEV,
});`, 'export const handleError = handleErrorWithSentry();']);
});`,
'export const handleError = handleErrorWithSentry();',
]);
});
});

Expand All @@ -206,17 +230,21 @@ describe('Sveltekit', () => {
);

beforeAll(async () => {
await runWizardOnSvelteKitProject(projectDir, integration, (projectDir) => {
createFile(
path.resolve(projectDir, 'src/hooks.server.ts'),
SERVER_HOOK_TEMPLATE,
)

createFile(
path.resolve(projectDir, 'src/hooks.client.ts'),
CLIENT_HOOK_TEMPLATE,
)
});
await runWizardOnSvelteKitProject(
projectDir,
integration,
(projectDir) => {
createFile(
path.resolve(projectDir, 'src/hooks.server.ts'),
SERVER_HOOK_TEMPLATE,
);

createFile(
path.resolve(projectDir, 'src/hooks.client.ts'),
CLIENT_HOOK_TEMPLATE,
);
},
);
});

afterAll(() => {
Expand All @@ -229,27 +257,28 @@ describe('Sveltekit', () => {
// These are removed from the common tests as the content is different
// when the hooks are merged instead of created from the template
test('hooks.client.ts contains sentry instrumentation', () => {
checkFileContents(
path.resolve(projectDir, 'src/hooks.client.ts'),
[`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
checkFileContents(path.resolve(projectDir, 'src/hooks.client.ts'), [
`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
dsn: "${TEST_ARGS.PROJECT_DSN}",
tracesSampleRate: 1,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1,
integrations: [Sentry.replayIntegration()]
})`, 'export const handleError = Sentry.handleErrorWithSentry(']);
})`,
'export const handleError = Sentry.handleErrorWithSentry(',
]);
});

test('hooks.server.ts contains sentry init', () => {
checkFileContents(
path.resolve(projectDir, 'src/hooks.server.ts'),
[`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
checkFileContents(path.resolve(projectDir, 'src/hooks.server.ts'), [
`import * as Sentry from '@sentry/sveltekit';`,
`Sentry.init({
dsn: "${TEST_ARGS.PROJECT_DSN}",
tracesSampleRate: 1
})`, 'export const handleError = Sentry.handleErrorWithSentry();']);
})`,
'export const handleError = Sentry.handleErrorWithSentry();',
]);
});
});
});

Loading

0 comments on commit 8181920

Please sign in to comment.