From d11f0a9e75ee69509d7bce2ae186366052ce471a Mon Sep 17 00:00:00 2001 From: Ed Morales Date: Mon, 12 Sep 2016 10:05:43 -0700 Subject: [PATCH] fix(karma): rc6 (code-health) (#61) * fixed configuration so karma could run again without issues and use testing modules from angular * first rc6 intermediate unit test * removed unnecessary config from karma.conf.js * updated karma.travis.conf.js --- config/karma.conf.js | 16 +++++++---- config/karma.travis.conf.js | 16 +++++++---- src/app/app.component.spec.ts | 52 +++++++++++++++++++++++++++-------- src/system-config.ts | 10 ++++++- src/tsconfig.json | 3 +- 5 files changed, 70 insertions(+), 27 deletions(-) diff --git a/config/karma.conf.js b/config/karma.conf.js index e19265783f..d0dd30e126 100644 --- a/config/karma.conf.js +++ b/config/karma.conf.js @@ -14,12 +14,16 @@ module.exports = function (config) { } }, files: [ - { pattern: 'dist/vendor/es6-shim/es6-shim.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false }, - { pattern: 'dist/vendor/reflect-metadata/Reflect.js', included: true, watched: false }, - { pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false }, - { pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false }, + { pattern: 'dist/vendor/core-js/client/core.js', included: true, watched: false}, + { pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false}, + { pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/proxy.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/sync-test.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/jasmine-patch.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/fake-async-test.js', included: true, watched: false}, + { pattern: 'dist/vendor/hammerjs/hammer.min.js', included: true, watched: false}, { pattern: 'config/karma-test-shim.js', included: true, watched: true }, diff --git a/config/karma.travis.conf.js b/config/karma.travis.conf.js index 3ca1fb0b6b..5e4b04454c 100644 --- a/config/karma.travis.conf.js +++ b/config/karma.travis.conf.js @@ -7,12 +7,16 @@ module.exports = function (config) { require('karma-firefox-launcher') ], files: [ - { pattern: 'dist/vendor/es6-shim/es6-shim.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false }, - { pattern: 'dist/vendor/reflect-metadata/Reflect.js', included: true, watched: false }, - { pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false }, - { pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false }, + { pattern: 'dist/vendor/core-js/client/core.js', included: true, watched: false}, + { pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false}, + { pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/proxy.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/sync-test.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/jasmine-patch.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false}, + { pattern: 'dist/vendor/zone.js/dist/fake-async-test.js', included: true, watched: false}, + { pattern: 'dist/vendor/hammerjs/hammer.min.js', included: true, watched: false}, { pattern: 'config/karma-test-shim.js', included: true, watched: true }, diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 3fe92e68b2..8b809897d5 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,26 +1,54 @@ import { TestBed, inject, + async, ComponentFixture, } from '@angular/core/testing'; - +import { RouterTestingModule } from '@angular/router/testing'; +import { XHRBackend, Response, ResponseOptions } from '@angular/http'; +import { MockBackend } from '@angular/http/testing'; +import { CovalentCoreModule } from '../platform/core'; import { DocsAppComponent } from './app.component'; describe('Component: App', () => { - TestBed.configureTestingModule({ - providers: [ - DocsAppComponent, - ], - }); + let generalResponses: Map = new Map(); + generalResponses.set('app/assets/icons/teradata.svg', new Response(new ResponseOptions({ + status: 200, body: '', + }))); - TestBed.compileComponents(); + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + CovalentCoreModule.forRoot(), + RouterTestingModule, + ], + declarations: [ + DocsAppComponent, + ], + providers: [ + MockBackend, + { provide: XHRBackend, useExisting: MockBackend }, + ], + }); + TestBed.compileComponents(); + })); - beforeEach(inject([], function(): void { + it('should create the component', async(inject([MockBackend], (mockBackend: MockBackend) => { + let responses: Map = new Map(generalResponses); + mockBackend.connections.subscribe((connection: any) => { + connection.mockRespond(responses.get(connection.request.url)); + }); - })); + let fixture: ComponentFixture = TestBed.createComponent(DocsAppComponent); + let testComponent: DocsAppComponent = fixture.debugElement.componentInstance; + let element: HTMLElement = fixture.nativeElement; - it('should create the component', inject([], () => { - - })); + expect(element.querySelector('[title="Covalent"]')).toBeTruthy(); + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(element.querySelectorAll('md-nav-list[menu-items] a[md-list-item]').length) + .toBe(testComponent.routes.length); + }); + }))); }); diff --git a/src/system-config.ts b/src/system-config.ts index e0c632d980..f105742080 100644 --- a/src/system-config.ts +++ b/src/system-config.ts @@ -4,6 +4,14 @@ /** Map relative paths to URLs. */ const map: any = { + '@angular/core/testing': 'vendor/@angular/core/bundles/core-testing.umd.js', + '@angular/compiler/testing': 'vendor/@angular/compiler/bundles/compiler-testing.umd.js', + '@angular/router/testing': 'vendor/@angular/router/bundles/router-testing.umd.js', + '@angular/http/testing': 'vendor/@angular/http/bundles/http-testing.umd.js', + '@angular/common/testing': 'vendor/@angular/common/bundles/common-testing.umd.js', + '@angular/platform-browser/testing': 'vendor/@angular/platform-browser/bundles/platform-browser-testing.umd.js', + '@angular/platform-browser-dynamic/testing': + 'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', }; /** User packages configuration. */ @@ -14,7 +22,7 @@ const packages: any = { /* * Everything underneath this line is managed by the CLI. */ -const angularPackages = { +const angularPackages: any = { // Angular specific barrels. '@angular/core': { main: 'bundles/core.umd.js'}, '@angular/core/testing': { main: 'bundles/core-testing.umd.js'}, diff --git a/src/tsconfig.json b/src/tsconfig.json index 2080a6cd5d..b989feab78 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -15,8 +15,7 @@ "sourceMap": true, "target": "es5", "inlineSources": true - }, - + }, "files": [ "main.ts", "typings.d.ts"