Skip to content

Commit 8630dc8

Browse files
alan-agius4AndrewKushnir
authored andcommitted
test: add Integration tests for hydration and event reply (angular#55708)
This commit introduces integration tests for hydration and event reply functionalities. Additionally, it implements a payload size check for the `event-dispatch-contract.min.js`. PR Close angular#55708
1 parent ca6cdcd commit 8630dc8

28 files changed

+7144
-3
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ integration/cli-hello-world-ivy-i18n/node_modules
1717
integration/cli-hello-world-lazy/node_modules
1818
integration/cli-hello-world-mocha/node_modules
1919
integration/cli-signal-inputs/node_modules
20+
integration/platform-server-hydration/node_modules
2021
integration/defer/node_modules
2122
integration/dynamic-compiler/node_modules
2223
integration/forms/node_modules

goldens/size-tracking/integration-payloads.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,12 @@
5151
"polyfills": 33807,
5252
"defer.component": 371
5353
}
54+
},
55+
"platform-server-hydration/browser": {
56+
"uncompressed": {
57+
"main": 200584,
58+
"polyfills": 33807,
59+
"event-dispatch-contract.min": 11293
60+
}
5461
}
5562
}

integration/ng_elements/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
"protractor": "protractor e2e/protractor.config.js"
3434
},
3535
"private": true
36-
}
36+
}
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+
/bazel-out
8+
9+
# Node
10+
/node_modules
11+
npm-debug.log
12+
yarn-error.log
13+
14+
# IDEs and editors
15+
.idea/
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
22+
*.sublime-workspace
23+
24+
# Visual Studio Code
25+
.vscode/*
26+
!.vscode/settings.json
27+
!.vscode/tasks.json
28+
!.vscode/launch.json
29+
!.vscode/extensions.json
30+
.history/*
31+
32+
# Miscellaneous
33+
/.angular/cache
34+
.sass-cache/
35+
/connect.lock
36+
/coverage
37+
/libpeerconnection.log
38+
testem.log
39+
/typings
40+
41+
# System files
42+
.DS_Store
43+
Thumbs.db
44+
45+
# event contract
46+
public/event-dispatch-contract.min.js
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("//integration:index.bzl", "ng_integration_test")
2+
3+
ng_integration_test(
4+
name = "test",
5+
setup_chromium = True,
6+
track_payload_paths = [
7+
"/browser",
8+
],
9+
track_payload_size = "platform-server-hydration",
10+
)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"cli": {
6+
"analytics": false,
7+
"cache": {
8+
"enabled": false
9+
}
10+
},
11+
"projects": {
12+
"hydration": {
13+
"projectType": "application",
14+
"schematics": {},
15+
"root": "",
16+
"sourceRoot": "src",
17+
"prefix": "app",
18+
"architect": {
19+
"build": {
20+
"builder": "@angular-devkit/build-angular:application",
21+
"options": {
22+
"progress": false,
23+
"outputPath": "dist",
24+
"index": "src/index.html",
25+
"browser": "src/main.ts",
26+
"polyfills": ["zone.js"],
27+
"tsConfig": "tsconfig.app.json",
28+
"assets": [
29+
{
30+
"glob": "**/*",
31+
"input": "public"
32+
}
33+
],
34+
"styles": ["src/styles.css"],
35+
"scripts": [],
36+
"server": "src/main.server.ts",
37+
"prerender": false,
38+
"ssr": true
39+
},
40+
"configurations": {
41+
"production": {
42+
"budgets": [
43+
{
44+
"type": "initial",
45+
"maximumWarning": "500kb",
46+
"maximumError": "1mb"
47+
},
48+
{
49+
"type": "anyComponentStyle",
50+
"maximumWarning": "2kb",
51+
"maximumError": "4kb"
52+
}
53+
],
54+
"outputHashing": "all"
55+
},
56+
"development": {
57+
"optimization": false,
58+
"extractLicenses": false,
59+
"sourceMap": true
60+
}
61+
},
62+
"defaultConfiguration": "production"
63+
},
64+
"serve": {
65+
"builder": "@angular-devkit/build-angular:dev-server",
66+
"options": {
67+
"port": 0
68+
},
69+
"configurations": {
70+
"production": {
71+
"buildTarget": "hydration:build:production"
72+
},
73+
"development": {
74+
"buildTarget": "hydration:build:development"
75+
}
76+
},
77+
"defaultConfiguration": "development"
78+
},
79+
"e2e": {
80+
"builder": "@angular-devkit/build-angular:protractor",
81+
"options": {
82+
"port": 0,
83+
"protractorConfig": "e2e/protractor.conf.js",
84+
"webdriverUpdate": false
85+
},
86+
"configurations": {
87+
"production": {
88+
"devServerTarget": "hydration:serve:production"
89+
},
90+
"development": {
91+
"devServerTarget": "hydration:serve:development"
92+
}
93+
},
94+
"defaultConfiguration": "development"
95+
}
96+
}
97+
}
98+
}
99+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* This script copies '@angular/core/event-dispatch-contract.min.js' to the 'public' directory, ensuring it's available as an asset.
3+
* This is necessary to perform size checks on the distributed script.
4+
*/
5+
6+
import {copyFileSync} from 'node:fs';
7+
8+
copyFileSync(
9+
'./node_modules/@angular/core/event-dispatch-contract.min.js',
10+
'public/event-dispatch-contract.min.js',
11+
);
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+
const {SpecReporter} = require('jasmine-spec-reporter');
5+
6+
/**
7+
* @type { import("protractor").Config }
8+
*/
9+
exports.config = {
10+
allScriptsTimeout: 11000,
11+
specs: ['./src/**/*.e2e-spec.ts'],
12+
chromeDriver: process.env.CHROMEDRIVER_BIN,
13+
capabilities: {
14+
browserName: 'chrome',
15+
chromeOptions: {
16+
binary: process.env.CHROME_BIN,
17+
// See /integration/README.md#browser-tests for more info on these args
18+
args: [
19+
'--no-sandbox',
20+
'--headless',
21+
'--disable-gpu',
22+
'--disable-dev-shm-usage',
23+
'--hide-scrollbars',
24+
'--mute-audio',
25+
],
26+
},
27+
},
28+
directConnect: true,
29+
baseUrl: 'http://localhost:4200/',
30+
framework: 'jasmine',
31+
jasmineNodeOpts: {
32+
showColors: true,
33+
defaultTimeoutInterval: 30000,
34+
print: function () {},
35+
},
36+
onPrepare() {
37+
require('ts-node').register({
38+
project: require('path').join(__dirname, './tsconfig.json'),
39+
});
40+
jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
41+
},
42+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {browser, by, element} from 'protractor';
2+
import {bootstrapClientApp, navigateTo, verifyNoBrowserErrors} from './util';
3+
4+
describe('App E2E Tests', () => {
5+
beforeEach(async () => {
6+
// Don't wait for Angular since it is not bootstrapped automatically.
7+
await browser.waitForAngularEnabled(false);
8+
9+
// Load the page without waiting for Angular since it is not bootstrapped automatically.
10+
await navigateTo('');
11+
});
12+
13+
afterEach(async () => {
14+
// Make sure there were no client side errors.
15+
await verifyNoBrowserErrors();
16+
});
17+
18+
it('should reply click event', async () => {
19+
const divElement = element(by.css('#divElement'));
20+
expect(await divElement.getText()).toContain('click not triggered');
21+
22+
// Trigger click
23+
await divElement.click();
24+
25+
// Bootstrap client application
26+
await bootstrapClientApp();
27+
28+
expect(await divElement.getText()).toContain('click triggered');
29+
});
30+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import * as webdriver from 'selenium-webdriver';
9+
import {browser} from 'protractor';
10+
11+
export async function verifyNoBrowserErrors(): Promise<void> {
12+
const browserLog = await browser.manage().logs().get('browser');
13+
const errors: string[] = [];
14+
15+
for (const {message, level} of browserLog) {
16+
console.log('>> ' + message);
17+
if (level.value >= webdriver.logging.Level.INFO.value) {
18+
errors.push(message);
19+
}
20+
}
21+
22+
expect(errors).toEqual([]);
23+
}
24+
25+
export async function navigateTo(url: string): Promise<void> {
26+
await browser.driver.get(browser.baseUrl + url);
27+
}
28+
29+
export async function bootstrapClientApp(): Promise<void> {
30+
await browser.executeScript('doBootstrap()');
31+
}

0 commit comments

Comments
 (0)