From efc9b90f1411d0cd1c2c1a9e1e59fa3b7ad3381b Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Tue, 3 May 2016 00:48:56 -0600 Subject: [PATCH] chore: fix all linting issues with generated app --- .../files/__path__/__name__.component.spec.ts | 42 +++++++++++++++---- .../directive/files/__path__/index.ts | 2 +- .../__path__/app/__name__.component.spec.ts | 10 ++--- .../pipe/files/__path__/__name__.pipe.spec.ts | 6 +-- .../blueprints/pipe/files/__path__/index.ts | 2 +- .../files/__path__/__name__.service.spec.ts | 11 ++--- .../service/files/__path__/index.ts | 2 +- addon/ng2/tasks/lint.ts | 5 ++- lib/cli/index.js | 2 +- tests/e2e/e2e_workflow.spec.js | 10 +++++ 10 files changed, 59 insertions(+), 33 deletions(-) diff --git a/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts b/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts index b27b6cefb576..21820d317a53 100644 --- a/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts +++ b/addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts @@ -1,20 +1,46 @@ import { - async, + beforeEach, beforeEachProviders, describe, - ddescribe, expect, - iit, it, - inject + inject, } from '@angular/core/testing'; import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing'; +import { Component } from '@angular/core'; +import { By } from '@angular/platform-browser'; import { <%= classifiedModuleName %>Component } from './<%= dasherizedModuleName %>.component'; describe('Component: <%= classifiedModuleName %>', () => { + let builder: TestComponentBuilder; + beforeEachProviders(() => [<%= classifiedModuleName %>Component]); - - it('should create the component', inject([<%= classifiedModuleName %>Component], (component: <%= classifiedModuleName %>Component) => { - expect(component).toBeTruthy(); - })); + beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) { + builder = tcb; + })); + + it('should inject the component', inject([<%= classifiedModuleName %>Component], + (component: <%= classifiedModuleName %>Component) => { + expect(component).toBeTruthy(); + })); + + it('should create the component', inject([], () => { + return builder.createAsync(<%= classifiedModuleName %>ComponentTestController) + .then((fixture: ComponentFixture) => { + let query = fixture.debugElement.query(By.directive(<%= classifiedModuleName %>Component)); + expect(query).toBeTruthy(); + expect(query.componentInstance).toBeTruthy(); + }); + })); }); + +@Component({ + selector: 'test', + template: ` + <<%= selector %>>> + `, + directives: [<%= classifiedModuleName %>Component] +}) +class <%= classifiedModuleName %>ComponentTestController { +} + diff --git a/addon/ng2/blueprints/directive/files/__path__/index.ts b/addon/ng2/blueprints/directive/files/__path__/index.ts index 805bf4825021..421c3da10cc6 100644 --- a/addon/ng2/blueprints/directive/files/__path__/index.ts +++ b/addon/ng2/blueprints/directive/files/__path__/index.ts @@ -1 +1 @@ -export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive'; \ No newline at end of file +export {<%= classifiedModuleName %>} from './<%= dasherizedModuleName %>.directive'; diff --git a/addon/ng2/blueprints/ng2/files/__path__/app/__name__.component.spec.ts b/addon/ng2/blueprints/ng2/files/__path__/app/__name__.component.spec.ts index ab9ce267c3bd..dff262b07022 100644 --- a/addon/ng2/blueprints/ng2/files/__path__/app/__name__.component.spec.ts +++ b/addon/ng2/blueprints/ng2/files/__path__/app/__name__.component.spec.ts @@ -1,24 +1,22 @@ import { - async, beforeEachProviders, describe, - ddescribe, expect, - iit, it, inject } from '@angular/core/testing'; -import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing'; import { <%= jsComponentName %>AppComponent } from '../app/<%= htmlComponentName %>.component'; beforeEachProviders(() => [<%= jsComponentName %>AppComponent]); describe('App: <%= jsComponentName %>', () => { - it('should create the app', inject([<%= jsComponentName %>AppComponent], (app: <%= jsComponentName %>AppComponent) => { + it('should create the app', + inject([<%= jsComponentName %>AppComponent], (app: <%= jsComponentName %>AppComponent) => { expect(app).toBeTruthy(); })); - it('should have as title \'<%= htmlComponentName %> works!\'', inject([<%= jsComponentName %>AppComponent], (app: <%= jsComponentName %>AppComponent) => { + it('should have as title \'<%= htmlComponentName %> works!\'', + inject([<%= jsComponentName %>AppComponent], (app: <%= jsComponentName %>AppComponent) => { expect(app.title).toEqual('<%= htmlComponentName %> works!'); })); }); diff --git a/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts b/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts index de9549aae7c4..01184c887dd8 100644 --- a/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts +++ b/addon/ng2/blueprints/pipe/files/__path__/__name__.pipe.spec.ts @@ -1,20 +1,16 @@ import { it, - iit, describe, - ddescribe, expect, inject, beforeEachProviders } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; -import { provide } from '@angular/core'; import { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.pipe'; describe('<%= classifiedModuleName %> Pipe', () => { beforeEachProviders(() => [<%= classifiedModuleName%>]); - it('should transform the input', inject([<%= classifiedModuleName %>], (pipe:<%= classifiedModuleName %>) => { + it('should transform the input', inject([<%= classifiedModuleName %>], (pipe: <%= classifiedModuleName %>) => { expect(pipe.transform(true)).toBe(null); })); }); diff --git a/addon/ng2/blueprints/pipe/files/__path__/index.ts b/addon/ng2/blueprints/pipe/files/__path__/index.ts index 7722395a535f..02968bfbd332 100644 --- a/addon/ng2/blueprints/pipe/files/__path__/index.ts +++ b/addon/ng2/blueprints/pipe/files/__path__/index.ts @@ -1 +1 @@ -export { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.pipe'; \ No newline at end of file +export { <%= classifiedModuleName %> } from './<%= dasherizedModuleName %>.pipe'; diff --git a/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts b/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts index 06ca3e1fb022..22388d3435ec 100644 --- a/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts +++ b/addon/ng2/blueprints/service/files/__path__/__name__.service.spec.ts @@ -1,22 +1,17 @@ import { - async, beforeEachProviders, it, - iit, describe, - ddescribe, expect, inject } from '@angular/core/testing'; -import { provide } from '@angular/core'; import { <%= classifiedModuleName %>Service } from './<%= dasherizedModuleName %>.service'; describe('<%= classifiedModuleName %> Service', () => { - beforeEachProviders(() => [<%= classifiedModuleName %>Service]); - it('should ...', inject([<%= classifiedModuleName %>Service], (service: <%= classifiedModuleName %>Service) => { - + it('should ...', + inject([<%= classifiedModuleName %>Service], (service: <%= classifiedModuleName %>Service) => { + expect(service).toBeTruthy(); })); - }); diff --git a/addon/ng2/blueprints/service/files/__path__/index.ts b/addon/ng2/blueprints/service/files/__path__/index.ts index 2f135a7e3fe1..78b9dc378f5e 100644 --- a/addon/ng2/blueprints/service/files/__path__/index.ts +++ b/addon/ng2/blueprints/service/files/__path__/index.ts @@ -1 +1 @@ -export {<%= classifiedModuleName %>Service} from './<%= dasherizedModuleName %>.service'; \ No newline at end of file +export {<%= classifiedModuleName %>Service} from './<%= dasherizedModuleName %>.service'; diff --git a/addon/ng2/tasks/lint.ts b/addon/ng2/tasks/lint.ts index b2e0258b3489..d407dc68df3c 100644 --- a/addon/ng2/tasks/lint.ts +++ b/addon/ng2/tasks/lint.ts @@ -7,15 +7,16 @@ module.exports = Task.extend({ run: function () { var ui = this.ui; - return new Promise(function(resolve) { + return new Promise(function(resolve, reject) { exec('npm run lint', (err, stdout) => { ui.writeLine(stdout); if (err) { ui.writeLine(chalk.red('Lint errors found in the listed files.')); + reject(); } else { ui.writeLine(chalk.green('All files pass linting.')); + resolve(); } - resolve(); }); }); } diff --git a/lib/cli/index.js b/lib/cli/index.js index 3acb68eb5fca..ec87c3dbec98 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -100,4 +100,4 @@ module.exports = function(options) { process.env.CLI_ROOT = process.env.CLI_ROOT || path.resolve(__dirname, '..', '..'); return cli(options); -} +}; diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 5f77a61122da..35850233f8a1 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -88,6 +88,16 @@ describe('Basic end-to-end Workflow', function () { }); }); + it('lints', () => { + this.timeout(420000); + + return ng(['lint']).then(() => { + }) + .catch(err => { + throw new Error('Linting failed: ' + err); + }); + }); + it('Perform `ng test` after initial build', function () { this.timeout(420000);