Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ivy): add render3 integration tests #21557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions integration/_payload-limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,19 @@
"bundle": 100661
}
}
},
"hello_world__render3__closure": {
"master": {
"uncompressed": {
"bundle": 6671
}
}
},
"hello_world__render3__rollup": {
"master": {
"uncompressed": {
"bundle": 56550
}
}
}
}
6 changes: 6 additions & 0 deletions integration/hello_world__render3__closure/clean_ngDevMode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# This script replaces 'ngDevMode' by false in @angular/core/render3 source code, so that this code can be eliminated.
# This is a workaround for https://github.com/google/closure-compiler/issues/1601

find built/packages/core/src/render3/* -name '*.js' -exec sed -i '' -e "s/import '.\/ng_dev_mode';//g" {} \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document what this does and why do we do it this way?

I thought closure had a way to set the compilation constant via config so I'm not sure why we do this kind of search&replace. if there is a good reason for it, please document it in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is workaround for google/closure-compiler#1601 Can you include the link in a comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you see if you can get it work with

-D "ngDevMode$$module$built$packages$core$src$render3$ng_dev_mode=false"
-D "ngDevMode=false"

This should set the closure compiler vars and tree shake them, but I don't seem to be able to get it to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added. Due to this bug, I couldn't make it work either.

find built/packages/core/src/render3/* -name '*.js' -exec sed -i '' -e 's/ngDevMode/false/g' {} \;
22 changes: 22 additions & 0 deletions integration/hello_world__render3__closure/closure.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--compilation_level=ADVANCED_OPTIMIZATIONS
--language_out=ES5
--js_output_file=dist/bundle.js
--output_manifest=dist/manifest.MF
--variable_renaming_report=dist/variable_renaming_report
--property_renaming_report=dist/property_renaming_report
--create_source_map=%outname%.map

--warning_level=QUIET
--dependency_mode=STRICT
--rewrite_polyfills=false
--jscomp_off=checkVars

--module_resolution=node
--package_json_entry_names es2015
--process_common_js_modules

--js built/**.js
--entry_point=built/index

--output_wrapper "%output%
//# sourceMappingURL=bundle.js.map"
12 changes: 12 additions & 0 deletions integration/hello_world__render3__closure/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { browser, element, by } from 'protractor';

describe('Hello world E2E Tests', function () {
it('should display: Hello world!', function () {
browser.ignoreSynchronization = true;
browser.get('');
const div = element(by.css('div'));
expect(div.getText()).toEqual('Hello world!');
element(by.css('input')).sendKeys('!');
expect(div.getText()).toEqual('Hello world!!');
});
});
15 changes: 15 additions & 0 deletions integration/hello_world__render3__closure/e2e/browser.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"open": false,
"logLevel": "silent",
"port": 8080,
"server": {
"baseDir": "src",
"routes": {
"/dist": "dist",
"/node_modules": "node_modules"
},
"middleware": {
"0": null
}
}
}
15 changes: 15 additions & 0 deletions integration/hello_world__render3__closure/e2e/protractor.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports.config = {
specs: [
'../built/e2e/*.e2e-spec.js'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox'],
binary: process.env.CHROME_BIN,
}
},
directConnect: true,
baseUrl: 'http://localhost:8080/',
framework: 'jasmine'
};
8 changes: 8 additions & 0 deletions integration/hello_world__render3__closure/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "../built/e2e",
"types": ["jasmine"],
// TODO(alexeagle): was required for Protractor 4.0.11
"skipLibCheck": true
}
}
24 changes: 24 additions & 0 deletions integration/hello_world__render3__closure/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "angular-integration",
"version": "0.0.0",
"license": "MIT",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "private: true" plz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"private": true,
"dependencies": {
"typescript": "file:../../node_modules/typescript"
},
"devDependencies": {
"@types/jasmine": "2.5.41",
"concurrently": "3.4.0",
"lite-server": "2.2.2",
"protractor": "file:../../node_modules/protractor",
"google-closure-compiler": "20171023.0.1"
},
"scripts": {
"postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG && mkdir -p built && cp -rf ../../dist/packages ./built/packages && ./clean_ngDevMode.sh",
"closure": "java -jar node_modules/google-closure-compiler/compiler.jar --flagfile closure.conf && mkdir -p dist/packages && cp -rf ../../packages/core dist/packages/core",
"test": "tsc && yarn run closure && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first",
"serve": "lite-server -c e2e/browser.config.json",
"preprotractor": "tsc -p e2e",
"protractor": "protractor e2e/protractor.config.js"
}
}
17 changes: 17 additions & 0 deletions integration/hello_world__render3__closure/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Hello World</title>
<base href="/">
</head>

<body>
<hello-world></hello-world>

<script src="dist/bundle.js"></script>

</body>

</html>
37 changes: 37 additions & 0 deletions integration/hello_world__render3__closure/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {defineComponent, renderComponent, detectChanges, T, t, E, e, L, p, b, b1} from '../built/packages/core/src/render3';
import {ComponentDef} from '../built/packages/core/src/render3/interfaces/definition';

export class HelloWorld {
name: string = "world";

/** @nocollapse */
static ngComponentDef: ComponentDef<HelloWorld> = defineComponent({
tag: 'hello-world',
template: function (ctx: HelloWorld, cm: boolean) {
if (cm) {
E(0, 'div');
T(1);
e();
E(2, 'input');
L('input', (e) => {
ctx.name = (<HTMLInputElement>e.target).value;
detectChanges(component);
});
e();
}
t(1, b1('Hello ', ctx.name, '!'));
p(2, 'value', b(ctx.name));
},
factory: () => new HelloWorld()
});
}

