Skip to content

Commit

Permalink
feat(angular): Support Angular 19 (#14398)
Browse files Browse the repository at this point in the history
Add support for the new major version by bumping peer dependencies
and adding an Angular 19 e2e test app.
  • Loading branch information
Lms24 authored Nov 21, 2024
1 parent 2435b87 commit b3dad24
Show file tree
Hide file tree
Showing 26 changed files with 866 additions and 7 deletions.
17 changes: 17 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-19/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single
ij_typescript_use_double_quotes = false

[*.md]
max_line_length = off
trim_trailing_whitespace = false
44 changes: 44 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-19/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db

test-results
3 changes: 3 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-19/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Angular 19

E2E test app for Angular 19 and `@sentry/angular`.
96 changes: 96 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-19/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-19": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/angular-19",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kB",
"maximumError": "1MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kB",
"maximumError": "8kB"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "angular-19:build:production"
},
"development": {
"buildTarget": "angular-19:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
}
}
}
47 changes: 47 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-19/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "angular-19",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"dev": "ng serve",
"proxy": "node start-event-proxy.mjs",
"preview": "http-server dist/angular-19/browser --port 8080",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "playwright test",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "playwright test",
"clean": "npx rimraf .angular node_modules pnpm-lock.yaml dist"
},
"private": true,
"dependencies": {
"@angular/animations": "^19.0.0",
"@angular/common": "^19.0.0",
"@angular/compiler": "^19.0.0",
"@angular/core": "^19.0.0",
"@angular/forms": "^19.0.0",
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.0",
"@angular/router": "^19.0.0",
"@sentry/angular": "* || latest",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^19.0.0",
"@angular/cli": "^19.0.0",
"@angular/compiler-cli": "^19.0.0",
"@playwright/test": "^1.44.1",
"@sentry-internal/test-utils": "link:../../../test-utils",
"@types/jasmine": "~5.1.0",
"http-server": "^14.1.1",
"jasmine-core": "~5.4.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.6.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getPlaywrightConfig } from '@sentry-internal/test-utils';

const config = getPlaywrightConfig({
startCommand: `pnpm preview`,
port: 8080,
});

export default config;
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';

@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet],
template: `<router-outlet></router-outlet>`,
})
export class AppComponent {
title = 'angular-19';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
ApplicationConfig,
ErrorHandler,
inject,
provideAppInitializer,
provideZoneChangeDetection,
} from '@angular/core';
import { Router, provideRouter } from '@angular/router';

import { TraceService, createErrorHandler } from '@sentry/angular';
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
{
provide: ErrorHandler,
useValue: createErrorHandler(),
},
{
provide: TraceService,
deps: [Router],
},
provideAppInitializer(() => {
inject(TraceService);
}),
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Routes } from '@angular/router';
import { cancelGuard } from './cancel-guard.guard';
import { CancelComponent } from './cancel/cancel.components';
import { ComponentTrackingComponent } from './component-tracking/component-tracking.components';
import { HomeComponent } from './home/home.component';
import { UserComponent } from './user/user.component';

export const routes: Routes = [
{
path: 'users/:id',
component: UserComponent,
},
{
path: 'home',
component: HomeComponent,
},
{
path: 'cancel',
component: CancelComponent,
canActivate: [cancelGuard],
},
{
path: 'component-tracking',
component: ComponentTrackingComponent,
},
{
path: 'redirect1',
redirectTo: '/redirect2',
},
{
path: 'redirect2',
redirectTo: '/redirect3',
},
{
path: 'redirect3',
redirectTo: '/users/456',
},
{
path: '**',
redirectTo: 'home',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ActivatedRouteSnapshot, CanActivateFn, RouterStateSnapshot } from '@angular/router';

export const cancelGuard: CanActivateFn = (_next: ActivatedRouteSnapshot, _state: RouterStateSnapshot) => {
return false;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-cancel',
standalone: true,
template: `<div></div>`,
})
export class CancelComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AfterViewInit, Component, OnInit } from '@angular/core';
import { TraceClass, TraceMethod, TraceModule } from '@sentry/angular';
import { SampleComponent } from '../sample-component/sample-component.components';

@Component({
selector: 'app-cancel',
standalone: true,
imports: [TraceModule, SampleComponent],
template: `<app-sample-component [trace]="'sample-component'"></app-sample-component>`,
})
@TraceClass({ name: 'ComponentTrackingComponent' })
export class ComponentTrackingComponent implements OnInit, AfterViewInit {
@TraceMethod({ name: 'ngOnInit' })
ngOnInit() {}

@TraceMethod()
ngAfterViewInit() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'app-home',
standalone: true,
imports: [RouterLink],
template: `
<main>
<h1>Welcome to Sentry's Angular 19 E2E test app</h1>
<ul>
<li> <a id="navLink" [routerLink]="['/users', '123']">Visit User 123</a> </li>
<li> <a id="redirectLink" [routerLink]="['/redirect1']">Redirect</a> </li>
<li> <a id="cancelLink" [routerLink]="['/cancel']">Cancel</a> </li>
<li> <a id="nonExistentLink" [routerLink]="['/non-existent']">Error</a> </li>
<li> <a id="componentTracking" [routerLink]="['/component-tracking']">Component Tracking</a> </li>
</ul>
<button id="errorBtn" (click)="throwError()">Throw error</button>
</main>
`,
})
export class HomeComponent {
throwError() {
throw new Error('Error thrown from Angular 18 E2E test app');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-sample-component',
standalone: true,
template: `<div>Component</div>`,
})
export class SampleComponent implements OnInit {
ngOnInit() {
console.log('SampleComponent');
}
}
Loading

0 comments on commit b3dad24

Please sign in to comment.