From e9a89c06934f63a7c0b3a35fa7b27987a2bacb16 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 1 Feb 2017 20:47:04 -0800 Subject: [PATCH] test: protractor test for closure bundle (#14240) PR Close #14240 --- .../{build.sh => bundle.sh} | 10 ++-- .../hello_world__closure/e2e/app.e2e-spec.ts | 8 ++++ .../e2e/browser.config.json | 14 ++++++ .../e2e/protractor.config.js | 16 +++++++ .../e2e/testability.externs.js | 47 +++++++++++++++++++ .../hello_world__closure/e2e/tsconfig.json | 8 ++++ integration/hello_world__closure/package.json | 11 ++++- .../hello_world__closure/src/index.html | 2 +- .../hello_world__closure/tsconfig.json | 4 +- scripts/ci-lite/test_e2e.sh | 7 +-- 10 files changed, 116 insertions(+), 11 deletions(-) rename integration/hello_world__closure/{build.sh => bundle.sh} (85%) create mode 100644 integration/hello_world__closure/e2e/app.e2e-spec.ts create mode 100644 integration/hello_world__closure/e2e/browser.config.json create mode 100644 integration/hello_world__closure/e2e/protractor.config.js create mode 100644 integration/hello_world__closure/e2e/testability.externs.js create mode 100644 integration/hello_world__closure/e2e/tsconfig.json diff --git a/integration/hello_world__closure/build.sh b/integration/hello_world__closure/bundle.sh similarity index 85% rename from integration/hello_world__closure/build.sh rename to integration/hello_world__closure/bundle.sh index 1143830985..03dec2970e 100755 --- a/integration/hello_world__closure/build.sh +++ b/integration/hello_world__closure/bundle.sh @@ -31,16 +31,18 @@ CLOSURE_ARGS=( # Uncomment for easier debugging # "--formatting=PRETTY_PRINT" + e2e/testability.externs.js node_modules/zone.js/dist/zone.js $(find -L vendor/rxjs -name *.js) node_modules/@angular/{core,common,compiler,platform-browser}/index.js $(find node_modules/@angular/{core,common,compiler,platform-browser}/src -name *.js) - "built/*.js" - "--entry_point=./built/main" + "built/src/*.js" + "--entry_point=./built/src/main" ) java -jar node_modules/google-closure-compiler/compiler.jar $(echo ${CLOSURE_ARGS[*]}) +# gzip on Travis doesn't have --keep option so copy the original file first +cp dist/bundle.js dist/bundle.tmp gzip -f dist/bundle.js +mv dist/bundle.tmp dist/bundle.js ls -alH dist/bundle* - -# TODO(alexeagle): add an e2e test that the application works in a browser diff --git a/integration/hello_world__closure/e2e/app.e2e-spec.ts b/integration/hello_world__closure/e2e/app.e2e-spec.ts new file mode 100644 index 0000000000..d23f09b6c2 --- /dev/null +++ b/integration/hello_world__closure/e2e/app.e2e-spec.ts @@ -0,0 +1,8 @@ +import { browser, element, by } from 'protractor'; + +describe('Hello world E2E Tests', function () { + it('should display: Hello world!', function () { + browser.get(''); + expect(element(by.css('div')).getText()).toEqual('Hello world!'); + }); +}); diff --git a/integration/hello_world__closure/e2e/browser.config.json b/integration/hello_world__closure/e2e/browser.config.json new file mode 100644 index 0000000000..2886960214 --- /dev/null +++ b/integration/hello_world__closure/e2e/browser.config.json @@ -0,0 +1,14 @@ +{ + "open": false, + "logLevel": "silent", + "port": 8080, + "server": { + "baseDir": "src", + "routes": { + "/dist": "dist" + }, + "middleware": { + "0": null + } + } +} diff --git a/integration/hello_world__closure/e2e/protractor.config.js b/integration/hello_world__closure/e2e/protractor.config.js new file mode 100644 index 0000000000..5bc4f6e640 --- /dev/null +++ b/integration/hello_world__closure/e2e/protractor.config.js @@ -0,0 +1,16 @@ +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', + useAllAngular2AppRoots: true +}; diff --git a/integration/hello_world__closure/e2e/testability.externs.js b/integration/hello_world__closure/e2e/testability.externs.js new file mode 100644 index 0000000000..a17161d38e --- /dev/null +++ b/integration/hello_world__closure/e2e/testability.externs.js @@ -0,0 +1,47 @@ +/** @externs */ +// Workaround for #11119 +// TODO(alexeagle): these externs ought to be distributed with Angular. +/** + * @externs + * @suppress {duplicate} + */ +// NOTE: generated by tsickle, do not edit. + +/** @record @struct */ +function BrowserNodeGlobal() {} + /** @type {?} */ +BrowserNodeGlobal.prototype.getAngularTestability; + /** @type {?} */ +BrowserNodeGlobal.prototype.getAllAngularTestabilities; + /** @type {?} */ +BrowserNodeGlobal.prototype.getAllAngularRootElements; + /** @type {?} */ +BrowserNodeGlobal.prototype.frameworkStabilizers; + +/** + * @param {?} condition + * @return {?} + */ +BrowserNodeGlobal.prototype.assert = function(condition) {}; + +/** @record @struct */ +function PublicTestability() {} + +/** + * @return {?} + */ +PublicTestability.prototype.isStable = function() {}; + +/** + * @param {?} callback + * @return {?} + */ +PublicTestability.prototype.whenStable = function(callback) {}; + +/** + * @param {?} using + * @param {?} provider + * @param {?} exactMatch + * @return {?} + */ +PublicTestability.prototype.findProviders = function(using, provider, exactMatch) {}; \ No newline at end of file diff --git a/integration/hello_world__closure/e2e/tsconfig.json b/integration/hello_world__closure/e2e/tsconfig.json new file mode 100644 index 0000000000..e112859422 --- /dev/null +++ b/integration/hello_world__closure/e2e/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "outDir": "../built/e2e", + "types": ["jasmine"], + // TODO(alexeagle): was required for Protractor 4.0.11 + "skipLibCheck": true + } +} \ No newline at end of file diff --git a/integration/hello_world__closure/package.json b/integration/hello_world__closure/package.json index 841ac415f5..f09cc3583c 100644 --- a/integration/hello_world__closure/package.json +++ b/integration/hello_world__closure/package.json @@ -16,7 +16,16 @@ "typescript": "~2.0", "zone.js": "^0.7.6" }, + "devDependencies": { + "@types/jasmine": "^2.5.41", + "concurrently": "^3.1.0", + "lite-server": "^2.2.2", + "protractor": "file:../../node_modules/protractor" + }, "scripts": { - "test": "ngc && ./build.sh" + "test": "ngc && ./bundle.sh && concurrently \"npm run serve\" \"npm run protractor\" --kill-others --success first", + "serve": "lite-server -c e2e/browser.config.json", + "preprotractor": "tsc -p e2e", + "protractor": "protractor e2e/protractor.config.js" } } diff --git a/integration/hello_world__closure/src/index.html b/integration/hello_world__closure/src/index.html index c6754de79e..c2190cc743 100644 --- a/integration/hello_world__closure/src/index.html +++ b/integration/hello_world__closure/src/index.html @@ -8,7 +8,7 @@ Loading... - + diff --git a/integration/hello_world__closure/tsconfig.json b/integration/hello_world__closure/tsconfig.json index 60bc16816c..4251dbfcec 100644 --- a/integration/hello_world__closure/tsconfig.json +++ b/integration/hello_world__closure/tsconfig.json @@ -11,7 +11,7 @@ "noImplicitAny": false, "sourceMap": false, "experimentalDecorators": true, - "outDir": "built", + "outDir": "built/src", "declaration": true, "types": [] }, @@ -21,6 +21,6 @@ "node_modules", "built", "dist", - "src/main-jit.ts" + "e2e" ] } \ No newline at end of file diff --git a/scripts/ci-lite/test_e2e.sh b/scripts/ci-lite/test_e2e.sh index ce67ee16ce..755501b5a3 100755 --- a/scripts/ci-lite/test_e2e.sh +++ b/scripts/ci-lite/test_e2e.sh @@ -21,6 +21,10 @@ echo 'travis_fold:start:test.buildPackages' echo 'travis_fold:end:test.buildPackages' +if [[ ${TRAVIS} ]]; then + sh -e /etc/init.d/xvfb start +fi + ./integration/build_rxjs_es6.sh ./integration/run_tests.sh #TODO(alexeagle): move offline_compiler_test to integration/ @@ -35,9 +39,6 @@ cd dist/ $(npm bin)/gulp serve & $(npm bin)/gulp serve-examples & cd .. -if [[ ${TRAVIS} ]]; then - sh -e /etc/init.d/xvfb start -fi NODE_PATH=$NODE_PATH:./dist/all $(npm bin)/protractor ./protractor-e2e.conf.js --bundles=true NODE_PATH=$NODE_PATH:./dist/all $(npm bin)/protractor ./protractor-examples-e2e.conf.js --bundles=true NODE_PATH=$NODE_PATH:./dist/all $(npm bin)/protractor ./protractor-perf.conf.js --bundles=true --dryrun