Skip to content

Commit 4af7e0c

Browse files
josephperrottatscott
authored andcommitted
build: set up adev testing (angular#53854)
Set up testing for the adev directory PR Close angular#53854
1 parent 9bbc415 commit 4af7e0c

13 files changed

Lines changed: 298 additions & 106 deletions

File tree

adev/BUILD.bazel

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("//:packages.bzl", "link_packages")
22
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
3-
load("@npm//@angular-devkit/architect-cli:index.bzl", "architect")
3+
load("@npm//@angular-devkit/architect-cli:index.bzl", "architect", "architect_test")
44

55
package(default_visibility = ["//visibility:public"])
66

@@ -21,6 +21,13 @@ APPLICATION_FILES = [
2121
],
2222
)
2323

24+
TEST_FILES = APPLICATION_FILES + [
25+
"karma.conf.js",
26+
"tsconfig.spec.json",
27+
] + glob(
28+
["**/*.spec.ts"],
29+
)
30+
2431
APPLICATION_DEPS = link_packages([
2532
"@npm//@angular-devkit/build-angular",
2633
"@npm//@angular/animations",
@@ -69,6 +76,21 @@ APPLICATION_DEPS = link_packages([
6976
"@npm//angular-split",
7077
])
7178

79+
TEST_DEPS = APPLICATION_DEPS + link_packages([
80+
"@npm//@angular/platform-browser-dynamic",
81+
"@npm//@angular/build-tooling/bazel/browsers/chromium",
82+
"@npm//@types/jasmine",
83+
"@npm//@types/node",
84+
"@npm//assert",
85+
"@npm//jasmine",
86+
"@npm//jasmine-core",
87+
"@npm//karma-chrome-launcher",
88+
"@npm//karma-coverage",
89+
"@npm//karma-jasmine",
90+
"@npm//karma-jasmine-html-reporter",
91+
"//aio/tools:windows-chromium-path",
92+
])
93+
7294
copy_to_bin(
7395
name = "application_files_bin",
7496
srcs = APPLICATION_FILES,
@@ -100,3 +122,19 @@ architect(
100122
":application_files_bin",
101123
],
102124
)
125+
126+
architect_test(
127+
name = "test",
128+
args = [
129+
"angular-dev:test",
130+
"--no-watch",
131+
],
132+
chdir = package_name(),
133+
data = TEST_DEPS + TEST_FILES,
134+
env = {
135+
"CHROME_BIN": "../$(CHROMIUM)",
136+
},
137+
toolchains = [
138+
"@npm//@angular/build-tooling/bazel/browsers/chromium:toolchain_alias",
139+
],
140+
)

adev/angular.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"polyfills": ["zone.js", "zone.js/testing"],
9090
"tsConfig": "tsconfig.spec.json",
9191
"include": ["src/app"],
92+
"karmaConfig": "karma.conf.js",
9293
"inlineStyleLanguage": "scss",
9394
"assets": ["src/favicon.ico", "src/assets"],
9495
"styles": ["@angular/docs/styles/global-styles.scss"],

adev/karma.conf.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
const {getAdjustedChromeBinPathForWindows} = require('../aio/tools/windows-chromium-path');
5+
6+
process.env.CHROME_BIN = getAdjustedChromeBinPathForWindows();
7+
8+
module.exports = function (config) {
9+
config.set({
10+
basePath: '',
11+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
12+
plugins: [
13+
require('karma-jasmine'),
14+
require('karma-chrome-launcher'),
15+
require('karma-jasmine-html-reporter'),
16+
require('karma-coverage'),
17+
require('@angular-devkit/build-angular/plugins/karma'),
18+
{'reporter:jasmine-seed': ['type', JasmineSeedReporter]},
19+
],
20+
proxies: {
21+
'/dummy/image': 'src/assets/images/logos/angular/angular.png',
22+
},
23+
client: {
24+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
25+
jasmine: {
26+
// you can add configuration options for Jasmine here
27+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
28+
// for example, you can disable the random execution with `random: false`
29+
// or set a specific seed with `seed: 4321`
30+
random: true,
31+
seed: '',
32+
},
33+
},
34+
jasmineHtmlReporter: {
35+
suppressAll: true // removes the duplicated traces
36+
},
37+
coverageReporter: {
38+
dir: require('path').join(__dirname, './coverage/site'),
39+
subdir: '.',
40+
reporters: [
41+
{ type: 'html' },
42+
{ type: 'text-summary' }
43+
],
44+
},
45+
reporters: ['progress', 'kjhtml', 'jasmine-seed'],
46+
port: 9876,
47+
colors: true,
48+
logLevel: config.LOG_INFO,
49+
autoWatch: true,
50+
customLaunchers: {
51+
ChromeHeadlessNoSandbox: {
52+
base: 'ChromeHeadless',
53+
// See /integration/README.md#browser-tests for more info on these args
54+
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--hide-scrollbars', '--mute-audio'],
55+
},
56+
},
57+
browsers: ['ChromeHeadlessNoSandbox'],
58+
browserNoActivityTimeout: 60000,
59+
singleRun: false,
60+
restartOnFileChange: true,
61+
});
62+
};
63+
64+
// Helpers
65+
function JasmineSeedReporter(baseReporterDecorator) {
66+
baseReporterDecorator(this);
67+
68+
this.onBrowserComplete = (browser, result) => {
69+
const seed = result.order && result.order.random && result.order.seed;
70+
if (seed) this.write(`${browser}: Randomized with seed ${seed}.\n`);
71+
};
72+
73+
this.onRunComplete = () => undefined;
74+
}

adev/src/app/core/services/analytics/analytics.service.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Injector} from '@angular/core';
10-
import {WINDOW} from '@angular/docs';
10+
import {ENVIRONMENT, WINDOW} from '@angular/docs';
1111
import {AnalyticsService} from './analytics.service';
1212

1313
describe('AnalyticsService', () => {
@@ -36,6 +36,7 @@ describe('AnalyticsService', () => {
3636

3737
injector = Injector.create({
3838
providers: [
39+
{provide: ENVIRONMENT, useValue: {}},
3940
{provide: AnalyticsService, deps: [WINDOW]},
4041
{provide: WINDOW, useFactory: () => mockWindow, deps: []},
4142
],

adev/src/app/editor/code-editor/code-editor.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {EmbeddedTutorialManager} from '../embedded-tutorial-manager.service';
1919

2020
import {CodeEditor, REQUIRED_FILES} from './code-editor.component';
2121
import {CodeMirrorEditor} from './code-mirror-editor.service';
22-
import {FakeChangeDetectorRef} from '../../../../../shared/src/lib/utils/test-utils.spec';
22+
import {FakeChangeDetectorRef} from '@angular/docs/testing';
2323
import {TutorialType} from '@angular/docs';
2424

2525
const files = [

0 commit comments

Comments
 (0)