From 694c14b7290c65b9422fe5639018d10cc9f450d6 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Sun, 6 Dec 2015 20:57:47 +0000 Subject: [PATCH 1/2] feat(test): protractor integration, e2e test sample --- README.md | 22 ++++++++++++--- addon/ng2/blueprints/ng2/files/e2e/app.e2e.ts | 15 ++++++++++ addon/ng2/blueprints/ng2/files/e2e/app.po.ts | 6 ++++ .../blueprints/ng2/files/e2e/tsconfig.json | 11 ++++++++ addon/ng2/blueprints/ng2/files/gitignore | 6 +++- addon/ng2/blueprints/ng2/files/package.json | 4 ++- .../blueprints/ng2/files/protractor.conf.js | 28 +++++++++++++++++++ 7 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 addon/ng2/blueprints/ng2/files/e2e/app.e2e.ts create mode 100644 addon/ng2/blueprints/ng2/files/e2e/app.po.ts create mode 100644 addon/ng2/blueprints/ng2/files/e2e/tsconfig.json create mode 100644 addon/ng2/blueprints/ng2/files/protractor.conf.js diff --git a/README.md b/README.md index 7545010d2479..5a4ba962f72e 100644 --- a/README.md +++ b/README.md @@ -69,19 +69,33 @@ ng build The build artifacts will be stored in the `dist/` directory. -### Running tests +### Running unit tests -Before running the tests make sure that the project is built. To build the +Before running the tests make sure that the project is built. To build the project once you can use: ```bash ng build ``` -With the project built in the `dist/` folder you can just run: `karma start`. +With the project built in the `dist/` folder you can just run: `karma start`. Karma will run the tests and keep the browser open waiting to run again. -This will be easier when the command + +### Running end-to-end tests + +Before running the tests make sure that you have an updated webdriver and that +the tests are built: + +```bash +$(npm bin)/webdriver-manager update +$(npm bin)/tsc -p e2e/ +``` + +Afterwards you only need to run `$(npm bin)/protractor` while serving via +`ng serve`. + +This will be easier when the command [ng test](https://github.com/angular/angular-cli/issues/70) is implemented. diff --git a/addon/ng2/blueprints/ng2/files/e2e/app.e2e.ts b/addon/ng2/blueprints/ng2/files/e2e/app.e2e.ts new file mode 100644 index 000000000000..b299821de396 --- /dev/null +++ b/addon/ng2/blueprints/ng2/files/e2e/app.e2e.ts @@ -0,0 +1,15 @@ +import "angular2/testing"; +import { <%= jsComponentName %>Page } from './app.po'; + +describe('<%= htmlComponentName %> App', function() { + let page: <%= jsComponentName %>Page; + + beforeEach(() => { + page = new <%= jsComponentName %>Page(); + }) + + it('should display message saying app works', () => { + page.navigateTo() + expect(page.getParagraphText()).toEqual('<%= htmlComponentName %> Works!'); + }); +}); diff --git a/addon/ng2/blueprints/ng2/files/e2e/app.po.ts b/addon/ng2/blueprints/ng2/files/e2e/app.po.ts new file mode 100644 index 000000000000..43e99b59c38c --- /dev/null +++ b/addon/ng2/blueprints/ng2/files/e2e/app.po.ts @@ -0,0 +1,6 @@ +import "angular2/testing"; + +export class <%= jsComponentName %>Page { + navigateTo() { return browser.get('/'); } + getParagraphText() { return element(by.css('<%= jsComponentName %>-app p')).getText(); } +} diff --git a/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json b/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json new file mode 100644 index 000000000000..304804ccabda --- /dev/null +++ b/addon/ng2/blueprints/ng2/files/e2e/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "sourceMap": true, + "declaration": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": false + } +} diff --git a/addon/ng2/blueprints/ng2/files/gitignore b/addon/ng2/blueprints/ng2/files/gitignore index caf98b528870..e497b68adc68 100644 --- a/addon/ng2/blueprints/ng2/files/gitignore +++ b/addon/ng2/blueprints/ng2/files/gitignore @@ -14,4 +14,8 @@ /coverage/* /libpeerconnection.log npm-debug.log -testem.log \ No newline at end of file +testem.log + +# e2e +/e2e/*.js +/e2e/*.map diff --git a/addon/ng2/blueprints/ng2/files/package.json b/addon/ng2/blueprints/ng2/files/package.json index 4250237942ef..a434ef4bdb9f 100644 --- a/addon/ng2/blueprints/ng2/files/package.json +++ b/addon/ng2/blueprints/ng2/files/package.json @@ -24,6 +24,8 @@ "jasmine-core": "^2.3.4", "karma": "^0.13.15", "karma-chrome-launcher": "^0.2.1", - "karma-jasmine": "^0.3.6" + "karma-jasmine": "^0.3.6", + "protractor": "^3.0.0", + "typescript": "^1.7.3" } } diff --git a/addon/ng2/blueprints/ng2/files/protractor.conf.js b/addon/ng2/blueprints/ng2/files/protractor.conf.js new file mode 100644 index 000000000000..d51992dfd1b3 --- /dev/null +++ b/addon/ng2/blueprints/ng2/files/protractor.conf.js @@ -0,0 +1,28 @@ +exports.config = { + allScriptsTimeout: 11000, + + specs: [ + 'e2e/**/*.e2e.js' + ], + + capabilities: { + 'browserName': 'chrome' + }, + + directConnect: true, + + baseUrl: 'http://localhost:4200/', + + framework: 'jasmine', + + jasmineNodeOpts: { + defaultTimeoutInterval: 30000 + }, + + useAllAngular2AppRoots: true, + + beforeLaunch: function() { + require('zone.js'); + require('reflect-metadata'); + } +}; From f127289b3ff87325e9e1800f09be0aaa51e5cddf Mon Sep 17 00:00:00 2001 From: Ciro Nunes Date: Tue, 15 Dec 2015 13:25:20 -0200 Subject: [PATCH 2/2] chore: update blueprints considering `noImplicityAny` --- addon/ng2/blueprints/ng2/files/src/app/__name__.spec.ts | 4 ++-- addon/ng2/blueprints/ng2/files/src/app/__name__.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/ng2/blueprints/ng2/files/src/app/__name__.spec.ts b/addon/ng2/blueprints/ng2/files/src/app/__name__.spec.ts index b7c3d56b1ece..f118dc87b206 100644 --- a/addon/ng2/blueprints/ng2/files/src/app/__name__.spec.ts +++ b/addon/ng2/blueprints/ng2/files/src/app/__name__.spec.ts @@ -4,12 +4,12 @@ import {<%= jsComponentName %>App} from '../app/<%= htmlComponentName %>'; beforeEachProviders(() => [<%= jsComponentName %>App]); describe('App: <%= jsComponentName %>', () => { - it('should have the `defaultMeaning` as 42', inject([<%= jsComponentName %>App], (app) => { + it('should have the `defaultMeaning` as 42', inject([<%= jsComponentName %>App], (app: <%= jsComponentName %>App) => { expect(app.defaultMeaning).toBe(42); })); describe('#meaningOfLife', () => { - it('should get the meaning of life', inject([<%= jsComponentName %>App], (app) => { + it('should get the meaning of life', inject([<%= jsComponentName %>App], (app: <%= jsComponentName %>App) => { expect(app.meaningOfLife()).toBe('The meaning of life is 42'); expect(app.meaningOfLife(22)).toBe('The meaning of life is 22'); })); diff --git a/addon/ng2/blueprints/ng2/files/src/app/__name__.ts b/addon/ng2/blueprints/ng2/files/src/app/__name__.ts index 86601ac047f9..832a90bb1239 100644 --- a/addon/ng2/blueprints/ng2/files/src/app/__name__.ts +++ b/addon/ng2/blueprints/ng2/files/src/app/__name__.ts @@ -11,7 +11,7 @@ import {Component} from 'angular2/core'; export class <%= jsComponentName %>App { defaultMeaning: number = 42; - meaningOfLife(meaning) { + meaningOfLife(meaning?: number) { return `The meaning of life is ${meaning || this.defaultMeaning}`; } }