Skip to content

Commit 177eab2

Browse files
gkalpakjosephperrott
authored andcommitted
ci: add integration test for Angular Elemens with SSR (angular#40559)
This commit adds an integration test that uses `@angular/elements` with `@angular/platform-server` in order to highlight a current incompatibility. The issue will be fixed in a subsequent commit. PR Close angular#40559
1 parent b5efc95 commit 177eab2

35 files changed

+10161
-0
lines changed

.bazelignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ integration/bazel-schematics/demo
1717
# All integration test node_modules folders
1818
integration/bazel/node_modules
1919
integration/bazel-schematics/node_modules
20+
integration/cli-elements-universal/node_modules
2021
integration/cli-hello-world/node_modules
2122
integration/cli-hello-world-ivy-compat/node_modules
2223
integration/cli-hello-world-ivy-i18n/node_modules
@@ -44,6 +45,7 @@ integration/typings_test_ts37/node_modules
4445
# All integration test .yarn_local_cache folders
4546
integration/bazel/.yarn_local_cache
4647
integration/bazel-schematics/.yarn_local_cache
48+
integration/cli-elements-universal/.yarn_local_cache
4749
integration/cli-hello-world/.yarn_local_cache
4850
integration/cli-hello-world-ivy-compat/.yarn_local_cache
4951
integration/cli-hello-world-ivy-i18n/.yarn_local_cache
@@ -71,6 +73,7 @@ integration/typings_test_ts37/.yarn_local_cache
7173
# All integration test NPM_PACKAGE_MANIFEST.json folders
7274
integration/bazel/NPM_PACKAGE_MANIFEST.json
7375
integration/bazel-schematics/NPM_PACKAGE_MANIFEST.json
76+
integration/cli-elements-universal/NPM_PACKAGE_MANIFEST.json
7477
integration/cli-hello-world/NPM_PACKAGE_MANIFEST.json
7578
integration/cli-hello-world-ivy-compat/NPM_PACKAGE_MANIFEST.json
7679
integration/cli-hello-world-ivy-i18n/NPM_PACKAGE_MANIFEST.json

integration/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ INTEGRATION_TESTS = {
3333
"no-ivy-aot",
3434
],
3535
},
36+
"cli-elements-universal": {},
3637
"cli-hello-world": {"commands": "payload_size_tracking"},
3738
"cli-hello-world-ivy-compat": {"commands": "payload_size_tracking"},
3839
"cli-hello-world-ivy-i18n": {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# For the full list of supported browsers by the Angular framework, please see:
6+
# https://angular.io/guide/browser-support
7+
8+
# You can see what browsers were selected by your queries by running:
9+
# npx browserslist
10+
11+
last 1 Chrome version
12+
last 1 Firefox version
13+
last 2 Edge major versions
14+
last 2 Safari major versions
15+
last 2 iOS major versions
16+
Firefox ESR
17+
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
# Only exists if Bazel was run
8+
/bazel-out
9+
10+
# dependencies
11+
/node_modules
12+
13+
# profiling files
14+
chrome-profiler-events*.json
15+
speed-measure-plugin*.json
16+
17+
# IDEs and editors
18+
/.idea
19+
.project
20+
.classpath
21+
.c9/
22+
*.launch
23+
.settings/
24+
*.sublime-workspace
25+
26+
# IDE - VSCode
27+
.vscode/*
28+
!.vscode/settings.json
29+
!.vscode/tasks.json
30+
!.vscode/launch.json
31+
!.vscode/extensions.json
32+
.history/*
33+
34+
# misc
35+
/.sass-cache
36+
/connect.lock
37+
/coverage
38+
/libpeerconnection.log
39+
npm-debug.log
40+
yarn-error.log
41+
testem.log
42+
/typings
43+
44+
# System Files
45+
.DS_Store
46+
Thumbs.db
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# CliElementsUniversal
2+
3+
This project tests the integration of Angular Elements (`@angular/elements`) with SSR (via `@angular/platform-server`).
4+
5+
The project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.1.4.
6+
Support for Angular Elements was added with `ng add @angular/elements` and for SSR with `ng generate app-shell`.
7+
8+
What this project tests is that an app can be successfully SSR'd even when it uses `@angular/elements`, which relies on certain DOM built-ins being available as soon as it is imported.
9+
This is tested by generating the [app-shell](https://angular.io/guide/app-shell) (using `ng run cli-elements-universal:app-shell:production`) and then verifying that the `index.html` file was generated correctly.
10+
(See, the `test-ssr` script in [package.json](./package.json).)
11+
12+
NOTE:
13+
Currently, `domino` (the server-side DOM implementation used by `@angular/platform-server`) does not support [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components), so the Custom Elements functionality does not work on the server.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"cli-elements-universal": {
7+
"projectType": "application",
8+
"schematics": {
9+
"@schematics/angular:application": {
10+
"strict": true
11+
}
12+
},
13+
"root": "",
14+
"sourceRoot": "src",
15+
"prefix": "app",
16+
"architect": {
17+
"build": {
18+
"builder": "@angular-devkit/build-angular:browser",
19+
"options": {
20+
"outputPath": "dist/cli-elements-universal/browser",
21+
"index": "src/index.html",
22+
"main": "src/main.ts",
23+
"polyfills": "src/polyfills.ts",
24+
"tsConfig": "tsconfig.app.json",
25+
"aot": true,
26+
"assets": [
27+
"src/favicon.ico",
28+
"src/assets"
29+
],
30+
"styles": [
31+
"src/styles.css"
32+
],
33+
"scripts": [],
34+
"progress": false
35+
},
36+
"configurations": {
37+
"production": {
38+
"fileReplacements": [
39+
{
40+
"replace": "src/environments/environment.ts",
41+
"with": "src/environments/environment.prod.ts"
42+
}
43+
],
44+
"optimization": true,
45+
"outputHashing": "all",
46+
"sourceMap": false,
47+
"namedChunks": false,
48+
"extractLicenses": true,
49+
"vendorChunk": false,
50+
"buildOptimizer": true,
51+
"budgets": [
52+
{
53+
"type": "initial",
54+
"maximumWarning": "500kb",
55+
"maximumError": "1mb"
56+
},
57+
{
58+
"type": "anyComponentStyle",
59+
"maximumWarning": "2kb",
60+
"maximumError": "4kb"
61+
}
62+
]
63+
}
64+
}
65+
},
66+
"serve": {
67+
"builder": "@angular-devkit/build-angular:dev-server",
68+
"options": {
69+
"browserTarget": "cli-elements-universal:build"
70+
},
71+
"configurations": {
72+
"production": {
73+
"browserTarget": "cli-elements-universal:build:production"
74+
}
75+
}
76+
},
77+
"extract-i18n": {
78+
"builder": "@angular-devkit/build-angular:extract-i18n",
79+
"options": {
80+
"browserTarget": "cli-elements-universal:build"
81+
}
82+
},
83+
"test": {
84+
"builder": "@angular-devkit/build-angular:karma",
85+
"options": {
86+
"main": "src/test.ts",
87+
"polyfills": "src/polyfills.ts",
88+
"tsConfig": "tsconfig.spec.json",
89+
"karmaConfig": "karma.conf.js",
90+
"assets": [
91+
"src/favicon.ico",
92+
"src/assets"
93+
],
94+
"styles": [
95+
"src/styles.css"
96+
],
97+
"scripts": [],
98+
"watch": false
99+
}
100+
},
101+
"lint": {
102+
"builder": "@angular-devkit/build-angular:tslint",
103+
"options": {
104+
"tsConfig": [
105+
"tsconfig.app.json",
106+
"tsconfig.spec.json",
107+
"e2e/tsconfig.json",
108+
"tsconfig.server.json"
109+
],
110+
"exclude": [
111+
"**/node_modules/**"
112+
]
113+
}
114+
},
115+
"e2e": {
116+
"builder": "@angular-devkit/build-angular:protractor",
117+
"options": {
118+
"protractorConfig": "e2e/protractor.conf.js",
119+
"devServerTarget": "cli-elements-universal:serve",
120+
"webdriverUpdate": false
121+
},
122+
"configurations": {
123+
"production": {
124+
"devServerTarget": "cli-elements-universal:serve:production"
125+
}
126+
}
127+
},
128+
"server": {
129+
"builder": "@angular-devkit/build-angular:server",
130+
"options": {
131+
"outputPath": "dist/cli-elements-universal/server",
132+
"main": "src/main.server.ts",
133+
"tsConfig": "tsconfig.server.json",
134+
"progress": false
135+
},
136+
"configurations": {
137+
"production": {
138+
"outputHashing": "media",
139+
"fileReplacements": [
140+
{
141+
"replace": "src/environments/environment.ts",
142+
"with": "src/environments/environment.prod.ts"
143+
}
144+
],
145+
"sourceMap": false,
146+
"optimization": true
147+
}
148+
}
149+
},
150+
"app-shell": {
151+
"builder": "@angular-devkit/build-angular:app-shell",
152+
"options": {
153+
"browserTarget": "cli-elements-universal:build",
154+
"serverTarget": "cli-elements-universal:server",
155+
"route": ""
156+
},
157+
"configurations": {
158+
"production": {
159+
"browserTarget": "cli-elements-universal:build:production",
160+
"serverTarget": "cli-elements-universal:server:production"
161+
}
162+
}
163+
}
164+
}
165+
}
166+
},
167+
"defaultProject": "cli-elements-universal"
168+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @ts-check
2+
// Protractor configuration file, see link for more information
3+
// https://github.com/angular/protractor/blob/master/lib/config.ts
4+
5+
const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');
6+
7+
/**
8+
* @type { import("protractor").Config }
9+
*/
10+
exports.config = {
11+
allScriptsTimeout: 11000,
12+
specs: [
13+
'./src/**/*.e2e-spec.ts'
14+
],
15+
capabilities: {
16+
browserName: 'chrome',
17+
chromeOptions: {
18+
binary: require('puppeteer').executablePath(),
19+
// See /integration/README.md#browser-tests for more info on these args
20+
args: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--hide-scrollbars', '--mute-audio']
21+
},
22+
},
23+
directConnect: true,
24+
SELENIUM_PROMISE_MANAGER: false,
25+
baseUrl: 'http://localhost:4200/',
26+
framework: 'jasmine',
27+
jasmineNodeOpts: {
28+
showColors: true,
29+
defaultTimeoutInterval: 30000,
30+
print: function() {}
31+
},
32+
onPrepare() {
33+
require('ts-node').register({
34+
project: require('path').join(__dirname, './tsconfig.json')
35+
});
36+
jasmine.getEnv().addReporter(new SpecReporter({
37+
spec: {
38+
displayStacktrace: StacktraceOption.PRETTY
39+
}
40+
}));
41+
}
42+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { AppPage } from './app.po';
2+
import { browser, logging } from 'protractor';
3+
4+
describe('workspace-project App', () => {
5+
let page: AppPage;
6+
7+
beforeEach(() => {
8+
page = new AppPage();
9+
});
10+
11+
afterEach(async () => {
12+
// Assert that there are no errors emitted from the browser.
13+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
14+
const errorLogs = logs.filter(({level}) => level === logging.Level.SEVERE);
15+
expect(errorLogs).toEqual([]);
16+
});
17+
18+
it('should display welcome message', async () => {
19+
await page.navigateTo();
20+
expect(await page.getTitleText()).toBe('cli-elements-universal app is running!');
21+
});
22+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { browser, by, element } from 'protractor';
2+
3+
export class AppPage {
4+
async navigateTo(): Promise<unknown> {
5+
return browser.get(browser.baseUrl);
6+
}
7+
8+
async getTitleText(): Promise<string> {
9+
return element(by.css('h1')).getText();
10+
}
11+
}

0 commit comments

Comments
 (0)