mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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.
This commit is contained in:
committed by
Kristiyan Kostadinov
parent
b4e798ed87
commit
46d5670688
+1
-8
@@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
+8
-18
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
+16
-16
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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());
|
||||
@@ -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",
|
||||
],
|
||||
)
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user