From 46d5670688e76f76510f3e3fd5388af6449fc0cb Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Tue, 28 Oct 2025 12:02:56 +0000 Subject: [PATCH] refactor(docs-infra): switch to use unit-test builder - Deletes the old Karma configuration and test entry point. - Updates `angular.json` to use the `@angular/build` builders. - Adjusts test files to align with the new setup. --- MODULE.bazel | 2 +- adev/BUILD.bazel | 9 +- adev/angular.json | 26 ++--- adev/karma.conf.js | 85 --------------- adev/package.json | 32 +++--- adev/src/app/app.component.spec.ts | 8 +- .../services/a-dev-title-strategy.spec.ts | 2 +- adev/test-main.ts | 18 ---- adev/tools/BUILD.bazel | 12 --- adev/tools/windows-chromium-path.js | 49 --------- pnpm-lock.yaml | 102 +----------------- 11 files changed, 35 insertions(+), 310 deletions(-) delete mode 100644 adev/karma.conf.js delete mode 100644 adev/test-main.ts delete mode 100644 adev/tools/BUILD.bazel delete mode 100644 adev/tools/windows-chromium-path.js diff --git a/MODULE.bazel b/MODULE.bazel index 47185d47f7c..57300212e57 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -18,7 +18,7 @@ bazel_dep(name = "yq.bzl", version = "0.3.1") bazel_dep(name = "rules_angular") git_override( module_name = "rules_angular", - commit = "1f1aa3edb32f5e9135088548a419874a094eb687", + commit = "b97a21c7cead2a07ea1bffa68eaae7f7e08dfc5f", remote = "https://github.com/devversion/rules_angular.git", ) diff --git a/adev/BUILD.bazel b/adev/BUILD.bazel index b6fdf6222d6..3ddd57cb686 100644 --- a/adev/BUILD.bazel +++ b/adev/BUILD.bazel @@ -30,7 +30,6 @@ APPLICATION_FILES = [ ) APPLICATION_DEPS = [ - ":node_modules/@angular-devkit/build-angular", ":node_modules/@codemirror/autocomplete", ":node_modules/@codemirror/commands", ":node_modules/@codemirror/lang-angular", @@ -82,10 +81,7 @@ APPLICATION_DEPS = [ ":node_modules/w3c-keyname", ] -TEST_FILES = APPLICATION_FILES + [ - "karma.conf.js", - "test-main.ts", -] + glob(["src/**/*.spec.ts"]) +TEST_FILES = APPLICATION_FILES + glob(["src/app/**/*.spec.ts"]) TEST_DEPS = [ dep @@ -93,8 +89,6 @@ TEST_DEPS = [ if dep != ":node_modules/@types/node" ] + [ "@rules_browsers//browsers/chromium", - "@rules_browsers//browsers/firefox", - "//adev/tools:windows-chromium-path", ] ng_config(name = "ng_config") @@ -164,6 +158,5 @@ ng_test( project_name = "angular-dev", toolchains = [ "@rules_browsers//browsers/chromium:toolchain_alias", - "@rules_browsers//browsers/firefox:toolchain_alias", ], ) diff --git a/adev/angular.json b/adev/angular.json index eeb7555e3da..621683d1671 100644 --- a/adev/angular.json +++ b/adev/angular.json @@ -56,7 +56,7 @@ "defaultConfiguration": "production" }, "serve": { - "builder": "@angular-devkit/build-angular:dev-server", + "builder": "@angular/build:dev-server", "configurations": { "production": { "buildTarget": "angular-dev:build:production" @@ -74,24 +74,14 @@ } } }, - "extract-i18n": { - "builder": "@angular-devkit/build-angular:extract-i18n", - "options": { - "buildTarget": "angular-dev:build" - } - }, "test": { - "builder": "@angular/build:karma", - "options": { - "tsConfig": "tsconfig.spec.json", - "include": ["src/app"], - "karmaConfig": "karma.conf.js", - "main": "test-main.ts", - "inlineStyleLanguage": "scss", - "assets": ["src/favicon.ico", "src/assets"], - "styles": ["@angular/docs/styles/global-styles.scss"], - "scripts": [], - "webWorkerTsConfig": "tsconfig.worker.json" + "builder": "@angular/build:unit-test", + "options": { + "runner": "karma", + "browsers": ["ChromeHeadlessNoSandbox"], + "include": [ + "src/app/**/*.spec.ts" + ] } } } diff --git a/adev/karma.conf.js b/adev/karma.conf.js deleted file mode 100644 index 4ede0475551..00000000000 --- a/adev/karma.conf.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -const {getAdjustedChromeBinPathForWindows} = require('./tools/windows-chromium-path'); - -process.env.CHROME_BIN = getAdjustedChromeBinPathForWindows(); - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - {'reporter:jasmine-seed': ['type', JasmineSeedReporter]}, - ], - proxies: { - '/dummy/image': 'src/assets/images/logos/angular/angular.png', - }, - client: { - clearContext: false, // leave Jasmine Spec Runner output visible in browser - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - random: true, - seed: '', - }, - }, - jasmineHtmlReporter: { - suppressAll: true, // removes the duplicated traces - }, - coverageReporter: { - dir: require('path').join(__dirname, './coverage/site'), - subdir: '.', - reporters: [{type: 'html'}, {type: 'text-summary'}], - }, - reporters: ['progress', 'kjhtml', 'jasmine-seed'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: 'ChromeHeadless', - // See /integration/README.md#browser-tests for more info on these args - flags: [ - '--no-sandbox', - '--headless', - '--disable-gpu', - '--disable-dev-shm-usage', - '--hide-scrollbars', - '--mute-audio', - ], - }, - }, - browsers: ['ChromeHeadlessNoSandbox'], - browserNoActivityTimeout: 60000, - singleRun: false, - restartOnFileChange: true, - }); -}; - -// Helpers -function JasmineSeedReporter(baseReporterDecorator) { - baseReporterDecorator(this); - - this.onBrowserComplete = (browser, result) => { - const seed = result.order && result.order.random && result.order.seed; - if (seed) this.write(`${browser}: Randomized with seed ${seed}.\n`); - }; - - this.onRunComplete = () => undefined; -} diff --git a/adev/package.json b/adev/package.json index cf67ae5085f..bd93c339b8a 100644 --- a/adev/package.json +++ b/adev/package.json @@ -1,14 +1,16 @@ { "dependencies": { + "@algolia/client-common": "5.41.0", "@algolia/client-search": "5.41.0", - "@angular-devkit/build-angular": "21.0.0-next.9", + "@algolia/requester-browser-xhr": "5.41.0", + "@algolia/requester-node-http": "5.41.0", "@angular/animations": "workspace:*", "@angular/build": "21.0.0-next.9", "@angular/cdk": "21.0.0-next.10", "@angular/cli": "21.0.0-next.9", "@angular/common": "workspace:*", - "@angular/compiler-cli": "workspace:*", "@angular/compiler": "workspace:*", + "@angular/compiler-cli": "workspace:*", "@angular/core": "workspace:*", "@angular/docs": "workspace:*", "@angular/forms": "workspace:*", @@ -30,8 +32,13 @@ "@codemirror/state": "6.5.2", "@codemirror/view": "6.38.6", "@lezer/common": "1.3.0", + "@lezer/css": "1.3.0", "@lezer/highlight": "1.2.2", + "@lezer/html": "1.3.12", "@lezer/javascript": "1.5.4", + "@lezer/lr": "1.4.2", + "@lezer/sass": "1.1.0", + "@marijn/find-cluster-break": "1.0.2", "@stackblitz/sdk": "1.11.0", "@types/dom-navigation": "1.0.6", "@types/jasmine": "5.1.12", @@ -43,6 +50,7 @@ "@xterm/xterm": "5.5.0", "algoliasearch": "5.41.0", "angular-split": "20.0.0", + "crelt": "1.0.6", "diff": "8.0.2", "emoji-regex": "10.6.0", "fflate": "0.8.2", @@ -50,37 +58,29 @@ "jsdom": "27.0.1", "karma-chrome-launcher": "3.2.0", "karma-coverage": "2.2.1", - "karma-jasmine-html-reporter": "2.1.0", "karma-jasmine": "5.1.0", + "karma-jasmine-html-reporter": "2.1.0", "marked": "16.4.1", "mermaid": "11.12.0", "ngx-progressbar": "14.0.0", "open-in-idx": "0.1.1", "playwright-core": "1.56.1", - "preact-render-to-string": "6.6.3", "preact": "10.27.2", + "preact-render-to-string": "6.6.3", "prettier": "3.6.2", "rxjs": "7.8.2", "shiki": "3.14.0", + "style-mod": "4.1.3", "tinyglobby": "0.2.15", "tslib": "2.8.1", "typescript": "5.9.3", + "w3c-keyname": "2.2.8", "xhr2": "0.2.1", - "zone.js": "0.15.1", - "@algolia/client-common": "5.41.0", - "@algolia/requester-browser-xhr": "5.41.0", - "@algolia/requester-node-http": "5.41.0", - "@lezer/css": "1.3.0", - "@lezer/html": "1.3.12", - "@lezer/lr": "1.4.2", - "@lezer/sass": "1.1.0", - "@marijn/find-cluster-break": "1.0.2", - "crelt": "1.0.6", - "style-mod": "4.1.3", - "w3c-keyname": "2.2.8" + "zone.js": "0.15.1" }, "devDependencies": { "autoprefixer": "10.4.21", + "karma": "~6.4.4", "postcss": "8.5.6", "tailwindcss": "3.4.18" } diff --git a/adev/src/app/app.component.spec.ts b/adev/src/app/app.component.spec.ts index a77f9c5cf68..1b536096633 100644 --- a/adev/src/app/app.component.spec.ts +++ b/adev/src/app/app.component.spec.ts @@ -18,8 +18,9 @@ describe('AppComponent', () => { const fakeSearch = {}; const fakeWindow = {location: {hostname: 'angular.dev'}}; - it('should create the app', () => { - TestBed.configureTestingModule({ + it('should create the app', async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent], providers: [ provideHttpClient(), provideHttpClientTesting(), @@ -33,7 +34,8 @@ describe('AppComponent', () => { useValue: fakeSearch, }, ], - }); + }).compileComponents(); + const fixture = TestBed.createComponent(AppComponent); const app = fixture.componentInstance; expect(app).toBeTruthy(); diff --git a/adev/src/app/core/services/a-dev-title-strategy.spec.ts b/adev/src/app/core/services/a-dev-title-strategy.spec.ts index 82a7d3082e3..808716a7a61 100644 --- a/adev/src/app/core/services/a-dev-title-strategy.spec.ts +++ b/adev/src/app/core/services/a-dev-title-strategy.spec.ts @@ -13,7 +13,7 @@ import {Router, provideRouter} from '@angular/router'; import {Title} from '@angular/platform-browser'; import {Component} from '@angular/core'; -@Component({}) +@Component({template: ''}) class FakeComponent {} describe('ADevTitleStrategy', () => { diff --git a/adev/test-main.ts b/adev/test-main.ts deleted file mode 100644 index 1c4ba42ec15..00000000000 --- a/adev/test-main.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -import {NgModule, provideZonelessChangeDetection} from '@angular/core'; -import {TestBed} from '@angular/core/testing'; -import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing'; - -@NgModule({ - providers: [provideZonelessChangeDetection()], -}) -export class TestModule {} - -TestBed.initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting()); diff --git a/adev/tools/BUILD.bazel b/adev/tools/BUILD.bazel deleted file mode 100644 index 7b9cbe3e6db..00000000000 --- a/adev/tools/BUILD.bazel +++ /dev/null @@ -1,12 +0,0 @@ -load("@aspect_rules_js//js:defs.bzl", "js_library") - -package(default_visibility = [ - "//adev:__subpackages__", -]) - -js_library( - name = "windows-chromium-path", - srcs = [ - "windows-chromium-path.js", - ], -) diff --git a/adev/tools/windows-chromium-path.js b/adev/tools/windows-chromium-path.js deleted file mode 100644 index 483bff23b22..00000000000 --- a/adev/tools/windows-chromium-path.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -const os = require('os'); -const path = require('path'); - -/* - TODO: this is a hack; the root cause should be found and fixed. - - For some unknown reason, the symlinked copy of chromium under runfiles won't run under - karma on Windows. To work around this, use chromium under the execroot in the external - folder and point to that instead. - - Return: - The adjusted absolute chromium path to use on Windows. On other platforms this is a - noop and returns the existing process.env.CHROME_BIN. -*/ -exports.getAdjustedChromeBinPathForWindows = function () { - if (os.platform() === 'win32') { - const runfilesWorkspaceRoot = path.join(process.env.RUNFILES, 'angular'); - - // Get the path to chromium from the runfiles base folder. By default, the Bazel make var - // $(CHROMIUM) (which CHROME_BIN is set to) has a preceding '../' to escape the workspace - // root within runfiles. Additional '../' may have been prepended to cancel out any chdirs. - const chromiumPath = process.env.CHROME_BIN.replace(/^(\.\.\/)*/, ''); - - // Escape from runfiles to the exec root - const execRootSlashWorkspace = 'execroot' + path.sep + 'angular'; - const index = runfilesWorkspaceRoot.indexOf(execRootSlashWorkspace); - const execRootPath = runfilesWorkspaceRoot.substring(0, index + execRootSlashWorkspace.length); - const runfilesToExecRoot = path.relative(runfilesWorkspaceRoot, execRootPath); - - // Resolve the path to chromium under the execroot - const chromiumExecRootPath = path.resolve( - runfilesWorkspaceRoot, - runfilesToExecRoot, - 'external', - chromiumPath, - ); - - return chromiumExecRootPath; - } - return process.env.CHROME_BIN; -}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b1ce33fe5aa..c715b847f86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -514,9 +514,6 @@ importers: '@algolia/requester-node-http': specifier: 5.41.0 version: 5.41.0 - '@angular-devkit/build-angular': - specifier: 21.0.0-next.9 - version: 21.0.0-next.9(0d561972421c35029e2a2294be3fedb0) '@angular/animations': specifier: workspace:* version: link:../packages/animations @@ -740,6 +737,9 @@ importers: autoprefixer: specifier: 10.4.21 version: 10.4.21(postcss@8.5.6) + karma: + specifier: ~6.4.4 + version: 6.4.4(bufferutil@4.0.9)(utf-8-validate@6.0.5) postcss: specifier: 8.5.6 version: 8.5.6 @@ -10525,7 +10525,6 @@ packages: engines: {node: '>=0.6.0', teleport: '>=0.2.0'} deprecated: |- You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. - (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) qjobs@1.2.0: @@ -13030,101 +13029,6 @@ snapshots: transitivePeerDependencies: - chokidar - '@angular-devkit/build-angular@21.0.0-next.9(0d561972421c35029e2a2294be3fedb0)': - dependencies: - '@ampproject/remapping': 2.3.0 - '@angular-devkit/architect': 0.2100.0-next.9(chokidar@4.0.3) - '@angular-devkit/build-webpack': 0.2100.0-next.9(chokidar@4.0.3)(webpack-dev-server@5.2.2(bufferutil@4.0.9)(utf-8-validate@6.0.5)(webpack@5.102.1(esbuild@0.25.11)))(webpack@5.102.1(esbuild@0.25.11)) - '@angular-devkit/core': 21.0.0-next.9(chokidar@4.0.3) - '@angular/build': 21.0.0-next.9(27fc717c41beaddc6d6a50516b43cd52) - '@angular/compiler-cli': link:packages/compiler-cli - '@babel/core': 7.28.4 - '@babel/generator': 7.28.3 - '@babel/helper-annotate-as-pure': 7.27.3 - '@babel/helper-split-export-declaration': 7.24.7 - '@babel/plugin-transform-async-generator-functions': 7.28.0(@babel/core@7.28.4) - '@babel/plugin-transform-async-to-generator': 7.27.1(@babel/core@7.28.4) - '@babel/plugin-transform-runtime': 7.28.3(@babel/core@7.28.4) - '@babel/preset-env': 7.28.3(@babel/core@7.28.4) - '@babel/runtime': 7.28.4 - '@discoveryjs/json-ext': 0.6.3 - '@ngtools/webpack': 21.0.0-next.9(@angular/compiler-cli@packages+compiler-cli)(typescript@5.9.3)(webpack@5.102.1(esbuild@0.25.11)) - ansi-colors: 4.1.3 - autoprefixer: 10.4.21(postcss@8.5.6) - babel-loader: 10.0.0(@babel/core@7.28.4)(webpack@5.102.1(esbuild@0.25.11)) - browserslist: 4.27.0 - copy-webpack-plugin: 13.0.1(webpack@5.102.1(esbuild@0.25.11)) - css-loader: 7.1.2(webpack@5.102.1(esbuild@0.25.11)) - esbuild-wasm: 0.25.11 - http-proxy-middleware: 3.0.5 - istanbul-lib-instrument: 6.0.3 - jsonc-parser: 3.3.1 - karma-source-map-support: 1.4.0 - less: 4.4.2 - less-loader: 12.3.0(less@4.4.2)(webpack@5.102.1(esbuild@0.25.11)) - license-webpack-plugin: 4.0.2(webpack@5.102.1(esbuild@0.25.11)) - loader-utils: 3.3.1 - mini-css-extract-plugin: 2.9.4(webpack@5.102.1(esbuild@0.25.11)) - open: 10.2.0 - ora: 9.0.0 - picomatch: 4.0.3 - piscina: 5.1.3 - postcss: 8.5.6 - postcss-loader: 8.2.0(postcss@8.5.6)(typescript@5.9.3)(webpack@5.102.1(esbuild@0.25.11)) - resolve-url-loader: 5.0.0 - rxjs: 7.8.2 - sass: 1.93.2 - sass-loader: 16.0.5(sass@1.93.2)(webpack@5.102.1(esbuild@0.25.11)) - semver: 7.7.3 - source-map-loader: 5.0.0(webpack@5.102.1(esbuild@0.25.11)) - source-map-support: 0.5.21 - terser: 5.44.0 - tinyglobby: 0.2.15 - tree-kill: 1.2.2 - tslib: 2.8.1 - typescript: 5.9.3 - webpack: 5.102.1(esbuild@0.25.11) - webpack-dev-middleware: 7.4.5(webpack@5.102.1(esbuild@0.25.11)) - webpack-dev-server: 5.2.2(bufferutil@4.0.9)(utf-8-validate@6.0.5)(webpack@5.102.1(esbuild@0.25.11)) - webpack-merge: 6.0.1 - webpack-subresource-integrity: 5.1.0(webpack@5.102.1(esbuild@0.25.11)) - optionalDependencies: - '@angular/core': link:packages/core - '@angular/localize': link:packages/localize - '@angular/platform-browser': link:packages/platform-browser - '@angular/platform-server': link:packages/platform-server - '@angular/service-worker': link:packages/service-worker - '@angular/ssr': 21.0.0-next.9(@angular/common@packages+common)(@angular/core@packages+core)(@angular/platform-server@packages+platform-server)(@angular/router@packages+router) - esbuild: 0.25.11 - jest: 30.2.0(@types/node@24.9.1)(ts-node@10.9.2(@types/node@24.9.1)(typescript@5.9.3)) - jest-environment-jsdom: 30.2.0(bufferutil@4.0.9)(utf-8-validate@6.0.5) - karma: 6.4.4(bufferutil@4.0.9)(utf-8-validate@6.0.5) - ng-packagr: 21.0.0-next.4(@angular/compiler-cli@packages+compiler-cli)(tailwindcss@3.4.18(tsx@4.20.6)(yaml@2.8.1))(tslib@2.8.1)(typescript@5.9.3) - protractor: 7.0.0 - tailwindcss: 3.4.18(tsx@4.20.6)(yaml@2.8.1) - transitivePeerDependencies: - - '@angular/compiler' - - '@rspack/core' - - '@swc/core' - - '@types/node' - - bufferutil - - chokidar - - debug - - html-webpack-plugin - - jiti - - lightningcss - - node-sass - - sass-embedded - - stylus - - sugarss - - supports-color - - tsx - - uglify-js - - utf-8-validate - - vitest - - webpack-cli - - yaml - '@angular-devkit/build-angular@21.0.0-next.9(5abb7f248f26cfa404fde9da1295c7e8)': dependencies: '@ampproject/remapping': 2.3.0