Skip to content

Commit

Permalink
feat(angular): Add Support for Angular 18 (#12183)
Browse files Browse the repository at this point in the history
Add support for Angular 18 in our Angular SDK

- bumped peer dependency version range
- added e2e test for Angular 18
  • Loading branch information
Lms24 committed May 23, 2024
1 parent a45bdd1 commit 6c28d4b
Show file tree
Hide file tree
Showing 27 changed files with 923 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ jobs:
test-application:
[
'angular-17',
'angular-18',
'cloudflare-astro',
'node-express',
'create-react-app',
Expand Down
16 changes: 16 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-18/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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

[*.md]
max_line_length = off
trim_trailing_whitespace = false
42 changes: 42 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-18/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See http://help.github.com/ignore-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
2 changes: 2 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-18/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
3 changes: 3 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-18/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Angular 18

E2E test app for Angular 18 and `@sentry/angular`.
95 changes: 95 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-18/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-18": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/angular-18",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "angular-18:build:production"
},
"development": {
"buildTarget": "angular-18:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "angular-18:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
}
}
}
51 changes: 51 additions & 0 deletions dev-packages/e2e-tests/test-applications/angular-18/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "angular-18",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"dev": "ng serve",
"proxy": "node start-event-proxy.mjs",
"preview": "http-server dist/angular-18/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": "^18.0.0",
"@angular/common": "^18.0.0",
"@angular/compiler": "^18.0.0",
"@angular/core": "^18.0.0",
"@angular/forms": "^18.0.0",
"@angular/platform-browser": "^18.0.0",
"@angular/platform-browser-dynamic": "^18.0.0",
"@angular/router": "^18.0.0",
"@sentry/angular": "* || latest",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
},
"devDependencies": {
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server",
"@angular-devkit/build-angular": "^18.0.0",
"@angular/cli": "^18.0.0",
"@angular/compiler-cli": "^18.0.0",
"@playwright/test": "^1.41.1",
"@types/jasmine": "~5.1.0",
"http-server": "^14.1.1",
"jasmine-core": "~5.1.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.4.5",
"wait-port": "1.0.4"
},
"volta": {
"extends": "../../package.json"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

// Fix urls not resolving to localhost on Node v17+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
import { setDefaultResultOrder } from 'dns';
setDefaultResultOrder('ipv4first');

const testEnv = process.env['TEST_ENV'] || 'production';

if (!testEnv) {
throw new Error('No test env defined');
}

const angularPort = 8080;
const eventProxyPort = 3031;

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './tests',
/* Maximum time one test can run for. */
timeout: 150_000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 10000,
},
fullyParallel: false,
workers: 1,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* `next dev` is incredibly buggy with the app dir */
retries: testEnv === 'development' ? 3 : 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: `http://localhost:${angularPort}`,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},
],

/* Run your local dev server before starting the tests */
webServer: [
{
command: 'node start-event-proxy.mjs',
port: eventProxyPort,
},
{
command:
testEnv === 'development'
? `pnpm wait-port ${eventProxyPort} && pnpm preview -p ${angularPort}`
: `pnpm wait-port ${eventProxyPort} && pnpm preview -p ${angularPort}`,
port: angularPort,
},
],
};

export default config;
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-18';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { APP_INITIALIZER, ApplicationConfig, ErrorHandler } 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: [
provideRouter(routes),
{
provide: ErrorHandler,
useValue: createErrorHandler(),
},
{
provide: TraceService,
deps: [Router],
},
{
provide: APP_INITIALIZER,
useFactory: () => () => {},
deps: [TraceService],
multi: true,
},
],
};
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 {}
Loading

0 comments on commit 6c28d4b

Please sign in to comment.