Skip to content

Commit 6c28d4b

Browse files
authored
feat(angular): Add Support for Angular 18 (#12183)
Add support for Angular 18 in our Angular SDK - bumped peer dependency version range - added e2e test for Angular 18
1 parent a45bdd1 commit 6c28d4b

27 files changed

+923
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ jobs:
994994
test-application:
995995
[
996996
'angular-17',
997+
'angular-18',
997998
'cloudflare-astro',
998999
'node-express',
9991000
'create-react-app',
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.ts]
12+
quote_type = single
13+
14+
[*.md]
15+
max_line_length = off
16+
trim_trailing_whitespace = false
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
9+
# Node
10+
/node_modules
11+
npm-debug.log
12+
yarn-error.log
13+
14+
# IDEs and editors
15+
.idea/
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
*.sublime-workspace
22+
23+
# Visual Studio Code
24+
.vscode/*
25+
!.vscode/settings.json
26+
!.vscode/tasks.json
27+
!.vscode/launch.json
28+
!.vscode/extensions.json
29+
.history/*
30+
31+
# Miscellaneous
32+
/.angular/cache
33+
.sass-cache/
34+
/connect.lock
35+
/coverage
36+
/libpeerconnection.log
37+
testem.log
38+
/typings
39+
40+
# System files
41+
.DS_Store
42+
Thumbs.db
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Angular 18
2+
3+
E2E test app for Angular 18 and `@sentry/angular`.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"angular-18": {
7+
"projectType": "application",
8+
"schematics": {},
9+
"root": "",
10+
"sourceRoot": "src",
11+
"prefix": "app",
12+
"architect": {
13+
"build": {
14+
"builder": "@angular-devkit/build-angular:application",
15+
"options": {
16+
"outputPath": "dist/angular-18",
17+
"index": "src/index.html",
18+
"browser": "src/main.ts",
19+
"polyfills": [
20+
"zone.js"
21+
],
22+
"tsConfig": "tsconfig.app.json",
23+
"assets": [
24+
"src/favicon.ico",
25+
"src/assets"
26+
],
27+
"styles": [
28+
"src/styles.css"
29+
],
30+
"scripts": []
31+
},
32+
"configurations": {
33+
"production": {
34+
"budgets": [
35+
{
36+
"type": "initial",
37+
"maximumWarning": "500kb",
38+
"maximumError": "1mb"
39+
},
40+
{
41+
"type": "anyComponentStyle",
42+
"maximumWarning": "2kb",
43+
"maximumError": "4kb"
44+
}
45+
],
46+
"outputHashing": "all"
47+
},
48+
"development": {
49+
"optimization": false,
50+
"extractLicenses": false,
51+
"sourceMap": true
52+
}
53+
},
54+
"defaultConfiguration": "production"
55+
},
56+
"serve": {
57+
"builder": "@angular-devkit/build-angular:dev-server",
58+
"configurations": {
59+
"production": {
60+
"buildTarget": "angular-18:build:production"
61+
},
62+
"development": {
63+
"buildTarget": "angular-18:build:development"
64+
}
65+
},
66+
"defaultConfiguration": "development"
67+
},
68+
"extract-i18n": {
69+
"builder": "@angular-devkit/build-angular:extract-i18n",
70+
"options": {
71+
"buildTarget": "angular-18:build"
72+
}
73+
},
74+
"test": {
75+
"builder": "@angular-devkit/build-angular:karma",
76+
"options": {
77+
"polyfills": [
78+
"zone.js",
79+
"zone.js/testing"
80+
],
81+
"tsConfig": "tsconfig.spec.json",
82+
"assets": [
83+
"src/favicon.ico",
84+
"src/assets"
85+
],
86+
"styles": [
87+
"src/styles.css"
88+
],
89+
"scripts": []
90+
}
91+
}
92+
}
93+
}
94+
}
95+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "angular-18",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"ng": "ng",
6+
"dev": "ng serve",
7+
"proxy": "node start-event-proxy.mjs",
8+
"preview": "http-server dist/angular-18/browser --port 8080",
9+
"build": "ng build",
10+
"watch": "ng build --watch --configuration development",
11+
"test": "playwright test",
12+
"test:build": "pnpm install && npx playwright install && pnpm build",
13+
"test:assert": "playwright test",
14+
"clean": "npx rimraf .angular node_modules pnpm-lock.yaml dist"
15+
},
16+
"private": true,
17+
"dependencies": {
18+
"@angular/animations": "^18.0.0",
19+
"@angular/common": "^18.0.0",
20+
"@angular/compiler": "^18.0.0",
21+
"@angular/core": "^18.0.0",
22+
"@angular/forms": "^18.0.0",
23+
"@angular/platform-browser": "^18.0.0",
24+
"@angular/platform-browser-dynamic": "^18.0.0",
25+
"@angular/router": "^18.0.0",
26+
"@sentry/angular": "* || latest",
27+
"rxjs": "~7.8.0",
28+
"tslib": "^2.3.0",
29+
"zone.js": "~0.14.3"
30+
},
31+
"devDependencies": {
32+
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server",
33+
"@angular-devkit/build-angular": "^18.0.0",
34+
"@angular/cli": "^18.0.0",
35+
"@angular/compiler-cli": "^18.0.0",
36+
"@playwright/test": "^1.41.1",
37+
"@types/jasmine": "~5.1.0",
38+
"http-server": "^14.1.1",
39+
"jasmine-core": "~5.1.0",
40+
"karma": "~6.4.0",
41+
"karma-chrome-launcher": "~3.2.0",
42+
"karma-coverage": "~2.2.0",
43+
"karma-jasmine": "~5.1.0",
44+
"karma-jasmine-html-reporter": "~2.1.0",
45+
"typescript": "~5.4.5",
46+
"wait-port": "1.0.4"
47+
},
48+
"volta": {
49+
"extends": "../../package.json"
50+
}
51+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { devices } from '@playwright/test';
3+
4+
// Fix urls not resolving to localhost on Node v17+
5+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6+
import { setDefaultResultOrder } from 'dns';
7+
setDefaultResultOrder('ipv4first');
8+
9+
const testEnv = process.env['TEST_ENV'] || 'production';
10+
11+
if (!testEnv) {
12+
throw new Error('No test env defined');
13+
}
14+
15+
const angularPort = 8080;
16+
const eventProxyPort = 3031;
17+
18+
/**
19+
* See https://playwright.dev/docs/test-configuration.
20+
*/
21+
const config: PlaywrightTestConfig = {
22+
testDir: './tests',
23+
/* Maximum time one test can run for. */
24+
timeout: 150_000,
25+
expect: {
26+
/**
27+
* Maximum time expect() should wait for the condition to be met.
28+
* For example in `await expect(locator).toHaveText();`
29+
*/
30+
timeout: 10000,
31+
},
32+
fullyParallel: false,
33+
workers: 1,
34+
/* Fail the build on CI if you accidentally left test.only in the source code. */
35+
forbidOnly: !!process.env.CI,
36+
/* `next dev` is incredibly buggy with the app dir */
37+
retries: testEnv === 'development' ? 3 : 0,
38+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
39+
reporter: 'list',
40+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
41+
use: {
42+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
43+
actionTimeout: 0,
44+
/* Base URL to use in actions like `await page.goto('/')`. */
45+
baseURL: `http://localhost:${angularPort}`,
46+
47+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
48+
trace: 'on-first-retry',
49+
},
50+
51+
/* Configure projects for major browsers */
52+
projects: [
53+
{
54+
name: 'chromium',
55+
use: {
56+
...devices['Desktop Chrome'],
57+
},
58+
},
59+
],
60+
61+
/* Run your local dev server before starting the tests */
62+
webServer: [
63+
{
64+
command: 'node start-event-proxy.mjs',
65+
port: eventProxyPort,
66+
},
67+
{
68+
command:
69+
testEnv === 'development'
70+
? `pnpm wait-port ${eventProxyPort} && pnpm preview -p ${angularPort}`
71+
: `pnpm wait-port ${eventProxyPort} && pnpm preview -p ${angularPort}`,
72+
port: angularPort,
73+
},
74+
],
75+
};
76+
77+
export default config;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component } from '@angular/core';
2+
import { RouterOutlet } from '@angular/router';
3+
4+
@Component({
5+
selector: 'app-root',
6+
standalone: true,
7+
imports: [RouterOutlet],
8+
template: `<router-outlet></router-outlet>`,
9+
})
10+
export class AppComponent {
11+
title = 'angular-18';
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { APP_INITIALIZER, ApplicationConfig, ErrorHandler } from '@angular/core';
2+
import { Router, provideRouter } from '@angular/router';
3+
4+
import { TraceService, createErrorHandler } from '@sentry/angular';
5+
import { routes } from './app.routes';
6+
7+
export const appConfig: ApplicationConfig = {
8+
providers: [
9+
provideRouter(routes),
10+
{
11+
provide: ErrorHandler,
12+
useValue: createErrorHandler(),
13+
},
14+
{
15+
provide: TraceService,
16+
deps: [Router],
17+
},
18+
{
19+
provide: APP_INITIALIZER,
20+
useFactory: () => () => {},
21+
deps: [TraceService],
22+
multi: true,
23+
},
24+
],
25+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Routes } from '@angular/router';
2+
import { cancelGuard } from './cancel-guard.guard';
3+
import { CancelComponent } from './cancel/cancel.components';
4+
import { ComponentTrackingComponent } from './component-tracking/component-tracking.components';
5+
import { HomeComponent } from './home/home.component';
6+
import { UserComponent } from './user/user.component';
7+
8+
export const routes: Routes = [
9+
{
10+
path: 'users/:id',
11+
component: UserComponent,
12+
},
13+
{
14+
path: 'home',
15+
component: HomeComponent,
16+
},
17+
{
18+
path: 'cancel',
19+
component: CancelComponent,
20+
canActivate: [cancelGuard],
21+
},
22+
{
23+
path: 'component-tracking',
24+
component: ComponentTrackingComponent,
25+
},
26+
{
27+
path: 'redirect1',
28+
redirectTo: '/redirect2',
29+
},
30+
{
31+
path: 'redirect2',
32+
redirectTo: '/redirect3',
33+
},
34+
{
35+
path: 'redirect3',
36+
redirectTo: '/users/456',
37+
},
38+
{
39+
path: '**',
40+
redirectTo: 'home',
41+
},
42+
];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ActivatedRouteSnapshot, CanActivateFn, RouterStateSnapshot } from '@angular/router';
2+
3+
export const cancelGuard: CanActivateFn = (_next: ActivatedRouteSnapshot, _state: RouterStateSnapshot) => {
4+
return false;
5+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-cancel',
5+
standalone: true,
6+
template: `<div></div>`,
7+
})
8+
export class CancelComponent {}

0 commit comments

Comments
 (0)