Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 12984fd

Browse files
committed
docs(testing): update samples & test config to RC1
1 parent 0276741 commit 12984fd

13 files changed

+200
-161
lines changed
+83-80
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,93 @@
1-
/*global jasmine, __karma__, window*/
2-
(function () {
3-
4-
// Error.stackTraceLimit = Infinity;
5-
1+
// /*global jasmine, __karma__, window*/
2+
Error.stackTraceLimit = Infinity;
63
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
74

8-
// Cancel Karma's synchronous start,
9-
// we call `__karma__.start()` later, once all the specs are loaded.
10-
__karma__.loaded = function () { };
11-
12-
// SET THE RUNTIME APPLICATION ROOT HERE
13-
var appRoot ='app'; // no trailing slash!
14-
15-
// RegExp for client application base path within karma (which always starts 'base\')
16-
var karmaBase = '^\/base\/'; // RegEx string for base of karma folders
17-
var appPackage = 'base/' + appRoot; //e.g., base/app
18-
var appRootRe = new RegExp(karmaBase + appRoot + '\/');
19-
var onlyAppFilesRe = new RegExp(karmaBase + appRoot + '\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$');
20-
21-
var moduleNames = [];
22-
23-
// Configure systemjs packages to use the .js extension for imports from the app folder
24-
var packages = {};
25-
packages[appPackage] = {
26-
defaultExtension: false,
27-
format: 'register',
28-
map: Object.keys(window.__karma__.files)
29-
.filter(onlyAppFiles)
30-
// Create local module name mapping to karma file path for app files
31-
// with karma's fingerprint in query string, e.g.:
32-
// './hero.service': '/base/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
33-
.reduce(function (pathsMapping, appPath) {
34-
var moduleName = appPath.replace(appRootRe, './').replace(/\.js$/, '');
35-
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
36-
return pathsMapping;
37-
}, {})
38-
}
39-
40-
System.config({ packages: packages });
41-
42-
// Configure Angular for the browser and
43-
// with test versions of the platform providers
44-
Promise.all([
45-
System.import('angular2/testing'),
46-
System.import('angular2/platform/testing/browser')
47-
])
48-
.then(function (results) {
49-
var testing = results[0];
50-
var browser = results[1];
51-
testing.setBaseTestProviders(
52-
browser.TEST_BROWSER_PLATFORM_PROVIDERS,
53-
browser.TEST_BROWSER_APPLICATION_PROVIDERS);
54-
55-
// Load all spec files
56-
// (e.g. 'base/app/hero.service.spec.js')
57-
return Promise.all(
58-
Object.keys(window.__karma__.files)
59-
.filter(onlySpecFiles)
60-
.map(function (moduleName) {
61-
moduleNames.push(moduleName);
62-
return System.import(moduleName);
63-
}));
64-
})
65-
66-
.then(success, fail);
67-
68-
////// Helpers //////
69-
70-
function onlyAppFiles(filePath) {
71-
return onlyAppFilesRe.test(filePath);
5+
__karma__.loaded = function () {
6+
};
7+
8+
function isJsFile(path) {
9+
return path.slice(-3) == '.js';
7210
}
7311

74-
function onlySpecFiles(filePath) {
75-
return /\.spec\.js$/.test(filePath);
12+
function isSpecFile(path) {
13+
return /\.spec\.js$/.test(path);
7614
}
7715

78-
function success () {
79-
console.log(
80-
'Spec files loaded:\n ' +
81-
moduleNames.join('\n ') +
82-
'\nStarting Jasmine testrunner');
83-
__karma__.start();
16+
function isBuiltFile(path) {
17+
var builtPath = '/base/app/';
18+
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
8419
}
8520

86-
function fail(error) {
87-
__karma__.error(error.stack || error);
21+
var allSpecFiles = Object.keys(window.__karma__.files)
22+
.filter(isSpecFile)
23+
.filter(isBuiltFile);
24+
25+
//////////////////////////
26+
// Load our SystemJS configuration.
27+
28+
// map tells the System loader where to look for things
29+
var map = {
30+
'app': 'app',
31+
32+
'@angular': 'node_modules/@angular',
33+
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
34+
'rxjs': 'node_modules/rxjs'
35+
};
36+
37+
// packages tells the System loader how to load when no filename and/or no extension
38+
var packages = {
39+
'app': { main: 'main.js', defaultExtension: 'js' },
40+
'rxjs': { defaultExtension: 'js' },
41+
'angular2-in-memory-web-api': { defaultExtension: 'js' },
42+
};
43+
44+
var ngPackageNames = [
45+
'common',
46+
'compiler',
47+
'core',
48+
'http',
49+
'platform-browser',
50+
'platform-browser-dynamic',
51+
'router',
52+
'router-deprecated',
53+
'upgrade',
54+
];
55+
56+
// Add package entries for angular packages
57+
ngPackageNames.forEach(function(pkgName) {
58+
59+
// Bundled (~40 requests): DOESN'T WORK IN KARMA OR WALLABY (YET?)
60+
//packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
61+
62+
// Individual files (~300 requests):
63+
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
64+
});
65+
66+
var config = {
67+
baseURL: '/base',
68+
map: map,
69+
packages: packages
8870
}
8971

90-
})();
72+
System.config(config);
73+
//////////////
74+
75+
Promise.all([
76+
System.import('@angular/core/testing'),
77+
System.import('@angular/platform-browser-dynamic/testing')
78+
]).then(function (providers) {
79+
var testing = providers[0];
80+
var testingBrowser = providers[1];
81+
82+
testing.setBaseTestProviders(
83+
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
84+
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
85+
86+
}).then(function() {
87+
// Finally, load all spec files.
88+
// This will run the tests directly.
89+
return Promise.all(
90+
allSpecFiles.map(function (moduleName) {
91+
return System.import(moduleName);
92+
}));
93+
}).then(__karma__.start, __karma__.error);

public/docs/_examples/karma.conf.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,30 @@ module.exports = function(config) {
2121
}
2222
},
2323
files: [
24-
// Polyfills.
25-
'node_modules/code-js/client/shim.min.js',
24+
// System.js for module loading
25+
'node_modules/systemjs/dist/system.src.js',
2626

27-
// Zone.js dependencies
28-
// Note - do not include zone.js itself here, it is already
29-
// included in angular2-polyfills
27+
// Polyfills
28+
'node_modules/core-js/client/shim.js',
29+
30+
// Reflect and Zone.js
31+
'node_modules/reflect-metadata/Reflect.js',
3032
'node_modules/zone.js/dist/zone.js',
3133
'node_modules/zone.js/dist/jasmine-patch.js',
3234
'node_modules/zone.js/dist/async-test.js',
3335
'node_modules/zone.js/dist/fake-async-test.js',
3436

35-
{ pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: false },
36-
{ pattern: 'https://code.angularjs.org/tools/system.js', included: true, watched: false },
37-
3837
// RxJs.
3938
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
4039
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
4140

42-
{pattern: 'karma-test-shim.js', included: true, watched: true},
43-
{pattern: 'built/test/matchers.js', included: true, watched: true},
44-
45-
// paths loaded via module imports
46-
{pattern: 'built/**/*.js', included: false, watched: true},
41+
// Angular 2 itself and the testing library
42+
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
43+
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
4744

48-
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: true},
49-
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: true},
45+
'karma-test-shim.js',
5046

51-
// transpiled application & spec code paths to be loaded via module imports
47+
// transpiled application & spec code paths loaded via module imports
5248
{pattern: appBase + '**/*.js', included: false, watched: true},
5349

5450
// asset (HTML & CSS) paths loaded via Angular's component compiler

public/docs/_examples/testing/ts/app/app.component.spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
beforeEach, beforeEachProviders,
99
describe, ddescribe, xdescribe,
1010
expect, it, iit, xit,
11-
async, inject, ComponentFixture, TestComponentBuilder
12-
} from '@angular/testing';
11+
async, inject
12+
} from '@angular/core/testing';
13+
14+
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
1315

1416
import { Hero, HeroService, MockHeroService } from './mock-hero.service';
1517

@@ -18,7 +20,7 @@ import { Router, MockRouter,
1820
RouterOutlet, MockRouterOutlet} from './mock-router';
1921

2022
describe('AppComponent', () => {
21-
let fixture: ComponentFixture;
23+
let fixture: ComponentFixture<AppComponent>;
2224
let comp: AppComponent;
2325

2426
beforeEach(async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {

public/docs/_examples/testing/ts/app/app.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import { Component } from '@angular/core';
44

55
// Can't test with ROUTER_DIRECTIVES yet
6-
// import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router';
6+
// import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
77

88
import { RouteConfig, RouterLink,
9-
RouterOutlet, ROUTER_PROVIDERS } from '@angular/router';
9+
RouterOutlet, ROUTER_PROVIDERS } from '@angular/router-deprecated';
1010

1111
import { DashboardComponent } from './dashboard.component';
1212
import { HeroesComponent } from './heroes.component';

public/docs/_examples/testing/ts/app/bad-tests.spec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import { DebugElement } from '@angular/core';
1919
import { By } from '@angular/platform-browser';
2020

2121
import {
22-
beforeEach, beforeEachProviders, withProviders,
22+
beforeEach, beforeEachProviders,
2323
describe, ddescribe, xdescribe,
2424
expect, it, iit, xit,
25-
async, inject, fakeAsync, tick,
26-
ComponentFixture, TestComponentBuilder
27-
} from '@angular/testing';
25+
async, inject
26+
} from '@angular/core/testing';
27+
28+
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
2829

2930
import { provide } from '@angular/core';
3031
import { ViewMetadata } from '@angular/core';
@@ -90,7 +91,7 @@ xdescribe('async & inject testing errors', () => {
9091
let itPromise = patchJasmineIt();
9192

9293
it('should fail with an error from a promise', async(() => {
93-
return Promise.reject('baz')
94+
return Promise.reject('baz');
9495
}));
9596

9697
itPromise.then(

public/docs/_examples/testing/ts/app/bag.spec.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import { DebugElement } from '@angular/core';
1616
import { By } from '@angular/platform-browser';
1717

1818
import {
19-
beforeEach, beforeEachProviders, withProviders,
19+
beforeEach, beforeEachProviders,
2020
describe, ddescribe, xdescribe,
2121
expect, it, iit, xit,
22-
async, inject, fakeAsync, tick,
23-
ComponentFixture, TestComponentBuilder
24-
} from '@angular/testing';
22+
async, inject,
23+
fakeAsync, tick, withProviders
24+
} from '@angular/core/testing';
25+
26+
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
2527

2628
import { provide } from '@angular/core';
2729
import { ViewMetadata } from '@angular/core';
@@ -349,7 +351,7 @@ describe('test component builder', function() {
349351
})), 10000); // Long timeout because this test makes an actual XHR.
350352

351353
describe('(lifecycle hooks w/ MyIfParentComp)', () => {
352-
let fixture: ComponentFixture;
354+
let fixture: ComponentFixture<MyIfParentComp>;
353355
let parent: MyIfParentComp;
354356
let child: MyIfChildComp;
355357

public/docs/_examples/testing/ts/app/dashboard.component.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
beforeEach, beforeEachProviders,
99
describe, ddescribe, xdescribe,
1010
expect, it, iit, xit,
11-
async, inject, TestComponentBuilder
12-
} from '@angular/testing';
11+
async, inject
12+
} from '@angular/core/testing';
13+
14+
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
1315

1416
import { Hero, HeroService, MockHeroService } from './mock-hero.service';
1517
import { Router, MockRouter } from './mock-router';

public/docs/_examples/testing/ts/app/dashboard.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// #docregion
33
import { Component, OnInit } from '@angular/core';
44
// #docregion import-router
5-
import { Router } from '@angular/router';
5+
import { Router } from '@angular/router-deprecated';
66
// #enddocregion import-router
77

88
import { Hero } from './hero';

public/docs/_examples/testing/ts/app/hero-detail.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Component, OnInit } from '@angular/core';
66
// #enddocregion import-oninit
77
// #docregion import-route-params
8-
import {RouteParams} from '@angular/router';
8+
import {RouteParams} from '@angular/router-deprecated';
99
// #enddocregion import-route-params
1010

1111
import { Hero } from './hero';

public/docs/_examples/testing/ts/app/heroes.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// #docplaster
22
// #docregion
33
import { Component, OnInit } from '@angular/core';
4-
import { Router } from '@angular/router';
4+
import { Router } from '@angular/router-deprecated';
55

66
import { Hero } from './hero';
77
import { HeroDetailComponent } from './hero-detail.component';
@@ -47,4 +47,4 @@ export class HeroesComponent implements OnInit {
4747
}
4848
// #enddocregion heroes-component-renaming
4949
// #enddocregion class
50-
// #enddocregion
50+
// #enddocregion

public/docs/_examples/testing/ts/app/http-hero.service.spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* tslint:disable:no-unused-variable */
22
import {
3-
beforeEach, beforeEachProviders, withProviders,
3+
beforeEach, beforeEachProviders,
44
describe, ddescribe, xdescribe,
55
expect, it, iit, xit,
6-
async, inject, TestComponentBuilder
7-
} from '@angular/testing';
6+
async, inject, withProviders
7+
} from '@angular/core/testing';
8+
9+
import { TestComponentBuilder } from '@angular/compiler/testing';
810

911
import { provide } from '@angular/core';
1012

public/docs/_examples/testing/ts/app/mock-router.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export * from '@angular/router';
1+
export * from '@angular/router-deprecated';
22

33
import { Directive, DynamicComponentLoader, ViewContainerRef,
44
Injectable, Optional, Input } from '@angular/core';
55

66
import { ComponentInstruction, Instruction,
7-
Router, RouterOutlet} from '@angular/router';
7+
Router, RouterOutlet} from '@angular/router-deprecated';
88

99
let _resolveToTrue = Promise.resolve(true);
1010

0 commit comments

Comments
 (0)