Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 2be1c3c

Browse files
committed
test(@nguniversal/common): update e2e test
(cherry picked from commit e1fa4e5)
1 parent b990c82 commit 2be1c3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+732
-326
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# universal-integration
2+
3+
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.0-next.4.
4+
5+
## Development server
6+
7+
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8+
9+
## Code scaffolding
10+
11+
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12+
13+
## Build
14+
15+
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
16+
17+
## Running unit tests
18+
19+
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20+
21+
## Running end-to-end tests
22+
23+
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24+
25+
## Further help
26+
27+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"common": {
7+
"projectType": "application",
8+
"schematics": {
9+
"@schematics/angular:component": {
10+
"inlineTemplate": true,
11+
"inlineStyle": true,
12+
"skipTests": true
13+
},
14+
"@schematics/angular:class": {
15+
"skipTests": true
16+
},
17+
"@schematics/angular:directive": {
18+
"skipTests": true
19+
},
20+
"@schematics/angular:guard": {
21+
"skipTests": true
22+
},
23+
"@schematics/angular:module": {
24+
"skipTests": true
25+
},
26+
"@schematics/angular:pipe": {
27+
"skipTests": true
28+
},
29+
"@schematics/angular:service": {
30+
"skipTests": true
31+
}
32+
},
33+
"root": "",
34+
"sourceRoot": "src",
35+
"prefix": "app",
36+
"architect": {
37+
"build": {
38+
"builder": "@angular-devkit/build-angular:browser",
39+
"options": {
40+
"progress": false,
41+
"outputPath": "dist/common/browser",
42+
"index": "src/index.html",
43+
"main": "src/main.ts",
44+
"polyfills": "src/polyfills.ts",
45+
"tsConfig": "tsconfig.app.json",
46+
"aot": true,
47+
"assets": [
48+
"src/favicon.ico",
49+
"src/assets"
50+
],
51+
"styles": [
52+
"src/styles.css"
53+
],
54+
"scripts": []
55+
},
56+
"configurations": {
57+
"production": {
58+
"fileReplacements": [
59+
{
60+
"replace": "src/environments/environment.ts",
61+
"with": "src/environments/environment.prod.ts"
62+
}
63+
],
64+
"optimization": true,
65+
"outputHashing": "all",
66+
"sourceMap": false,
67+
"namedChunks": false,
68+
"extractLicenses": true,
69+
"vendorChunk": false,
70+
"buildOptimizer": true,
71+
"budgets": [
72+
{
73+
"type": "initial",
74+
"maximumWarning": "2mb",
75+
"maximumError": "5mb"
76+
},
77+
{
78+
"type": "anyComponentStyle",
79+
"maximumWarning": "6kb",
80+
"maximumError": "10kb"
81+
}
82+
]
83+
}
84+
}
85+
},
86+
"serve": {
87+
"builder": "@angular-devkit/build-angular:dev-server",
88+
"options": {
89+
"browserTarget": "common:build"
90+
},
91+
"configurations": {
92+
"production": {
93+
"browserTarget": "common:build:production"
94+
}
95+
}
96+
},
97+
"serve-ssr": {
98+
"builder": "@nguniversal/builders:ssr-dev-server",
99+
"options": {
100+
"browserTarget": "common:build",
101+
"serverTarget": "common:server"
102+
},
103+
"configurations": {
104+
"production": {
105+
"browserTarget": "common:build:production",
106+
"serverTarget": "common:server:production"
107+
}
108+
}
109+
},
110+
"extract-i18n": {
111+
"builder": "@angular-devkit/build-angular:extract-i18n",
112+
"options": {
113+
"browserTarget": "common:build"
114+
}
115+
},
116+
"test": {
117+
"builder": "@angular-devkit/build-angular:karma",
118+
"options": {
119+
"main": "src/test.ts",
120+
"polyfills": "src/polyfills.ts",
121+
"tsConfig": "tsconfig.spec.json",
122+
"karmaConfig": "karma.conf.js",
123+
"assets": [
124+
"src/favicon.ico",
125+
"src/assets"
126+
],
127+
"styles": [
128+
"src/styles.css"
129+
],
130+
"scripts": []
131+
}
132+
},
133+
"lint": {
134+
"builder": "@angular-devkit/build-angular:tslint",
135+
"options": {
136+
"tsConfig": [
137+
"tsconfig.app.json",
138+
"tsconfig.spec.json",
139+
"e2e/tsconfig.json"
140+
],
141+
"exclude": [
142+
"**/node_modules/**"
143+
]
144+
}
145+
},
146+
"e2e": {
147+
"builder": "@angular-devkit/build-angular:protractor",
148+
"options": {
149+
"webdriverUpdate": false,
150+
"protractorConfig": "e2e/protractor.conf.js"
151+
}
152+
},
153+
"server": {
154+
"builder": "@angular-devkit/build-angular:server",
155+
"options": {
156+
"progress": false,
157+
"outputPath": "dist/common/server",
158+
"main": "server.ts",
159+
"tsConfig": "tsconfig.server.json"
160+
},
161+
"configurations": {
162+
"production": {
163+
"fileReplacements": [
164+
{
165+
"replace": "src/environments/environment.ts",
166+
"with": "src/environments/environment.prod.ts"
167+
}
168+
],
169+
"sourceMap": false,
170+
"optimization": true
171+
}
172+
}
173+
}
174+
}
175+
}},
176+
"defaultProject": "common"
177+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
# You can see what browsers were selected by your queries by running:
6+
# npx browserslist
7+
8+
> 0.5%
9+
last 2 versions
10+
Firefox ESR
11+
not dead
12+
not IE 9-11 # For IE 9-11 support, remove 'not'.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 } = 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+
args: ['--headless'],
19+
binary: require('puppeteer').executablePath(),
20+
}
21+
},
22+
directConnect: true,
23+
baseUrl: 'http://localhost:4200/',
24+
framework: 'jasmine',
25+
jasmineNodeOpts: {
26+
showColors: true,
27+
defaultTimeoutInterval: 30000,
28+
print: function() {}
29+
},
30+
onPrepare() {
31+
require('ts-node').register({
32+
project: require('path').join(__dirname, './tsconfig.json')
33+
});
34+
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
35+
}
36+
};