const component = renderComponent(HelloWorld);
25 changes: 25 additions & 0 deletions integration/hello_world__render3__closure/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"angularCompilerOptions": {
"annotationsAs": "static fields",
"annotateForClosureCompiler": true,
"alwaysCompileGeneratedCode": true
},

"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"strict": true,
"target": "es5",
"noImplicitAny": false,
"sourceMap": false,
"experimentalDecorators": true,
"outDir": "built",
"rootDir": "./src",
"declaration": true,
"types": [],
"lib": ["es2015", "dom"]
},
"files": [
"src/index.ts"
]
}
12 changes: 12 additions & 0 deletions integration/hello_world__render3__rollup/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { browser, element, by } from 'protractor';

describe('Hello world E2E Tests', function () {
it('should display: Hello world!', function () {
browser.ignoreSynchronization = true;
browser.get('');
const div = element(by.css('div'));
expect(div.getText()).toEqual('Hello world!');
element(by.css('input')).sendKeys('!');
expect(div.getText()).toEqual('Hello world!!');
});
});
15 changes: 15 additions & 0 deletions integration/hello_world__render3__rollup/e2e/browser.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"open": false,
"logLevel": "silent",
"port": 8080,
"server": {
"baseDir": "src",
"routes": {
"/dist": "dist",
"/node_modules": "node_modules"
},
"middleware": {
"0": null
}
}
}
15 changes: 15 additions & 0 deletions integration/hello_world__render3__rollup/e2e/protractor.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports.config = {
specs: [
'../built/e2e/*.e2e-spec.js'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox'],
binary: process.env.CHROME_BIN,
}
},
directConnect: true,
baseUrl: 'http://localhost:8080/',
framework: 'jasmine'
};
8 changes: 8 additions & 0 deletions integration/hello_world__render3__rollup/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "../built/e2e",
"types": ["jasmine"],
// TODO(alexeagle): was required for Protractor 4.0.11
"skipLibCheck": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "strict": true ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}
37 changes: 37 additions & 0 deletions integration/hello_world__render3__rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "angular-integration",
"version": "0.0.0",
"license": "MIT",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"private": true,
"dependencies": {
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
"rxjs": "file:../../node_modules/rxjs",
"typescript": "file:../../node_modules/typescript"
},
"devDependencies": {
"@types/jasmine": "2.5.41",
"concurrently": "3.4.0",
"lite-server": "2.2.2",
"protractor": "file:../../node_modules/protractor",
"rollup": "0.54.0",
"rollup-plugin-commonjs": "8.2.6",
"rollup-plugin-node-resolve": "3.0.2",
"rollup-plugin-replace": "2.0.0",
"rollup-plugin-typescript2": "0.10.0",
"rollup-plugin-uglify": "2.0.1"
},
"scripts": {
"postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG",
"rollup": "rollup -c rollup.config.js",
"test": "yarn run rollup && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first",
"serve": "lite-server -c e2e/browser.config.json",
"preprotractor": "tsc -p e2e",
"protractor": "protractor e2e/protractor.config.js"
}
}
41 changes: 41 additions & 0 deletions integration/hello_world__render3__rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import typescript2 from 'rollup-plugin-typescript2';
import uglify from 'rollup-plugin-uglify';

export default {
input: `src/index.ts`,
output: {
name: 'hw',
file: `dist/bundle.js`,
format: 'iife',
sourcemap: false
},
plugins: [
typescript2({
typescript: require('typescript'),
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}),
replace({
delimiters: ['', ''],
values: {
'/** @class */': '/** @__PURE__ */'
}
}),
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
}),
uglify({
mangle: true,
compress: {
global_defs: {
'ngDevMode': false,
}
}
})
],
external: []
}
17 changes: 17 additions & 0 deletions integration/hello_world__render3__rollup/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Hello World</title>
<base href="/">
</head>

<body>
<hello-world></hello-world>

<script src="dist/bundle.js"></script>

</body>

</html>