Skip to content

Commit 8083609

Browse files
wagnermacielvikerman
authored andcommitted
test: add e2e test for prerender builder (#1378)
1 parent 6865eb7 commit 8083609

38 files changed

+812
-0
lines changed
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).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"express-engine-ivy-prerender": {
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/express-engine-ivy-prerender/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+
"extractCss": true,
68+
"namedChunks": false,
69+
"extractLicenses": true,
70+
"vendorChunk": false,
71+
"buildOptimizer": true,
72+
"budgets": [
73+
{
74+
"type": "initial",
75+
"maximumWarning": "2mb",
76+
"maximumError": "5mb"
77+
},
78+
{
79+
"type": "anyComponentStyle",
80+
"maximumWarning": "6kb",
81+
"maximumError": "10kb"
82+
}
83+
]
84+
}
85+
}
86+
},
87+
"serve": {
88+
"builder": "@angular-devkit/build-angular:dev-server",
89+
"options": {
90+
"browserTarget": "express-engine-ivy-prerender:build"
91+
},
92+
"configurations": {
93+
"production": {
94+
"browserTarget": "express-engine-ivy-prerender:build:production"
95+
}
96+
}
97+
},
98+
"serve-ssr": {
99+
"builder": "@nguniversal/builders:ssr-dev-server",
100+
"options": {
101+
"browserTarget": "express-engine-ivy-prerender:build",
102+
"serverTarget": "express-engine-ivy-prerender:server"
103+
},
104+
"configurations": {
105+
"production": {
106+
"browserTarget": "express-engine-ivy-prerender:build:production",
107+
"serverTarget": "express-engine-ivy-prerender:server:production"
108+
}
109+
}
110+
},
111+
"extract-i18n": {
112+
"builder": "@angular-devkit/build-angular:extract-i18n",
113+
"options": {
114+
"browserTarget": "express-engine-ivy-prerender:build"
115+
}
116+
},
117+
"test": {
118+
"builder": "@angular-devkit/build-angular:karma",
119+
"options": {
120+
"main": "src/test.ts",
121+
"polyfills": "src/polyfills.ts",
122+
"tsConfig": "tsconfig.spec.json",
123+
"karmaConfig": "karma.conf.js",
124+
"assets": [
125+
"src/favicon.ico",
126+
"src/assets"
127+
],
128+
"styles": [
129+
"src/styles.css"
130+
],
131+
"scripts": []
132+
}
133+
},
134+
"lint": {
135+
"builder": "@angular-devkit/build-angular:tslint",
136+
"options": {
137+
"tsConfig": [
138+
"tsconfig.app.json",
139+
"tsconfig.spec.json",
140+
"e2e/tsconfig.json"
141+
],
142+
"exclude": [
143+
"**/node_modules/**"
144+
]
145+
}
146+
},
147+
"server": {
148+
"builder": "@angular-devkit/build-angular:server",
149+
"options": {
150+
"progress": false,
151+
"outputPath": "dist/express-engine-ivy-prerender/server",
152+
"main": "server.ts",
153+
"tsConfig": "tsconfig.server.json"
154+
},
155+
"configurations": {
156+
"production": {
157+
"fileReplacements": [
158+
{
159+
"replace": "src/environments/environment.ts",
160+
"with": "src/environments/environment.prod.ts"
161+
}
162+
],
163+
"sourceMap": false,
164+
"optimization": true
165+
}
166+
}
167+
},
168+
"prerender": {
169+
"builder": "@nguniversal/builders:prerender",
170+
"options": {
171+
"browserTarget": "express-engine-ivy-prerender:build:production",
172+
"serverTarget": "express-engine-ivy-prerender:server:production",
173+
"routes": []
174+
}
175+
},
176+
"e2e": {
177+
"builder": "@angular-devkit/build-angular:protractor",
178+
"options": {
179+
"webdriverUpdate": false,
180+
"protractorConfig": "e2e/protractor.conf.js",
181+
"baseUrl": "http://localhost:3000"
182+
}
183+
}
184+
}
185+
}
186+
},
187+
"defaultProject": "express-engine-ivy-prerender",
188+
"cli": {
189+
"analytics": false
190+
}
191+
}
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'.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
const { exec, execSync } = require('child_process');
7+
let serverDaemon;
8+
9+
/**
10+
* @type { import("protractor").Config }
11+
*/
12+
exports.config = {
13+
allScriptsTimeout: 11000,
14+
specs: [
15+
'./src/**/*.e2e-spec.ts'
16+
],
17+
capabilities: {
18+
browserName: 'chrome',
19+
chromeOptions: {
20+
args: ['--no-sandbox'],
21+
binary: process.env.CHROME_BIN,
22+
}
23+
},
24+
directConnect: true,
25+
baseUrl: 'http://localhost:3000/',
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({ spec: { displayStacktrace: true } }));
37+
serverDaemon = exec('node static-server');
38+
execSync(
39+
'ng run express-engine-ivy-prerender:prerender --routes=pikachu',
40+
{ stdio: 'inherit' },
41+
);
42+
},
43+
onComplete() {
44+
serverDaemon.kill();
45+
},
46+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { AppPage } from './app.po';
2+
3+
describe('workspace-project App', () => {
4+
let page: AppPage;
5+
6+
beforeEach(() => {
7+
page = new AppPage();
8+
});
9+
10+
it('should have prerendered /pikachu', async () => {
11+
page.navigateTo('pikachu');
12+
expect(await page.getTitleText()).toEqual('pikachu');
13+
});
14+
15+
it('should not have prerendered anything else', async () => {
16+
// This test is just to verify that we are serving ONLY static content.
17+
expect(await page.is404('charmander'));
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { browser, by, element, logging } from 'protractor';
2+
3+
export class AppPage {
4+
navigateTo(route: string) {
5+
browser.get(browser.baseUrl + route);
6+
}
7+
8+
getTitleText() {
9+
return element(by.tagName('h1')).getText() as Promise<string>;
10+
}
11+
12+
async is404(route: string) {
13+
// Need this to avoid getting an "Angular could not be found on the page" error
14+
browser.waitForAngularEnabled(false);
15+
browser.get(`/${route}`);
16+
browser.waitForAngularEnabled(true);
17+
18+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19+
if (!logs.length) {
20+
return false;
21+
}
22+
23+
const lastError = logs[logs.length - 1];
24+
const errmsg = `http://localhost:3000/${route} - Failed to load resource: the server responded with a status of 404 (Not Found)`
25+
26+
return lastError.message === errmsg;
27+
}
28+
}
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+
}
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-prerender'),
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)