Skip to content

Commit

Permalink
fix(karma): rc6 (code-health) (#61)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
emoralesb05 authored and kyleledbetter committed Sep 12, 2016
1 parent 6104b55 commit d11f0a9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
16 changes: 10 additions & 6 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },

Expand Down
16 changes: 10 additions & 6 deletions config/karma.travis.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },

Expand Down
52 changes: 40 additions & 12 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<string, Response> = new Map<string, Response>();
generalResponses.set('app/assets/icons/teradata.svg', new Response(new ResponseOptions({
status: 200, body: '<svg></svg>',
})));

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<string, Response> = new Map<string, Response>(generalResponses);
mockBackend.connections.subscribe((connection: any) => {
connection.mockRespond(responses.get(connection.request.url));
});

}));
let fixture: ComponentFixture<any> = 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);
});
})));
});
10 changes: 9 additions & 1 deletion src/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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'},
Expand Down
3 changes: 1 addition & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"sourceMap": true,
"target": "es5",
"inlineSources": true
},

},
"files": [
"main.ts",
"typings.d.ts"
Expand Down

0 comments on commit d11f0a9

Please sign in to comment.