integration/common/e2e/helloworld-spec.ts renamed to integration/common-engine/e2e/src/app.e2e-spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88

99
import {browser, by, element} from 'protractor';
1010

11-
import {verifyNoBrowserErrors} from './util';
11+
import {verifyNoBrowserErrors, waitForAppRootElement} from './util';
12+
13+
describe('Hello world E2E Tests', () => {
14+
beforeAll(async () => {
15+
await browser.driver.wait(
16+
waitForAppRootElement(),
17+
6000 * 2,
18+
'Server should have started in 2 minutes',
19+
);
20+
});
1221

13-
describe('Hello world E2E Tests', function() {
14-
it('should display: Hello world! with static counter', function() {
22+
it('should display: Hello world!', async () => {
1523
// Load the page without waiting for Angular since it is not bootstrapped automatically.
16-
browser.driver.get(browser.baseUrl + 'helloworld');
17-
24+
await browser.driver.get(browser.baseUrl);
1825

1926
const style = browser.driver.findElement(by.css('style[ng-transition="hlw"]'));
2027
expect(style.getText()).not.toBeNull();
2128

2229
// Test the contents from the server.
23-
const serverDiv = browser.driver.findElement(by.css('div#name'));
30+
const serverDiv = browser.driver.findElement(by.css('div'));
2431
expect(serverDiv.getText()).toMatch('Hello world!');
2532

26-
// Test the contents from the server.
27-
const counterDiv = browser.driver.findElement(by.css('div#counter'));
28-
expect(counterDiv.getText()).toMatch('Counter: 1');
29-
3033
// Bootstrap the client side app.
31-
browser.executeScript('doBootstrap()');
34+
await browser.executeScript('doBootstrap()');
3235

3336
// Retest the contents after the client bootstraps.
34-
expect(element(by.css('div#name')).getText()).toMatch('Hello world!');
35-
expect(element(by.css('div#counter')).getText()).toMatch('Counter: 1');
37+
expect(element(by.css('div')).getText()).toMatch('Hello world!');
3638

3739
// Make sure the server styles got replaced by client side ones.
3840
expect(element(by.css('style[ng-transition="hlw"]')).isPresent()).toBeFalsy();

integration/common/e2e/util.ts renamed to integration/common-engine/e2e/src/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
/* tslint:disable:no-console */
99
import * as webdriver from 'selenium-webdriver';
10+
import { by } from 'protractor';
1011
declare var browser: any;
1112
declare var expect: any;
1213

@@ -23,3 +24,14 @@ export function verifyNoBrowserErrors() {
2324
expect(errors).toEqual([]);
2425
});
2526
}
27+
28+
export async function waitForAppRootElement(): Promise<boolean> {
29+
try {
30+
await browser.driver.get(browser.baseUrl);
31+
await browser.driver.findElement(by.tagName('app-root'));
32+
return true;
33+
} catch {
34+
await browser.driver.sleep(1000);
35+
return waitForAppRootElement();
36+
}
37+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../out-tsc/e2e",
5+
"module": "commonjs",
6+
"target": "es5",
7+
"types": [
8+
"jasmine",
9+
"jasminewd2",
10+
"node"
11+
]
12+
}
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage-istanbul-reporter'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
clearContext: false // leave Jasmine Spec Runner output visible in browser
17+
},
18+
coverageIstanbulReporter: {
19+
dir: require('path').join(__dirname, './coverage/express-engine-ivy'),
20+
reports: ['html', 'lcovonly', 'text-summary'],
21+
fixWebpackSourcePaths: true
22+
},
23+
reporters: ['progress', 'kjhtml'],
24+
port: 9876,
25+
colors: true,
26+
logLevel: config.LOG_INFO,
27+
autoWatch: true,
28+
browsers: ['Chrome'],
29+
singleRun: false,
30+
restartOnFileChange: true
31+
});
32+
};

0 commit comments

Comments
 (0)